Skip to content

Commit

Permalink
Merge branch '2.18'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Tokenizer/Token.php
  • Loading branch information
keradus committed Apr 18, 2021
2 parents d29da4a + e89da2d commit 283e731
Show file tree
Hide file tree
Showing 28 changed files with 49 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/Console/ConfigurationResolver.php
Expand Up @@ -478,7 +478,7 @@ public function getProgress()
public function getReporter()
{
if (null === $this->reporter) {
$reporterFactory = ReporterFactory::create();
$reporterFactory = new ReporterFactory();
$reporterFactory->registerBuiltInReporters();

$format = $this->getFormat();
Expand Down
13 changes: 5 additions & 8 deletions src/FileReader.php
Expand Up @@ -23,11 +23,6 @@
*/
final class FileReader
{
/**
* @var null|self
*/
private static $instance;

/**
* @var null|string
*/
Expand All @@ -38,11 +33,13 @@ final class FileReader
*/
public static function createSingleton()
{
if (null === self::$instance) {
self::$instance = new self();
static $instance = null;

if (!$instance) {
$instance = new self();
}

return self::$instance;
return $instance;
}

/**
Expand Down
10 changes: 0 additions & 10 deletions src/FixerFactory.php
Expand Up @@ -55,16 +55,6 @@ public function __construct()
$this->nameValidator = new FixerNameValidator();
}

/**
* Create instance.
*
* @return FixerFactory
*/
public static function create()
{
return new self();
}

public function setWhitespacesConfig(WhitespacesFixerConfig $config)
{
foreach ($this->fixers as $fixer) {
Expand Down
5 changes: 0 additions & 5 deletions src/Report/ReporterFactory.php
Expand Up @@ -25,11 +25,6 @@ final class ReporterFactory
/** @var ReporterInterface[] */
private $reporters = [];

public static function create()
{
return new self();
}

public function registerBuiltInReporters()
{
/** @var null|string[] $builtInReporters */
Expand Down
3 changes: 2 additions & 1 deletion src/RuleSet/Sets/PHPUnit30MigrationRiskySet.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\RuleSet\Sets;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\RuleSet\AbstractRuleSetDescription;

/**
Expand All @@ -23,7 +24,7 @@ public function getRules()
{
return [
'php_unit_dedicate_assert' => [
'target' => '3.0',
'target' => PhpUnitTargetVersion::VERSION_3_0,
],
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/RuleSet/Sets/PHPUnit32MigrationRiskySet.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\RuleSet\Sets;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\RuleSet\AbstractRuleSetDescription;

/**
Expand All @@ -24,7 +25,7 @@ public function getRules()
return [
'@PHPUnit30Migration:risky' => true,
'php_unit_no_expectation_annotation' => [
'target' => '3.2',
'target' => PhpUnitTargetVersion::VERSION_3_2,
],
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/RuleSet/Sets/PHPUnit35MigrationRiskySet.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\RuleSet\Sets;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\RuleSet\AbstractRuleSetDescription;

/**
Expand All @@ -24,7 +25,7 @@ public function getRules()
return [
'@PHPUnit32Migration:risky' => true,
'php_unit_dedicate_assert' => [
'target' => '3.5',
'target' => PhpUnitTargetVersion::VERSION_3_5,
],
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/RuleSet/Sets/PHPUnit43MigrationRiskySet.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\RuleSet\Sets;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\RuleSet\AbstractRuleSetDescription;

/**
Expand All @@ -24,7 +25,7 @@ public function getRules()
return [
'@PHPUnit35Migration:risky' => true,
'php_unit_no_expectation_annotation' => [
'target' => '4.3',
'target' => PhpUnitTargetVersion::VERSION_4_3,
],
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/RuleSet/Sets/PHPUnit48MigrationRiskySet.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\RuleSet\Sets;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\RuleSet\AbstractRuleSetDescription;

/**
Expand All @@ -24,7 +25,7 @@ public function getRules()
return [
'@PHPUnit43Migration:risky' => true,
'php_unit_namespaced' => [
'target' => '4.8',
'target' => PhpUnitTargetVersion::VERSION_4_8,
],
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/RuleSet/Sets/PHPUnit52MigrationRiskySet.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\RuleSet\Sets;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\RuleSet\AbstractRuleSetDescription;

/**
Expand All @@ -24,7 +25,7 @@ public function getRules()
return [
'@PHPUnit50Migration:risky' => true,
'php_unit_expectation' => [
'target' => '5.2',
'target' => PhpUnitTargetVersion::VERSION_5_2,
],
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/RuleSet/Sets/PHPUnit54MigrationRiskySet.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\RuleSet\Sets;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\RuleSet\AbstractRuleSetDescription;

/**
Expand All @@ -24,7 +25,7 @@ public function getRules()
return [
'@PHPUnit52Migration:risky' => true,
'php_unit_mock' => [
'target' => '5.4',
'target' => PhpUnitTargetVersion::VERSION_5_4,
],
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/RuleSet/Sets/PHPUnit55MigrationRiskySet.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\RuleSet\Sets;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\RuleSet\AbstractRuleSetDescription;

/**
Expand All @@ -24,7 +25,7 @@ public function getRules()
return [
'@PHPUnit54Migration:risky' => true,
'php_unit_mock' => [
'target' => '5.5',
'target' => PhpUnitTargetVersion::VERSION_5_5,
],
];
}
Expand Down
5 changes: 3 additions & 2 deletions src/RuleSet/Sets/PHPUnit56MigrationRiskySet.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\RuleSet\Sets;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\RuleSet\AbstractRuleSetDescription;

/**
Expand All @@ -24,10 +25,10 @@ public function getRules()
return [
'@PHPUnit55Migration:risky' => true,
'php_unit_dedicate_assert' => [
'target' => '5.6',
'target' => PhpUnitTargetVersion::VERSION_5_6,
],
'php_unit_expectation' => [
'target' => '5.6',
'target' => PhpUnitTargetVersion::VERSION_5_6,
],
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/RuleSet/Sets/PHPUnit57MigrationRiskySet.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\RuleSet\Sets;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\RuleSet\AbstractRuleSetDescription;

/**
Expand All @@ -24,7 +25,7 @@ public function getRules()
return [
'@PHPUnit56Migration:risky' => true,
'php_unit_namespaced' => [
'target' => '5.7',
'target' => PhpUnitTargetVersion::VERSION_5_7,
],
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/RuleSet/Sets/PHPUnit60MigrationRiskySet.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\RuleSet\Sets;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\RuleSet\AbstractRuleSetDescription;

/**
Expand All @@ -24,7 +25,7 @@ public function getRules()
return [
'@PHPUnit57Migration:risky' => true,
'php_unit_namespaced' => [
'target' => '6.0',
'target' => PhpUnitTargetVersion::VERSION_6_0,
],
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/RuleSet/Sets/PHPUnit75MigrationRiskySet.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\RuleSet\Sets;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\RuleSet\AbstractRuleSetDescription;

/**
Expand All @@ -24,7 +25,7 @@ public function getRules()
return [
'@PHPUnit60Migration:risky' => true,
'php_unit_dedicate_assert_internal_type' => [
'target' => '7.5',
'target' => PhpUnitTargetVersion::VERSION_7_5,
],
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/RuleSet/Sets/PHPUnit84MigrationRiskySet.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\RuleSet\Sets;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
use PhpCsFixer\RuleSet\AbstractRuleSetDescription;

/**
Expand All @@ -25,7 +26,7 @@ public function getRules()
'@PHPUnit60Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'php_unit_expectation' => [
'target' => '8.4',
'target' => PhpUnitTargetVersion::VERSION_8_4,
],
];
}
Expand Down
13 changes: 1 addition & 12 deletions src/Tokenizer/Token.php
Expand Up @@ -619,18 +619,7 @@ public function toJson(array $options = null)
Utils::triggerDeprecation(sprintf('Arguments of "%s()" is deprecated since 2.19 and will be removed in 3.0.', __METHOD__));
}

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
10 changes: 2 additions & 8 deletions src/Tokenizer/Tokens.php
Expand Up @@ -1135,12 +1135,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 +1145,7 @@ public function toJson()
$this->rewind();
}

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

/**
Expand Down Expand Up @@ -1389,7 +1383,7 @@ public function valid()
*/
protected function applyTransformers()
{
$transformers = Transformers::create();
$transformers = Transformers::createSingleton();
$transformers->transform($this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tokenizer/Transformers.php
Expand Up @@ -47,7 +47,7 @@ private function __construct()
/**
* @return Transformers
*/
public static function create()
public static function createSingleton()
{
static $instance = null;

Expand Down
2 changes: 1 addition & 1 deletion tests/AutoReview/TransformerTest.php
Expand Up @@ -99,7 +99,7 @@ public function provideTransformerCases()
static $transformersArray = null;

if (null === $transformersArray) {
$transformers = Transformers::create();
$transformers = Transformers::createSingleton();
$reflection = new \ReflectionObject($transformers);
$builtInTransformers = $reflection->getMethod('findBuiltInTransformers');
$builtInTransformers->setAccessible(true);
Expand Down

0 comments on commit 283e731

Please sign in to comment.