Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --custom-function parameter to check. #32

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
72e3c10
Add --custom-function parameter to add custom functions to the list o…
Dec 11, 2018
3940349
Add test for custom function parameter and add .idea folder to gitignore
Dec 11, 2018
a43368b
Revert the .idea folder
umutphp Jan 5, 2019
73dcc40
Implement the CR "Please use ` instead of " to match other parameters…
umutphp Jan 5, 2019
5c74a77
Empty is used instead of count($customFunctions) > 0
umutphp Jan 5, 2019
a3a361b
Merge branch 'master' into master
umutphp Jan 5, 2019
7643a89
Changed package name - new organization
grogy Feb 12, 2020
379a852
Changed suggested and required-dev packages to new organization
grogy Feb 12, 2020
c7a5689
Changed Travis-CI icon
grogy Feb 12, 2020
472158d
Changed icon for download per month for new organization
grogy Feb 14, 2020
63ef93f
Changed last version icon by new organization
grogy Feb 14, 2020
115b3e1
Fixed running tests in PHP 5.4 and PHP 5.5 in CI
grogy Feb 15, 2020
c9d56de
Fixed Travis CI configuration
grogy Feb 16, 2020
36c1a45
Added replace to composer for previous package
grogy Mar 15, 2020
85bfd1d
Added changelog
grogy Apr 25, 2020
7a02375
Added run CI with PHP 7.4
grogy Apr 25, 2020
758205c
Fixed vendor names in readme for install
grogy Apr 25, 2020
1ce12ed
Created version 0.4
grogy Apr 25, 2020
34d2bce
Create .gitattributes
reedy Apr 27, 2020
49e9706
Added .gitattributes to changelog
grogy May 14, 2020
b6763f2
Replace array syntax with short array syntax
peter279k May 26, 2020
557fd99
Added PHP array syntax to changelog
grogy May 27, 2020
71c87a2
Enhance test stuffs
peter279k May 26, 2020
00e90ca
Added cleaning changes to changelog
grogy May 27, 2020
5eb9b25
Composer: allow installation of more recent Parallel Lint
jrfnl Jun 28, 2020
e22ce7f
Added internal change to changelog
grogy Aug 14, 2020
1485b29
PHP 7.4: fix compatibility issue
jrfnl Jun 28, 2020
a10a2fc
Added fix for PHP 7.4 to changelog
grogy Aug 14, 2020
43d823b
Merge remote-tracking branch 'upstream/master'
umutphp Aug 14, 2020
6e2a072
Add test for none function founded
umutphp Aug 14, 2020
38513d0
Remove horizontal align
umutphp Aug 14, 2020
5495e34
Remove unneccessary empty check
umutphp Aug 14, 2020
e537cda
Add the Symfony Vardumper dd() helper method introduced in 4.1
umutphp Aug 14, 2020
66a65a8
Changed package name - new organization
grogy Feb 12, 2020
eee8857
Fixed Travis CI configuration
grogy Feb 16, 2020
417f968
Added replace to composer for previous package
grogy Mar 15, 2020
95e0158
Added run CI with PHP 7.4
grogy Apr 25, 2020
f58fae3
Fixed vendor names in readme for install
grogy Apr 25, 2020
562b7aa
Created version 0.4
grogy Apr 25, 2020
5847d7e
Create .gitattributes
reedy Apr 27, 2020
a29a7eb
Added .gitattributes to changelog
grogy May 14, 2020
f79cba3
Replace array syntax with short array syntax
peter279k May 26, 2020
f7886fd
Added PHP array syntax to changelog
grogy May 27, 2020
d6cf4df
Added cleaning changes to changelog
grogy May 27, 2020
e779ac4
Composer: allow installation of more recent Parallel Lint
jrfnl Jun 28, 2020
5941fae
Added internal change to changelog
grogy Aug 14, 2020
252cd39
PHP 7.4: fix compatibility issue
jrfnl Jun 28, 2020
0f7b965
Added fix for PHP 7.4 to changelog
grogy Aug 14, 2020
52d9da7
Add test for none function founded
umutphp Aug 14, 2020
6476f7b
Remove horizontal align
umutphp Aug 14, 2020
10fecd3
Remove unneccessary empty check
umutphp Aug 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
phpunit.xml export-ignore
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/vendor/
/composer.lock
/composer.lock
20 changes: 12 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
matrix:
include:
- php: 5.4
dist: trusty
- php: 5.5
dist: trusty
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4

