From ff466b79923d0ea2bcd59f16370fce8df569901e Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Thu, 29 Dec 2016 08:42:39 -0500 Subject: [PATCH] Change config API --- psalm.xml | 41 +++++++++++----------- src/Psalm/Config.php | 18 +++++----- src/Psalm/Config/FileFilter.php | 60 ++++++++++++++++----------------- tests/ArrayAccessTest.php | 4 +-- tests/ArrayAssignmentTest.php | 2 +- tests/FunctionCallTest.php | 2 +- tests/IssueSuppressionTest.php | 8 ++--- tests/MethodCallTest.php | 2 +- tests/Php70Test.php | 4 +-- tests/PropertyTypeTest.php | 8 ++--- 10 files changed, 75 insertions(+), 74 deletions(-) diff --git a/psalm.xml b/psalm.xml index adca273c0..9dd056e33 100644 --- a/psalm.xml +++ b/psalm.xml @@ -6,66 +6,67 @@ totallyTyped="true" strictBinaryOperands="false" > - + - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 5147a4f8b..ea2f064b8 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -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(); } /** diff --git a/src/Psalm/Config/FileFilter.php b/src/Psalm/Config/FileFilter.php index bfcd0cf35..059a912e7 100644 --- a/src/Psalm/Config/FileFilter.php +++ b/src/Psalm/Config/FileFilter.php @@ -8,32 +8,32 @@ class FileFilter /** * @var array */ - protected $include_dirs = []; + protected $only_dirs = []; /** * @var array */ - protected $exclude_dirs = []; + protected $ignore_dirs = []; /** * @var array */ - protected $include_files = []; + protected $only_files = []; /** * @var array */ - protected $include_files_lowercase = []; + protected $only_files_lowercase = []; /** * @var array */ - protected $exclude_files = []; + protected $ignore_files = []; /** * @var array */ - protected $exclude_files_lowercase = []; + protected $ignore_files_lowercase = []; /** * @var array @@ -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); } } diff --git a/tests/ArrayAccessTest.php b/tests/ArrayAccessTest.php index fec890eb0..46352648d 100644 --- a/tests/ArrayAccessTest.php +++ b/tests/ArrayAccessTest.php @@ -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'); diff --git a/tests/ArrayAssignmentTest.php b/tests/ArrayAssignmentTest.php index 9e8bdc6b2..a3c002cdb 100644 --- a/tests/ArrayAssignmentTest.php +++ b/tests/ArrayAssignmentTest.php @@ -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'); diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index 3a3139516..7388abe57 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -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('addExcludeFile('somefile.php'); + $filter->addIgnoreFile('somefile.php'); Config::getInstance()->setIssueHandler('UndefinedFunction', $filter); $stmts = self::$parser->parse('addIncludeFile('somefile.php'); + $filter->addOnlyFile('somefile.php'); Config::getInstance()->setIssueHandler('UndefinedFunction', $filter); $stmts = self::$parser->parse('addExcludeDirectory('src'); + $filter->addIgnoreDirectory('src'); Config::getInstance()->setIssueHandler('UndefinedFunction', $filter); $stmts = self::$parser->parse('addIncludeDirectory('src2'); + $filter->addOnlyDirectory('src2'); Config::getInstance()->setIssueHandler('UndefinedFunction', $filter); (new FileChecker( diff --git a/tests/MethodCallTest.php b/tests/MethodCallTest.php index 4f6f6c7f9..2f677d7a2 100644 --- a/tests/MethodCallTest.php +++ b/tests/MethodCallTest.php @@ -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); diff --git a/tests/Php70Test.php b/tests/Php70Test.php index 36db48a1e..7e4d3eba2 100644 --- a/tests/Php70Test.php +++ b/tests/Php70Test.php @@ -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('addExcludeFile('somefile.php'); + $filter->addIgnoreFile('somefile.php'); Config::getInstance()->setIssueHandler('MixedAssignment', $filter); $stmts = self::$parser->parse('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);