Skip to content

Commit

Permalink
DX: remove 'create' method in internal classes
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Apr 18, 2021
1 parent c990a13 commit 3cc28f8
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/Console/ConfigurationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion src/Tokenizer/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
19 changes: 5 additions & 14 deletions tests/FixerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ public function testInterfaceIsFluent()
static::assertSame($factory, $testInstance);
}

/**
* @covers \PhpCsFixer\FixerFactory::create
*/
public function testCreate()
{
$factory = FixerFactory::create();

static::assertInstanceOf(\PhpCsFixer\FixerFactory::class, $factory);
}

/**
* @covers \PhpCsFixer\FixerFactory::registerBuiltInFixers
*/
Expand Down Expand Up @@ -137,13 +127,13 @@ public function testRegisterFixerWithOccupiedName()
*/
public function testUseRuleSet()
{
$factory = FixerFactory::create()
$factory = (new FixerFactory())
->registerBuiltInFixers()
->useRuleSet(new RuleSet([]))
;
static::assertCount(0, $factory->getFixers());

$factory = FixerFactory::create()
$factory = (new FixerFactory())
->registerBuiltInFixers()
->useRuleSet(new RuleSet(['strict_comparison' => true, 'blank_line_before_statement' => false]))
;
Expand All @@ -160,7 +150,7 @@ public function testUseRuleSetWithNonExistingRule()
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Rule "non_existing_rule" does not exist.');

$factory = FixerFactory::create()
$factory = (new FixerFactory())
->registerBuiltInFixers()
->useRuleSet(new RuleSet(['non_existing_rule' => true]))
;
Expand Down Expand Up @@ -210,7 +200,8 @@ public function testConflictingFixers(RuleSet $ruleSet)
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessageMatches('#^Rule contains conflicting fixers:\n#');

FixerFactory::create()->registerBuiltInFixers()->useRuleSet($ruleSet);
(new FixerFactory())
->registerBuiltInFixers()->useRuleSet($ruleSet);
}

public function provideConflictingFixersCases()
Expand Down
7 changes: 0 additions & 7 deletions tests/Report/ReporterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@
*/
final class ReporterFactoryTest extends TestCase
{
public function testCreate()
{
$factory = ReporterFactory::create();

static::assertInstanceOf(\PhpCsFixer\Report\ReporterFactory::class, $factory);
}

public function testInterfaceIsFluent()
{
$builder = new ReporterFactory();
Expand Down
2 changes: 1 addition & 1 deletion tests/RuleSet/RuleSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function testResolveRulesWithDisabledSet()
public function testRiskyRulesInSet(array $set, $safe)
{
try {
$fixers = FixerFactory::create()
$fixers = (new FixerFactory())
->registerBuiltInFixers()
->useRuleSet(new RuleSet($set))
->getFixers()
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/AbstractIntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ private static function createFixers(IntegrationCase $case)
{
$config = $case->getConfig();

return FixerFactory::create()
return (new FixerFactory())
->registerBuiltInFixers()
->useRuleSet($case->getRuleset())
->setWhitespacesConfig(
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/TokensWithObservedTransformers.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function applyTransformers()
{
$this->observedModificationsPerTransformer = [];

$transformers = Transformers::create();
$transformers = Transformers::createSingleton();
foreach (AccessibleObject::create($transformers)->items as $transformer) {
$this->currentTransformer = $transformer->getName();
$this->observedModificationsPerTransformer[$this->currentTransformer] = [];
Expand Down
2 changes: 1 addition & 1 deletion tests/TextDiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function provideDiffReportingCases()
*/
public function testAllFormatsCovered()
{
$factory = ReporterFactory::create();
$factory = new ReporterFactory();
$formats = $factory->registerBuiltInReporters()->getFormats();
sort($formats);

Expand Down

0 comments on commit 3cc28f8

Please sign in to comment.