sudo: false

Expand Down
56 changes: 56 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### 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 .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.
- Added support for PHP 7.4.

### Internal

- Fixed running tests in PHP 5.4 and PHP 5.5 in CI.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Just create a `composer.json` file and run the `php composer.phar install` comma
```json
{
"require-dev": {
"jakub-onderka/php-var-dump-check": "~0.3"
"php-parallel-lint/php-var-dump-check": "~0.4"
}
}
```

For colored output install suggested package `jakub-onderka/php-console-highlighter`.
For colored output install suggested package `php-parallel-lint/php-console-highlighter`.

Usage and example output
--------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -79,6 +80,6 @@ or setting for ANT:

------

[![Build Status](https://travis-ci.org/JakubOnderka/PHP-Var-Dump-Check.svg?branch=master)](https://travis-ci.org/JakubOnderka/PHP-Var-Dump-Check)
[![Downloads this Month](https://img.shields.io/packagist/dm/jakub-onderka/php-var-dump-check.svg)](https://packagist.org/packages/jakub-onderka/php-var-dump-check)
[![Latest stable](https://img.shields.io/packagist/v/jakub-onderka/php-var-dump-check.svg)](https://packagist.org/packages/jakub-onderka/php-var-dump-check)
[![Build Status](https://travis-ci.org/php-parallel-lint/PHP-Var-Dump-Check.svg?branch=master)](https://travis-ci.org/php-parallel-lint/PHP-Var-Dump-Check)
[![Downloads this Month](https://img.shields.io/packagist/dm/php-parallel-lint/php-var-dump-check.svg)](https://packagist.org/packages/php-parallel-lint/php-var-dump-check)
[![Latest stable](https://img.shields.io/packagist/v/php-parallel-lint/php-var-dump-check.svg)](https://packagist.org/packages/php-parallel-lint/php-var-dump-check)
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "jakub-onderka/php-var-dump-check",
"name": "php-parallel-lint/php-var-dump-check",
"license": "BSD-2-Clause",
"description": "Find forgotten variables dump in PHP source code.",
"authors": [
Expand All @@ -15,11 +15,14 @@
"php": ">=5.4.0"
},
"suggest": {
"jakub-onderka/php-console-highlighter": "For colored console output"
"php-parallel-lint/php-console-highlighter": "For colored console output"
},
"require-dev": {
"phpunit/phpunit": "~4.5",
"jakub-onderka/php-parallel-lint": "~1.0"
"phpunit/phpunit": "^4.8.36",
"php-parallel-lint/php-parallel-lint": "^1.0"
},
"bin": ["var-dump-check"]
"bin": ["var-dump-check"],
"replace": {
"jakub-onderka/php-var-dump-check": "*"
}
}
30 changes: 15 additions & 15 deletions src/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function check($content)
*/
protected function checkForDumps(array $tokens)
{
$results = array();
$results = [];

$functionsToCheck = $this->prepareFunctionCheck($this->settings->functionsToCheck);

Expand Down Expand Up @@ -116,19 +116,19 @@ protected function checkFunctionCall(array $tokens, $from, FunctionConditions $c
list($ok, $arguments) = $this->checkIsFunctionCall($tokens, $from);

if (!$ok) {
return array(false, true);
return [false, true];
}

if ($conditions) {
if (isset($arguments[$conditions->getArgumentNumber() - 1])) {
list($isTrue, $sure) = $arguments[$conditions->getArgumentNumber() - 1]->isTrue();
return array($isTrue === $conditions->getMustBe(), $sure);
return [$isTrue === $conditions->getMustBe(), $sure];
} else {
return $conditions->getMustBe() === $conditions->getDefault() ? array(true, true) : array(false, true);
return $conditions->getMustBe() === $conditions->getDefault() ? [true, true] : [false, true];
}
}

return array(true, true);
return [true, true];
}

/**
Expand All @@ -138,7 +138,7 @@ protected function checkFunctionCall(array $tokens, $from, FunctionConditions $c
*/
protected function checkIsFunctionCall(array $tokens, $from)
{
$arguments = array();
$arguments = [];

$count = 0;
$argumentFrom = 0;
Expand All @@ -152,15 +152,15 @@ protected function checkIsFunctionCall(array $tokens, $from)
} else if ($tokens[$i] === ')') {
if (--$count === 0) {
$arguments[] = new FunctionArgument(array_slice($tokens, $argumentFrom, $i - $argumentFrom));
return array(true, $arguments);
return [true, $arguments];
}
} else if ($tokens[$i] === ',' && $count === 1) {
$arguments[] = new FunctionArgument(array_slice($tokens, $argumentFrom, $i - $argumentFrom));
$argumentFrom = $i + 1;
}
}

return array(false, $arguments);
return [false, $arguments];
}

/**
Expand All @@ -183,7 +183,7 @@ protected function tokenize($content)
*/
protected function prepareFunctionCheck(array $functionsToCheck)
{
$output = array();
$output = [];

foreach ($functionsToCheck as $function) {
$namespaces = explode('\\', $function);
Expand All @@ -195,34 +195,34 @@ protected function prepareFunctionCheck(array $functionsToCheck)
list($first, $second) = explode('::', $namespace);

if (!isset($next[$first])) {
$next[$first] = array();
$next[$first] = [];
}
$next = &$next[$first];

if (!isset($next[T_DOUBLE_COLON])) {
$next[T_DOUBLE_COLON] = array();
$next[T_DOUBLE_COLON] = [];
}
$next = &$next[T_DOUBLE_COLON];

if (!isset($next[$second])) {
$next[$second] = array();
$next[$second] = [];
}
$next = &$next[$second];
} else if (!empty($namespace)) {
if (!isset($next[$namespace])) {
$next[$namespace] = array();
$next[$namespace] = [];
}
$next = &$next[$namespace];

if (isset($namespaces[$key + 1])) {
if (!isset($next[T_NS_SEPARATOR])) {
$next[T_NS_SEPARATOR] = array();
$next[T_NS_SEPARATOR] = [];
}
$next = &$next[T_NS_SEPARATOR];
}
} else {
if (!isset($next[T_NS_SEPARATOR])) {
$next[T_NS_SEPARATOR] = array();
$next[T_NS_SEPARATOR] = [];
}
$next = &$next[T_NS_SEPARATOR];
}
Expand Down
6 changes: 3 additions & 3 deletions src/FunctionArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class FunctionArgument
{
/** @var array */
protected $tokens = array();
protected $tokens = [];

public function __construct($tokens)
{
Expand All @@ -25,7 +25,7 @@ public function isTrue()
$token = strtolower($token);
if ($tokenType === T_COMMENT) {
continue;
} else if ($tokenType === T_STRING && in_array($token, array('true', 'false', 'null'))) {
} else if ($tokenType === T_STRING && in_array($token, ['true', 'false', 'null'])) {
if ($token === 'true') {
$prediction = true;
} else {
Expand All @@ -50,7 +50,7 @@ public function isTrue()
}
}

return array($prediction, $sure);
return [$prediction, $sure];
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function check(Settings $settings, Output $output = null)
$output->setTotalFileCount($checkedFiles);

/** @var Result[] $results */
$results = array();
$results = [];

$startTime = microtime(true);
$checkedFiles = 0;
Expand Down Expand Up @@ -121,10 +121,10 @@ protected function loadFile($filename)
* @return array
* @throws Exception\NotExistsPath
*/
protected function getFilesFromPaths(array $paths, array $extensions, array $excluded = array())
protected function getFilesFromPaths(array $paths, array $extensions, array $excluded = [])
{
$extensions = array_flip($extensions);
$files = array();
$files = [];

foreach ($paths as $path) {
if (is_file($path)) {
Expand Down
6 changes: 3 additions & 3 deletions src/RecursiveDirectoryFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class RecursiveDirectoryFilterIterator extends \RecursiveFilterIterator
private $iterator;

/** @var array */
private $excluded = array();
private $excluded = [];

/**
* @param \RecursiveDirectoryIterator $iterator
Expand All @@ -17,7 +17,7 @@ public function __construct(\RecursiveDirectoryIterator $iterator, array $exclud
{
parent::__construct($iterator);
$this->iterator = $iterator;
$this->excluded = array_map(array($this, 'getPathname'), $excluded);
$this->excluded = array_map([$this, 'getPathname'], $excluded);
}

/**
Expand Down Expand Up @@ -85,6 +85,6 @@ private function getPathname($file)
*/
private function normalizeDirectorySeparator($file)
{
return str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $file);
return str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $file);
}
}
Loading