Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changing in_array to isset() since its _much_ faster.

  • Loading branch information...
commit d4a21a1778df89a40618d78f2b879e0895041f08 1 parent ee90231
Michael Nitschinger daschl authored
17 test/rules/HasCorrectVariableNames.php
View
@@ -13,17 +13,22 @@
class HasCorrectVariableNames extends \li3_quality\test\Rule {
protected $_superglobals = array(
- '$GLOBALS', '$_SERVER', '$_GET', '$_POST',
- '$_FILES', '$_COOKIE', '$_SESSION',
- '$_REQUEST', '$_ENV'
+ '$GLOBALS' => true,
+ '$_SERVER' => true,
+ '$_GET' => true,
+ '$_POST' => true,
+ '$_FILES' => true,
+ '$_COOKIE' => true,
+ '$_SESSION' => true,
+ '$_REQUEST' => true,
+ '$_ENV' => true
);
public function apply($testable) {
$tokens = $testable->tokens();
- foreach($tokens as $token) {
- $isSuperglobal = in_array($token['content'], $this->_superglobals);
- if($token['name'] == 'T_VARIABLE' && !$isSuperglobal) {
+ foreach($tokens as $token) {
+ if($token['name'] == 'T_VARIABLE' && !isset($this->_superglobals[$token['content']])) {
$name = preg_replace('/(\$_?|_+$)/', '', $token['content']);
if($name != Inflector::camelize($name, false)) {
$this->addViolation(array(
19 test/rules/HasNoForbiddenStatements.php
View
@@ -11,17 +11,24 @@
class HasNoForbiddenStatements extends \li3_quality\test\Rule {
protected $_forbidden = array(
- 'T_ENDDECLARE', 'T_ENDFOR', 'T_ENDFOREACH',
- 'T_ENDIF', 'T_ENDSWITCH', 'T_ENDWHILE',
- 'T_PRINT', 'T_GOTO', 'T_EVAL',
- 'T_GLOBAL', 'T_VAR', 'T_AT'
+ 'T_ENDDECLARE' => 'enddeclare',
+ 'T_ENDFOR' => 'endfor',
+ 'T_ENDFOREACH' => 'endforeach',
+ 'T_ENDIF' => 'endif',
+ 'T_ENDSWITCH' => 'endswitch',
+ 'T_ENDWHILE' => 'endwhile',
+ 'T_PRINT' => 'print',
+ 'T_GOTO' => 'goto',
+ 'T_EVAL' => 'eval',
+ 'T_GLOBAL' => 'global',
+ 'T_VAR' => 'var'
);
public function apply($testable) {
$tokens = $testable->tokens();
foreach($tokens as $token) {
- if(in_array($token['name'], $this->_forbidden)) {
- $tokenName = strtolower(substr($token['name'], 2));
+ if(isset($_forbidden[$token['name']])) {
+ $tokenName = $this->_forbidden[$token['name']];
$this->addViolation(array(
'message' => 'Forbidden "' . $tokenName . '" statement found',
'line' => $token['line']

2 comments on commit d4a21a1

Michael Nitschinger
Collaborator

This shoves off 10 secs on the lithium core, isset() is so much faster than in_array...

Michael Nitschinger
Collaborator

On my notebook I'm now at 47 seconds wall clock time for the core.

Please sign in to comment.
Something went wrong with that request. Please try again.