diff --git a/src/Tokenizer/Token.php b/src/Tokenizer/Token.php index c05742558eb..9eff12479a9 100644 --- a/src/Tokenizer/Token.php +++ b/src/Tokenizer/Token.php @@ -615,18 +615,7 @@ public function toArray() */ public function toJson(array $options = null) { - static $defaultOptions = null; - - if (null === $options) { - if (null === $defaultOptions) { - $defaultOptions = Utils::calculateBitmask(['JSON_PRETTY_PRINT', 'JSON_NUMERIC_CHECK']); - } - - $options = $defaultOptions; - } else { - $options = Utils::calculateBitmask($options); - } - + $options = $options ? Utils::calculateBitmask($options) : (JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK); $jsonResult = json_encode($this->toArray(), $options); if (JSON_ERROR_NONE !== json_last_error()) { diff --git a/src/Tokenizer/Tokens.php b/src/Tokenizer/Tokens.php index 178c3c28e1d..8d718dd2adc 100644 --- a/src/Tokenizer/Tokens.php +++ b/src/Tokenizer/Tokens.php @@ -13,7 +13,6 @@ namespace PhpCsFixer\Tokenizer; use PhpCsFixer\Preg; -use PhpCsFixer\Utils; /** * Collection of code tokens. @@ -1135,12 +1134,6 @@ public function setCode($code) public function toJson() { - static $options = null; - - if (null === $options) { - $options = Utils::calculateBitmask(['JSON_PRETTY_PRINT', 'JSON_NUMERIC_CHECK']); - } - $output = new \SplFixedArray(\count($this)); foreach ($this as $index => $token) { @@ -1151,7 +1144,7 @@ public function toJson() $this->rewind(); } - return json_encode($output, $options); + return json_encode($output, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK); } /** diff --git a/tests/Smoke/InstallViaComposerTest.php b/tests/Smoke/InstallViaComposerTest.php index 8a6abfb59e7..8c3e1bc9ab2 100644 --- a/tests/Smoke/InstallViaComposerTest.php +++ b/tests/Smoke/InstallViaComposerTest.php @@ -14,7 +14,6 @@ use Keradus\CliExecutor\CommandExecutor; use PhpCsFixer\Console\Application; -use PhpCsFixer\Utils; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; @@ -89,7 +88,7 @@ public function testInstallationViaPathIsPossible() file_put_contents( $tmpPath.'/composer.json', - json_encode($initialComposerFileState, Utils::calculateBitmask(['JSON_PRETTY_PRINT'])) + json_encode($initialComposerFileState, JSON_PRETTY_PRINT) ); static::assertCommandsWork($this->stepsToVerifyInstallation, $tmpPath); @@ -131,7 +130,7 @@ public function testInstallationViaArtifactIsPossible() file_put_contents( $tmpPath.'/composer.json', - json_encode($initialComposerFileState, Utils::calculateBitmask(['JSON_PRETTY_PRINT'])) + json_encode($initialComposerFileState, JSON_PRETTY_PRINT) ); $cwd = __DIR__.'/../..';