1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-03 10:07:52 +01:00
psalm/bin/psalm
2016-08-18 16:28:50 -04:00

69 lines
1.8 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
if (file_exists($file)) {
require $file;
break;
}
}
use Psalm\Checker\FileChecker;
use Psalm\Checker\ProjectChecker;
use Psalm\IssueBuffer;
// show all errors
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('memory_limit', '2048M');
// get options from command line
$options = getopt('f:m:', ['debug', 'config:', 'monochrome', 'show-info:']);
// get vars from options
$debug = array_key_exists('debug', $options);
$path_to_check = isset($options['f']) ? realpath($options['f']) : null;
$path_to_config = isset($options['config']) ? realpath($options['config']) : null;
$use_color = !array_key_exists('monochrome', $options);
$show_info = isset($options['show-info'])
? $options['show-info'] !== 'false' && $options['show-info'] !== '0'
: true;
// set the cache directory for the file checker
FileChecker::setCacheDir('/var/tmp/php-parser');
// initialise custom config, if passed
if ($path_to_config) {
ProjectChecker::setConfigXML($path_to_config);
}
ProjectChecker::$use_color = $use_color;
ProjectChecker::$show_info = $show_info;
$time = microtime(true);
if ($path_to_check === null) {
ProjectChecker::check($debug);
}
elseif ($path_to_check) {
if (is_dir($path_to_check)) {
ProjectChecker::checkDir($path_to_check, $debug);
}
else {
if ($path_to_check === __FILE__) {
exit(0);
}
ProjectChecker::checkFile($path_to_check, $debug);
}
}
else {
die('Cannot locate ' . $options['f'] . PHP_EOL);
}
if ($debug) {
echo('Checks took ' . (microtime(true) - $time));
echo(' and used ' . memory_get_peak_usage() . PHP_EOL);
}