diff --git a/.gitignore b/.gitignore index 94d6d75..4fbb073 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ /vendor/ -/composer.lock \ No newline at end of file +/composer.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d69e9f..18952cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,25 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added +- Added .gitattributes from [@reedy](https://github.com/reedy). + +### Fixed + +- PHP 7.4: fix compatibility issue [#7](https://github.com/php-parallel-lint/PHP-Var-Dump-Check/pull/7) from [@jrfnl](https://github.com/jrfnl). + +### Internal + +- Replaced array syntax with short array syntax from [@peter279k](https://github.com/peter279k). +- Added EOF (end of file) for some PHP files from [@peter279k](https://github.com/peter279k). +- Removed $loader variable on bootstrap.php file because it's unused from [@peter279k](https://github.com/peter279k). +- To be compatible with future PHPUnit version, using the ^4.8.36 version at least from [@peter279k](https://github.com/peter279k). +- Changed namespace to PHPunit\Framework\TestCase class namesapce from [@peter279k](https://github.com/peter279k). +- Composer: allow installation of more recent Parallel Lint [#9](https://github.com/php-parallel-lint/PHP-Var-Dump-Check/pull/9) from [@jrfnl](https://github.com/jrfnl). + +## [v0.4] - 2020-04-25 + +### Added + - Added check for Symfony dump function `dd` from [@antograssiot](https://github.com/antograssiot). - Added check for Laravel dump function `dump` from [@Douglasdc3](https://github.com/Douglasdc3). - Added changelog. diff --git a/README.md b/README.md index 1c7bb3b..f2d42e2 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Options for run - `--doctrine` - check dump: `Doctrine::dump`, `\Doctrine\Common\Util\Debug::dump` - `--symfony` - check dump: `dump`, `VarDumper::dump`, `VarDumper::setHandler`, `VarDumper::dd` - `--laravel` - check dump: `dd`, `dump` +- `--custom-function` - comma separated custom function name(s) to check like `pre_echo` - `--no-colors` - disable colors from output - `--exclude folder/` - exclude *folder/* from check - `--extensions php,phpt,php7` - map file extensions for check diff --git a/src/Settings.php b/src/Settings.php index a35d60d..8a61636 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -74,6 +74,7 @@ public static function parseArguments(array $arguments) { $arguments = new ArrayIterator(array_slice($arguments, 1)); $setting = new self; + $customFunctions = array(); foreach ($arguments as $argument) { if ($argument[0] !== '-') { @@ -124,6 +125,10 @@ public static function parseArguments(array $arguments) $setting->functionsToCheck[] = self::LARAVEL_DUMP; break; + case '--custom-function': + $customFunctions = array_map('trim', explode(',', $arguments->getNext())); + break; + case '--doctrine': $setting->functionsToCheck[] = self::DOCTRINE_DUMP; $setting->functionsToCheck[] = self::DOCTRINE_DUMP_2; @@ -134,7 +139,11 @@ public static function parseArguments(array $arguments) } } } + + // Merge if any custom function is given + $setting->functionsToCheck = array_merge($setting->functionsToCheck, $customFunctions); $setting->functionsToCheck = array_unique($setting->functionsToCheck); + return $setting; } diff --git a/tests/JakubOnderka/PhpVarDumpCheck/CustomFunctionTest.php b/tests/JakubOnderka/PhpVarDumpCheck/CustomFunctionTest.php new file mode 100644 index 0000000..75f1883 --- /dev/null +++ b/tests/JakubOnderka/PhpVarDumpCheck/CustomFunctionTest.php @@ -0,0 +1,79 @@ +functionsToCheck = array_merge($settings->functionsToCheck, array( + 'functionName1' + )); + + $uut = new PhpVarDumpCheck\Checker($settings); + $content = <<check($content); + $this->assertCount(0, $result); + } + + public function testCheck_singleFunction() + { + $settings = new PhpVarDumpCheck\Settings(); + + $settings->functionsToCheck = array_merge($settings->functionsToCheck, array( + 'functionName1' + )); + + $uut = new PhpVarDumpCheck\Checker($settings); + $content = <<check($content); + $this->assertCount(1, $result); + } + + + public function testCheck_multipleFunction() + { + $settings = new PhpVarDumpCheck\Settings(); + + $settings->functionsToCheck = array_merge($settings->functionsToCheck, array( + 'functionName1', + 'functionName2' + )); + + $uut = new PhpVarDumpCheck\Checker($settings); + + $content1 = <<check($content1); + $this->assertCount(1, $result); + + $result = $uut->check($content2); + $this->assertCount(1, $result); + + $result = $uut->check($content3); + $this->assertCount(2, $result); + } +} diff --git a/var-dump-check.php b/var-dump-check.php index 8a30870..8e18c63 100644 --- a/var-dump-check.php +++ b/var-dump-check.php @@ -15,19 +15,20 @@ function showOptions() { ?> Options: - --tracy Enable support for Tracy (Debugger::dump) - --zend Enable support for Zend (Zend_Debug::dump and \Zend\Debug\Debug::dump) - --ladybug Enable support for Ladybug (ladybug_dump, ladybug_dump_die, ld, ldd) - --symfony Enable support for Symfony2 (dump, VarDumper::dump, VarDumper::setHandler, Vardumper::dd()) - --doctrine Enable support for Doctrine (Doctrine::dump, \Doctrine\Common\Util\Debug::dump) - --laravel Enable support for Laravel (dd, dump) - --extensions Check only files with selected extensions separated by comma - (default: php, php3, php4, php5, phtml) - --exclude Exclude directory. If you want exclude multiple directory, use - multiple exclude parameters. - --no-colors Disable colors in console output. - -V, --version Show version. - -h, --help Print this help. + --tracy Enable support for Tracy (Debugger::dump) + --zend Enable support for Zend (Zend_Debug::dump and \Zend\Debug\Debug::dump) + --ladybug Enable support for Ladybug (ladybug_dump, ladybug_dump_die, ld, ldd) + --symfony Enable support for Symfony2 (dump, VarDumper::dump, VarDumper::setHandler, Vardumper::dd()) + --doctrine Enable support for Doctrine (Doctrine::dump, \Doctrine\Common\Util\Debug::dump) + --laravel Enable support for Laravel (dd, dump) + --custom-function Comma separated custom function name(s) to check like "pre_echo". + --extensions Check only files with selected extensions separated by comma + (default: php, php3, php4, php5, phtml) + --exclude Exclude directory. If you want exclude multiple directory, use + multiple exclude parameters. + --no-colors Disable colors in console output. + -V, --version Show version. + -h, --help Print this help.