Skip to content

Commit

Permalink
minor #5637 DX: do not calculate bitmap via helper anymore (keradus)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.18 branch.

Discussion
----------

DX: do not calculate bitmap via helper anymore

Commits
-------

2e54b06 DX: do not calculate bitmap via helper anymore
  • Loading branch information
keradus committed Apr 18, 2021
2 parents 0acd4d5 + 2e54b06 commit e89da2d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 23 deletions.
13 changes: 1 addition & 12 deletions src/Tokenizer/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
9 changes: 1 addition & 8 deletions src/Tokenizer/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace PhpCsFixer\Tokenizer;

use PhpCsFixer\Preg;
use PhpCsFixer\Utils;

/**
* Collection of code tokens.
Expand Down Expand Up @@ -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) {
Expand All @@ -1151,7 +1144,7 @@ public function toJson()
$this->rewind();
}

return json_encode($output, $options);
return json_encode($output, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions tests/Smoke/InstallViaComposerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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__.'/../..';
Expand Down

0 comments on commit e89da2d

Please sign in to comment.