1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Change config API

This commit is contained in:
Matthew Brown 2016-12-29 08:42:39 -05:00
parent 641ffc09c9
commit ff466b7992
10 changed files with 75 additions and 74 deletions

View File

@ -6,66 +6,67 @@
totallyTyped="true"
strictBinaryOperands="false"
>
<inspectFiles>
<projectFiles>
<directory name="src" />
<directory name="tests" />
</inspectFiles>
</projectFiles>
<issueHandler>
<NullOperand errorLevel="suppress" />
<MissingReturnType>
<excludeFiles>
<ignoreFiles>
<directory name="tests" />
</excludeFiles>
</ignoreFiles>
</MissingReturnType>
<MissingPropertyType>
<excludeFiles>
<ignoreFiles>
<directory name="tests" />
</excludeFiles>
</ignoreFiles>
</MissingPropertyType>
<MixedArgument>
<excludeFiles>
<ignoreFiles>
<directory name="tests" />
</excludeFiles>
</ignoreFiles>
</MixedArgument>
<MixedOperand>
<excludeFiles>
<ignoreFiles>
<directory name="tests" />
</excludeFiles>
</ignoreFiles>
</MixedOperand>
<MixedPropertyFetch>
<excludeFiles>
<ignoreFiles>
<directory name="tests" />
</excludeFiles>
</ignoreFiles>
</MixedPropertyFetch>
<NoInterfaceProperties>
<excludeFiles>
<ignoreFiles>
<directory name="tests" />
</excludeFiles>
</ignoreFiles>
</NoInterfaceProperties>
<NullArrayAccess>
<excludeFiles>
<ignoreFiles>
<directory name="tests" />
</excludeFiles>
</ignoreFiles>
</NullArrayAccess>
<NullPropertyFetch>
<excludeFiles>
<ignoreFiles>
<directory name="tests" />
</excludeFiles>
</ignoreFiles>
</NullPropertyFetch>
<NullArgument>
<excludeFiles>
<ignoreFiles>
<directory name="tests" />
</excludeFiles>
</ignoreFiles>
</NullArgument>
</issueHandler>
</psalm>

View File

