1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 09:19:40 +01:00
psalm/src/CodeInspector/Config.php

105 lines
2.7 KiB
PHP
Raw Normal View History

2016-06-06 07:07:50 +02:00
<?php
namespace CodeInspector;
2016-06-10 00:08:25 +02:00
use CodeInspector\Config\FileFilter;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SimpleXMLElement;
2016-06-06 07:07:50 +02:00
class Config
{
2016-06-10 00:08:25 +02:00
protected static $_config;
public $stopOnError = true;
public $useDocblockReturnType = false;
protected $errorHandlers;
protected $inspectFiles;
2016-06-06 07:07:50 +02:00
2016-06-10 00:08:25 +02:00
protected $fileExtensions = ['php'];
2016-06-06 07:07:50 +02:00
private function __construct()
{
self::$_config = $this;
}
2016-06-10 00:08:25 +02:00
public static function loadFromXML($file_contents)
{
$config = new self();
$config_xml = new SimpleXMLElement($file_contents);
if (isset($config_xml['stopOnError'])) {
$config->stopOnError = (bool) $config_xml['stopOnError'];
}
if (isset($config_xml['useDocblockReturnType'])) {
$config->stopOnError = (bool) $config_xml['useDocblockReturnType'];
}
if (isset($config_xml->inspectFiles)) {
$config->inspectFiles = new FileFilter($config_xml->inspectFiles);
}
if (isset($config_xml->fileExtensions)) {
$config->fileExtensions = [];
if ($config_xml->fileExtensions->extension instanceof SimpleXMLElement) {
$config->fileExtensions[] = preg_replace('/^.?/', '', $config_xml->fileExtensions->extension);
}
else {
foreach ($config_xml->fileExtensions->extension as $extension) {
$config->fileExtensions[] = preg_replace('/^.?/', '', $extension);
}
}
$config->inspectFiles = new FileFilter($config_xml->inspectFiles);
}
}
/**
* @return $this
*/
2016-06-06 07:07:50 +02:00
public static function getInstance()
{
if (self::$_config) {
return self::$_config;
}
return new self();
}
2016-06-10 00:08:25 +02:00
public function excludeIssueInFile($issue_type, $file_name)
{
}
2016-06-06 07:07:50 +02:00
public function doesInheritVariables($file_name)
{
return false;
}
2016-06-10 00:08:25 +02:00
public function getFilesToCheck()
{
$files = $this->inspectFiles->getIncludeFiles();
foreach ($this->inspectFiles->getIncludeFolders() as $folder) {
/** @var RecursiveDirectoryIterator */
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder));
$iterator->rewind();
while ($iterator->valid()) {
if (!$iterator->isDot()) {
if (in_array($iterator->getExtension(), $this->extensions)) {
$files[] = $iterator->getRealPath();
}
}
$iterator->next();
}
}
return $files;
}
2016-06-06 07:07:50 +02:00
}