Skip to content

Commit

Permalink
Changes for PHP7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
nilportugues committed Nov 10, 2015
1 parent d04958c commit d9bfb42
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 45 deletions.
5 changes: 0 additions & 5 deletions .idea/encodings.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/misc.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/modules.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/myapp.iml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/vcs.xml

This file was deleted.

35 changes: 25 additions & 10 deletions src/BackslashFixer/Fixer/FileEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@

class FileEditor
{
const BACKSLASH_TOKEN = 388;
const FUNCTION_TOKEN = 310;

/**
* @var array
*/
private static $constants = [];
/**
* @var \Zend\Code\Generator\FileGenerator
*/
private $fileGenerator;
/**
* @var FunctionRepository
*/
private $functions;
/**
* @var Interfaces\FileSystem
*/
private $fileSystem;

/**
Expand Down Expand Up @@ -61,26 +67,33 @@ public function addBackslashes($path)
$token = [0 => 0, 1 => $tempToken, 2 => 0];
}

if ($token[0] == self::FUNCTION_TOKEN) {
if ($token[0] == T_STRING) {
$reservedToken = $token[1];

//isFunction
if (!empty($functions[$reservedToken])
&& $previousToken[0] != self::BACKSLASH_TOKEN
&& $previousToken[0] != T_LIST
&& $previousToken[0] != T_NAMESPACE
&& $previousToken[0] != T_OBJECT_OPERATOR
) {
$line = $token[2];
$source[$line-1] = str_replace($reservedToken, '\\'.$reservedToken, $source[$line-1]);
}

//isConstant
if (!empty($constants[strtoupper($reservedToken)])
&& $previousToken[0] != self::BACKSLASH_TOKEN
if (!empty($constants[strtoupper($token[1])])
&& $previousToken[0] != T_NAMESPACE
&& !in_array(strtolower($token[1]), ['true', 'false', 'null'])
) {
$line = $token[2];
$source[$line-1] = str_replace($reservedToken, '\\'.$reservedToken, $source[$line-1]);
$source[$line-1] = str_replace($token[1], '\\'.$token[1], $source[$line-1]);
}
}

if (in_array(strtolower($token[1]), ['true', 'false', 'null'])) {
$line = $token[2];
$source[$line-1] = str_replace($token[1], '\\'.$token[1], $source[$line-1]);
}

$previousToken = $token;
}

Expand Down Expand Up @@ -129,7 +142,9 @@ private function getDefinedConstants()

$c = array_values(self::$constants);

return array_combine($c, $c);
self::$constants = array_combine($c, $c);

return self::$constants;
}

/**
Expand Down

0 comments on commit d9bfb42

Please sign in to comment.