@ -88,7 +88,7 @@ class Config
/**
* @var FileFilter|null
*/
protected $inspect_files;
protected $project_files;
/**
* The base directory of this config file
@ -228,8 +228,8 @@ class Config
$config->strict_binary_operands = $attribute_text === 'true' || $attribute_text === '1';
}
if (isset($config_xml->inspectFiles)) {
$config->inspect_files = FileFilter::loadFromXML($config_xml->inspectFiles, true);
if (isset($config_xml->projectFiles)) {
$config->project_files = FileFilter::loadFromXML($config_xml->projectFiles, true);
}
if (isset($config_xml->fileExtensions)) {
@ -289,12 +289,12 @@ class Config
$config->custom_error_levels[$key] = $error_level;
}
if (isset($issue_handler->excludeFiles)) {
$config->issue_handlers[$key] = FileFilter::loadFromXML($issue_handler->excludeFiles, false);
if (isset($issue_handler->ignoreFiles)) {
$config->issue_handlers[$key] = FileFilter::loadFromXML($issue_handler->ignoreFiles, false);
}
if (isset($issue_handler->includeFiles)) {
$config->issue_handlers[$key] = FileFilter::loadFromXML($issue_handler->includeFiles, true);
if (isset($issue_handler->onlyFiles)) {
$config->issue_handlers[$key] = FileFilter::loadFromXML($issue_handler->onlyFiles, true);
}
}
}
@ -439,11 +439,11 @@ class Config
*/
public function getIncludeDirs()
{
if (!$this->inspect_files) {
if (!$this->project_files) {
return [];
}
return $this->inspect_files->getIncludeDirs();
return $this->project_files->getIncludeDirs();
}
/**

View File

@ -8,32 +8,32 @@ class FileFilter
/**
* @var array<string>
*/
protected $include_dirs = [];
protected $only_dirs = [];
/**
* @var array<string>
*/
protected $exclude_dirs = [];
protected $ignore_dirs = [];
/**
* @var array<string>
*/
protected $include_files = [];
protected $only_files = [];
/**
* @var array<string>
*/
protected $include_files_lowercase = [];
protected $only_files_lowercase = [];
/**
* @var array<string>
*/
protected $exclude_files = [];
protected $ignore_files = [];
/**
* @var array<string>
*/
protected $exclude_files_lowercase = [];
protected $ignore_files_lowercase = [];
/**
* @var array<string>
@ -77,28 +77,28 @@ class FileFilter
if ($e->directory) {
/** @var \SimpleXMLElement $directory */
foreach ($e->directory as $directory) {
$filter->addIncludeDirectory((string)$directory['name']);
$filter->addOnlyDirectory((string)$directory['name']);
}
}
if ($e->file) {
/** @var \SimpleXMLElement $file */
foreach ($e->file as $file) {
$filter->addIncludeFile((string)$file['name']);
$filter->addOnlyFile((string)$file['name']);
}
}
} else {
if ($e->directory) {
/** @var \SimpleXMLElement $directory */
foreach ($e->directory as $directory) {
$filter->addExcludeDirectory((string)$directory['name']);
$filter->addIgnoreDirectory((string)$directory['name']);
}
}
if ($e->file) {
/** @var \SimpleXMLElement $file */
foreach ($e->file as $file) {
$filter->addExcludeFile((string)$file['name']);
$filter->addIgnoreFile((string)$file['name']);
}
}
}
@ -123,7 +123,7 @@ class FileFilter
public function allows($file_name, $case_sensitive = false)
{
if ($this->inclusive) {
foreach ($this->include_dirs as $include_dir) {
foreach ($this->only_dirs as $include_dir) {
if ($case_sensitive) {
if (strpos($file_name, $include_dir) === 0) {
return true;
@ -136,11 +136,11 @@ class FileFilter
}
if ($case_sensitive) {
if (in_array($file_name, $this->include_files)) {
if (in_array($file_name, $this->only_files)) {
return true;
}
} else {
if (in_array(strtolower($file_name), $this->include_files_lowercase)) {
if (in_array(strtolower($file_name), $this->only_files_lowercase)) {
return true;
}
}
@ -149,7 +149,7 @@ class FileFilter
}
// exclusive
foreach ($this->exclude_dirs as $exclude_dir) {
foreach ($this->ignore_dirs as $exclude_dir) {
if ($case_sensitive) {
if (strpos($file_name, $exclude_dir) === 0) {
return false;
@ -162,11 +162,11 @@ class FileFilter
}
if ($case_sensitive) {
if (in_array($file_name, $this->exclude_files)) {
if (in_array($file_name, $this->ignore_files)) {
return false;
}
} else {
if (in_array(strtolower($file_name), $this->exclude_files_lowercase)) {
if (in_array(strtolower($file_name), $this->ignore_files_lowercase)) {
return false;
}
}
@ -179,7 +179,7 @@ class FileFilter
*/
public function getIncludeDirs()
{
return $this->include_dirs;
return $this->only_dirs;
}
/**
@ -187,7 +187,7 @@ class FileFilter
*/
public function getExcludeDirs()
{
return $this->exclude_dirs;
return $this->ignore_dirs;
}
/**
@ -195,7 +195,7 @@ class FileFilter
*/
public function getIncludeFiles()
{
return $this->include_files;
return $this->only_files;
}
/**
@ -203,52 +203,52 @@ class FileFilter
*/
public function getExcludeFiles()
{
return $this->exclude_files;
return $this->ignore_files;
}
/**
* @param string $file_name
* @return void
*/
public function addExcludeFile($file_name)
public function addIgnoreFile($file_name)
{
if ($this->inclusive !== false) {
throw new \UnexpectedValueException('Cannot add exclude file when filter is not exclusive');
}
$this->exclude_files[] = $file_name;
$this->exclude_files_lowercase[] = strtolower($file_name);
$this->ignore_files[] = $file_name;
$this->ignore_files_lowercase[] = strtolower($file_name);
}
/**
* @param string $file_name
* @return void
*/
public function addIncludeFile($file_name)
public function addOnlyFile($file_name)
{
if ($this->inclusive !== true) {
throw new \UnexpectedValueException('Cannot add include file when filter is not inclusive');
}
$this->include_files[] = $file_name;
$this->include_files_lowercase[] = strtolower($file_name);
$this->only_files[] = $file_name;
$this->only_files_lowercase[] = strtolower($file_name);
}
/**
* @param string $dir_name
* @return void
*/
public function addExcludeDirectory($dir_name)
public function addIgnoreDirectory($dir_name)
{
$this->exclude_dirs[] = self::slashify($dir_name);
$this->ignore_dirs[] = self::slashify($dir_name);
}
/**
* @param string $dir_name
* @return void
*/
public function addIncludeDirectory($dir_name)
public function addOnlyDirectory($dir_name)
{
$this->include_dirs[] = self::slashify($dir_name);
$this->only_dirs[] = self::slashify($dir_name);
}
}

View File

@ -121,7 +121,7 @@ class ArrayAccessTest extends PHPUnit_Framework_TestCase
public function testMixedArrayAccess()
{
$filter = new Config\FileFilter(false);
$filter->addExcludeFile('somefile.php');
$filter->addIgnoreFile('somefile.php');
Config::getInstance()->setIssueHandler('MixedAssignment', $filter);
$context = new Context('somefile.php');
@ -142,7 +142,7 @@ class ArrayAccessTest extends PHPUnit_Framework_TestCase
public function testMixedArrayOffset()
{
$filter = new Config\FileFilter(false);
$filter->addExcludeFile('somefile.php');
$filter->addIgnoreFile('somefile.php');
Config::getInstance()->setIssueHandler('MixedAssignment', $filter);
$context = new Context('somefile.php');

View File

@ -662,7 +662,7 @@ class ArrayAssignmentTest extends PHPUnit_Framework_TestCase
public function testMixedStringOffsetAssignment()
{
$filter = new Config\FileFilter(false);
$filter->addExcludeFile('somefile.php');
$filter->addIgnoreFile('somefile.php');
Config::getInstance()->setIssueHandler('MixedAssignment', $filter);
$context = new Context('somefile.php');

View File

@ -46,7 +46,7 @@ class FunctionCallTest extends PHPUnit_Framework_TestCase
public function testMixedArgument()
{
$filter = new Config\FileFilter(false);
$filter->addExcludeFile('somefile.php');
$filter->addIgnoreFile('somefile.php');
Config::getInstance()->setIssueHandler('MixedAssignment', $filter);
$stmts = self::$parser->parse('<?php

View File

@ -47,7 +47,7 @@ class IssueSuppressionTest extends PHPUnit_Framework_TestCase
public function testExcludeFile()
{
$filter = new Config\FileFilter(false);
$filter->addExcludeFile('somefile.php');
$filter->addIgnoreFile('somefile.php');
Config::getInstance()->setIssueHandler('UndefinedFunction', $filter);
$stmts = self::$parser->parse('<?php
@ -65,7 +65,7 @@ class IssueSuppressionTest extends PHPUnit_Framework_TestCase
public function testIncludeFile()
{
$filter = new Config\FileFilter(true);
$filter->addIncludeFile('somefile.php');
$filter->addOnlyFile('somefile.php');
Config::getInstance()->setIssueHandler('UndefinedFunction', $filter);
$stmts = self::$parser->parse('<?php
@ -86,7 +86,7 @@ class IssueSuppressionTest extends PHPUnit_Framework_TestCase
public function testExcludeDirectory()
{
$filter = new Config\FileFilter(false);
$filter->addExcludeDirectory('src');
$filter->addIgnoreDirectory('src');
Config::getInstance()->setIssueHandler('UndefinedFunction', $filter);
$stmts = self::$parser->parse('<?php
@ -104,7 +104,7 @@ class IssueSuppressionTest extends PHPUnit_Framework_TestCase
public function testIncludeDirectory()
{
$filter = new Config\FileFilter(true);
$filter->addIncludeDirectory('src2');
$filter->addOnlyDirectory('src2');
Config::getInstance()->setIssueHandler('UndefinedFunction', $filter);
(new FileChecker(

View File

@ -64,7 +64,7 @@ class MethodCallTest extends PHPUnit_Framework_TestCase
public function testMixedMethodCall()
{
$filter = new Config\FileFilter(false);
$filter->addExcludeFile('somefile.php');
$filter->addIgnoreFile('somefile.php');
Config::getInstance()->setIssueHandler('MissingPropertyType', $filter);
Config::getInstance()->setIssueHandler('MixedAssignment', $filter);

View File

@ -74,7 +74,7 @@ class Php70Test extends PHPUnit_Framework_TestCase
public function testNullCoalesce()
{
$filter = new Config\FileFilter(false);
$filter->addExcludeFile('somefile.php');
$filter->addIgnoreFile('somefile.php');
Config::getInstance()->setIssueHandler('MixedAssignment', $filter);
$stmts = self::$parser->parse('<?php
@ -172,7 +172,7 @@ class Php70Test extends PHPUnit_Framework_TestCase
public function testGeneratorDelegation()
{
$filter = new Config\FileFilter(false);
$filter->addExcludeFile('somefile.php');
$filter->addIgnoreFile('somefile.php');
Config::getInstance()->setIssueHandler('MixedAssignment', $filter);
$stmts = self::$parser->parse('<?php

View File

@ -55,7 +55,7 @@ class PropertyTypeTest extends PHPUnit_Framework_TestCase
public function testPropertyWithoutTypeSuppressingIssue()
{
$filter = new Config\FileFilter(false);
$filter->addExcludeFile('somefile.php');
$filter->addIgnoreFile('somefile.php');
Config::getInstance()->setIssueHandler('MissingPropertyType', $filter);
Config::getInstance()->setIssueHandler('MixedAssignment', $filter);
@ -134,7 +134,7 @@ class PropertyTypeTest extends PHPUnit_Framework_TestCase
public function foo() : void {
echo $this->foo;
}
}
}
');
$file_checker = new FileChecker('somefile.php', $stmts);
@ -291,7 +291,7 @@ class PropertyTypeTest extends PHPUnit_Framework_TestCase
public function testMixedPropertyFetch()
{
$filter = new Config\FileFilter(false);
$filter->addExcludeFile('somefile.php');
$filter->addIgnoreFile('somefile.php');
Config::getInstance()->setIssueHandler('MissingPropertyType', $filter);
Config::getInstance()->setIssueHandler('MixedAssignment', $filter);
@ -319,7 +319,7 @@ class PropertyTypeTest extends PHPUnit_Framework_TestCase
public function testMixedPropertyAssignment()
{
$filter = new Config\FileFilter(false);
$filter->addExcludeFile('somefile.php');
$filter->addIgnoreFile('somefile.php');
Config::getInstance()->setIssueHandler('MissingPropertyType', $filter);
Config::getInstance()->setIssueHandler('MixedAssignment', $filter);