Skip to content

Commit 8173def

Browse files
umutphpgrogy
authored andcommitted
Add --custom-function parameter to check
1 parent 6e2f84b commit 8173def

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

src/Settings.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public static function parseArguments(array $arguments)
7474
{
7575
$arguments = new ArrayIterator(array_slice($arguments, 1));
7676
$setting = new self;
77+
$customFunctions = array();
7778

7879
foreach ($arguments as $argument) {
7980
if ($argument[0] !== '-') {
@@ -124,6 +125,10 @@ public static function parseArguments(array $arguments)
124125
$setting->functionsToCheck[] = self::LARAVEL_DUMP;
125126
break;
126127

128+
case '--custom-function':
129+
$customFunctions = array_map('trim', explode(',', $arguments->getNext()));
130+
break;
131+
127132
case '--doctrine':
128133
$setting->functionsToCheck[] = self::DOCTRINE_DUMP;
129134
$setting->functionsToCheck[] = self::DOCTRINE_DUMP_2;
@@ -134,7 +139,11 @@ public static function parseArguments(array $arguments)
134139
}
135140
}
136141
}
142+
143+
// Merge if any custom function is given
144+
$setting->functionsToCheck = array_merge($setting->functionsToCheck, $customFunctions);
137145
$setting->functionsToCheck = array_unique($setting->functionsToCheck);
146+
138147
return $setting;
139148
}
140149

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
use JakubOnderka\PhpVarDumpCheck;
4+
5+
class CustomFunctionTest extends PHPUnit_Framework_TestCase
6+
{
7+
8+
public function testCheck_noDebugFunction()
9+
{
10+
$settings = new PhpVarDumpCheck\Settings();
11+
12+
$settings->functionsToCheck = array_merge($settings->functionsToCheck, array(
13+
'functionName1'
14+
));
15+
16+
$uut = new PhpVarDumpCheck\Checker($settings);
17+
$content = <<<PHP
18+
<?php
19+
nonDebugFunction1(\$var);
20+
\$i++;
21+
nonDebugFunction2(\$i);
22+
PHP;
23+
$result = $uut->check($content);
24+
$this->assertCount(0, $result);
25+
}
26+
27+
public function testCheck_singleFunction()
28+
{
29+
$settings = new PhpVarDumpCheck\Settings();
30+
31+
$settings->functionsToCheck = array_merge($settings->functionsToCheck, array(
32+
'functionName1'
33+
));
34+
35+
$uut = new PhpVarDumpCheck\Checker($settings);
36+
$content = <<<PHP
37+
<?php
38+
functionName1(\$var);
39+
PHP;
40+
$result = $uut->check($content);
41+
$this->assertCount(1, $result);
42+
}
43+
44+
45+
public function testCheck_multipleFunction()
46+
{
47+
$settings = new PhpVarDumpCheck\Settings();
48+
49+
$settings->functionsToCheck = array_merge($settings->functionsToCheck, array(
50+
'functionName1',
51+
'functionName2'
52+
));
53+
54+
$uut = new PhpVarDumpCheck\Checker($settings);
55+
56+
$content1 = <<<PHP
57+
<?php
58+
functionName1(\$var);
59+
PHP;
60+
$content2 = <<<PHP
61+
<?php
62+
functionName2(\$var);
63+
PHP;
64+
$content3 = <<<PHP
65+
<?php
66+
functionName1(\$var);
67+
sleep(4);
68+
functionName2(\$var);
69+
PHP;
70+
$result = $uut->check($content1);
71+
$this->assertCount(1, $result);
72+
73+
$result = $uut->check($content2);
74+
$this->assertCount(1, $result);
75+
76+
$result = $uut->check($content3);
77+
$this->assertCount(2, $result);
78+
}
79+
}

var-dump-check.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function showOptions() {
2121
--symfony Enable support for Symfony2 (dump, VarDumper::dump, VarDumper::setHandler, Vardumper::dd())
2222
--doctrine Enable support for Doctrine (Doctrine::dump, \Doctrine\Common\Util\Debug::dump)
2323
--laravel Enable support for Laravel (dd, dump)
24+
--custom-function Comma separated custom function name(s) to check like "pre_echo".
2425
--extensions Check only files with selected extensions separated by comma
2526
(default: php, php3, php4, php5, phtml)
2627
--exclude Exclude directory. If you want exclude multiple directory, use

0 commit comments

Comments
 (0)