2016-06-10 00:08:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace CodeInspector;
|
|
|
|
|
2016-06-13 21:33:18 +02:00
|
|
|
use RecursiveDirectoryIterator;
|
|
|
|
use RecursiveIteratorIterator;
|
|
|
|
|
2016-06-10 00:08:25 +02:00
|
|
|
class ProjectChecker
|
|
|
|
{
|
|
|
|
public static function check($debug = false)
|
2016-06-13 21:33:18 +02:00
|
|
|
{
|
|
|
|
foreach (Config::getInstance()->getIncludeDirs() as $dir_name) {
|
|
|
|
self::checkDir($dir_name, $debug);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function checkDir($dir_name, $debug = false)
|
2016-06-10 00:08:25 +02:00
|
|
|
{
|
|
|
|
$config = Config::getInstance();
|
|
|
|
|
2016-06-13 21:33:18 +02:00
|
|
|
$file_extensions = $config->getFileExtensions();
|
2016-06-20 06:38:13 +02:00
|
|
|
$filetype_handlers = $config->getFiletypeHandlers();
|
2016-06-13 21:33:18 +02:00
|
|
|
$base_dir = $config->getBaseDir();
|
|
|
|
|
|
|
|
/** @var RecursiveDirectoryIterator */
|
2016-06-21 00:10:08 +02:00
|
|
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($base_dir . $dir_name));
|
2016-06-13 21:33:18 +02:00
|
|
|
$iterator->rewind();
|
|
|
|
|
|
|
|
$files = [];
|
|
|
|
|
|
|
|
while ($iterator->valid()) {
|
|
|
|
if (!$iterator->isDot()) {
|
2016-06-20 06:38:13 +02:00
|
|
|
$extension = $iterator->getExtension();
|
|
|
|
if (in_array($extension, $file_extensions)) {
|
|
|
|
$file_name = $iterator->getRealPath();
|
|
|
|
|
|
|
|
if ($debug) {
|
|
|
|
echo 'Checking ' . $file_name . PHP_EOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($filetype_handlers[$extension])) {
|
|
|
|
/** @var FileChecker */
|
|
|
|
$file_checker = new $filetype_handlers[$extension]($file_name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$file_checker = new FileChecker($file_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
$file_checker->check(true);
|
2016-06-13 21:33:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$iterator->next();
|
|
|
|
}
|
2016-06-20 06:38:13 +02:00
|
|
|
}
|
2016-06-10 00:08:25 +02:00
|
|
|
|
2016-06-20 06:38:13 +02:00
|
|
|
public static function checkFile($file_name, $debug = false)
|
|
|
|
{
|
|
|
|
if ($debug) {
|
|
|
|
echo 'Checking ' . $file_name . PHP_EOL;
|
|
|
|
}
|
2016-06-10 00:08:25 +02:00
|
|
|
|
2016-06-20 06:38:13 +02:00
|
|
|
$config = Config::getInstance();
|
|
|
|
|
2016-06-21 00:10:08 +02:00
|
|
|
$base_dir = $config->getBaseDir();
|
|
|
|
|
2016-06-20 06:38:13 +02:00
|
|
|
$extension = array_pop(explode('.', $file_name));
|
|
|
|
|
|
|
|
$filetype_handlers = $config->getFiletypeHandlers();
|
|
|
|
|
|
|
|
if (isset($filetype_handlers[$extension])) {
|
|
|
|
/** @var FileChecker */
|
2016-06-21 00:10:08 +02:00
|
|
|
$file_checker = new $filetype_handlers[$extension]($base_dir . $file_name);
|
2016-06-20 06:38:13 +02:00
|
|
|
}
|
|
|
|
else {
|
2016-06-21 00:10:08 +02:00
|
|
|
$file_checker = new FileChecker($base_dir . $file_name);
|
2016-06-10 00:08:25 +02:00
|
|
|
}
|
2016-06-20 06:38:13 +02:00
|
|
|
|
|
|
|
$file_checker->check(true);
|
2016-06-10 00:08:25 +02:00
|
|
|
}
|
|
|
|
}
|