Skip to content

Commit c4557ca

Browse files
committed
Use new for defaults in promoted properties
See phpactor/language-server#64
1 parent cb9a2b7 commit c4557ca

51 files changed

Lines changed: 102 additions & 241 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/ClassMover/Adapter/TolerantParser/TolerantClassFinder.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@
3030

3131
class TolerantClassFinder implements ClassFinder
3232
{
33-
private Parser $parser;
34-
35-
public function __construct(?Parser $parser = null)
33+
public function __construct(private Parser $parser = new Parser())
3634
{
37-
$this->parser = $parser ?: new Parser();
3835
}
3936

4037
public function findIn(TextDocument $source): NamespacedClassReferences

lib/ClassMover/Adapter/WorseTolerant/WorseTolerantMemberFinder.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,12 @@ class WorseTolerantMemberFinder implements MemberFinder
4545
{
4646
private Reflector $reflector;
4747

48-
private Parser $parser;
49-
50-
private LoggerInterface $logger;
51-
5248
public function __construct(
5349
?Reflector $reflector = null,
54-
?Parser $parser = null,
55-
?LoggerInterface $logger = null
50+
private Parser $parser = new Parser(),
51+
private LoggerInterface $logger = new NullLogger()
5652
) {
5753
$this->reflector = $reflector ?: ReflectorBuilder::create()->addSource(TextDocumentBuilder::empty());
58-
$this->parser = $parser ?: new Parser();
59-
$this->logger = $logger ?: new NullLogger();
6054
}
6155

6256
public function findMembers(SourceCode $source, ClassMemberQuery $query): MemberReferences

lib/ClassMover/ClassMover.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,10 @@
1414

1515
class ClassMover
1616
{
17-
private ClassFinder $finder;
18-
19-
private ClassReplacer $replacer;
20-
21-
public function __construct(?ClassFinder $finder = null, ?ClassReplacer $replacer = null)
22-
{
23-
$this->finder = $finder ?: new TolerantClassFinder();
24-
$this->replacer = $replacer ?: new TolerantClassReplacer(new TolerantUpdater(new TwigRenderer()));
17+
public function __construct(
18+
private ClassFinder $finder = new TolerantClassFinder(),
19+
private ClassReplacer $replacer = new TolerantClassReplacer(new TolerantUpdater(new TwigRenderer())),
20+
) {
2521
}
2622

2723
public function findReferences(string $source, string $fullyQualifiedName): FoundReferences

lib/ClassMover/Tests/Adapter/TolerantParser/TolerantClassFinderTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Phpactor\ClassMover\Tests\Adapter\TolerantParser;
44

55
use PHPUnit\Framework\Attributes\TestDox;
6-
use Microsoft\PhpParser\Parser;
76
use Phpactor\ClassMover\Adapter\TolerantParser\TolerantClassFinder;
87
use PHPUnit\Framework\TestCase;
98
use Phpactor\TextDocument\TextDocumentBuilder;
@@ -13,8 +12,7 @@ class TolerantClassFinderTest extends TestCase
1312
#[TestDox('It finds all class references.')]
1413
public function testFind(): void
1514
{
16-
$parser = new Parser();
17-
$tolerantRefFinder = new TolerantClassFinder($parser);
15+
$tolerantRefFinder = new TolerantClassFinder();
1816
$source = TextDocumentBuilder::fromUri(__DIR__ . '/examples/Example1.php')->build();
1917
$names = iterator_to_array($tolerantRefFinder->findIn($source));
2018

lib/ClassMover/Tests/Adapter/TolerantParser/TolerantClassReplacerTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PHPUnit\Framework\Attributes\DataProvider;
66
use PHPUnit\Framework\Attributes\TestDox;
77
use Generator;
8-
use Microsoft\PhpParser\Parser;
98
use Phpactor\ClassMover\Adapter\TolerantParser\TolerantClassFinder;
109
use PHPUnit\Framework\TestCase;
1110
use Phpactor\ClassMover\Adapter\TolerantParser\TolerantClassReplacer;
@@ -20,8 +19,7 @@ class TolerantClassReplacerTest extends TestCase
2019
#[TestDox('It finds all class references.')]
2120
public function testFind(string $fileName, string $classFqn, string $replaceWithFqn, string $expectedSource): void
2221
{
23-
$parser = new Parser();
24-
$tolerantRefFinder = new TolerantClassFinder($parser);
22+
$tolerantRefFinder = new TolerantClassFinder();
2523
$source = TextDocumentBuilder::fromUri(__DIR__ . '/examples/' . $fileName)->build();
2624
$originalName = FullyQualifiedName::fromString($classFqn);
2725

lib/CodeBuilder/Adapter/TolerantParser/Edits.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ class Edits
1616
*/
1717
private array $edits = [];
1818

19-
private TextFormat $format;
20-
21-
public function __construct(?TextFormat $format = null)
19+
public function __construct(private TextFormat $format = new TextFormat())
2220
{
23-
$this->format = $format ?: new TextFormat();
2421
}
2522

2623
/**

lib/CodeBuilder/Adapter/TolerantParser/TolerantUpdater.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525

2626
class TolerantUpdater implements Updater
2727
{
28-
private Parser $parser;
29-
30-
private TextFormat $textFormat;
31-
3228
private ClassUpdater $classUpdater;
3329

3430
private InterfaceUpdater $interfaceUpdater;
@@ -41,11 +37,9 @@ class TolerantUpdater implements Updater
4137

4238
public function __construct(
4339
private Renderer $renderer,
44-
?TextFormat $textFormat = null,
45-
?Parser $parser = null
40+
private TextFormat $textFormat = new TextFormat(),
41+
private Parser $parser = new Parser()
4642
) {
47-
$this->parser = $parser ?: new Parser();
48-
$this->textFormat = $textFormat ?: new TextFormat();
4943
$this->classUpdater = new ClassUpdater($renderer);
5044
$this->interfaceUpdater = new InterfaceUpdater($renderer);
5145
$this->traitUpdater = new TraitUpdater($renderer);

lib/CodeBuilder/Adapter/Twig/TwigRenderer.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ final class TwigRenderer implements Renderer
1515
{
1616
private Environment $twig;
1717

18-
private TemplateNameResolver $templateNameResolver;
19-
2018
public function __construct(
2119
?Environment $twig = null,
22-
?TemplateNameResolver $templateNameResolver = null
20+
private TemplateNameResolver $templateNameResolver = new ClassShortNameResolver(),
2321
) {
2422
$this->twig = $twig ?: $this->createTwig();
25-
$this->templateNameResolver = $templateNameResolver ?: new ClassShortNameResolver();
2623
}
2724

2825
public function render(Prototype $prototype, ?string $variant = null): Code

lib/CodeTransform/Adapter/TolerantParser/ClassToFile/Transformer/ClassNameFixerTransformer.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,8 @@
3131

3232
class ClassNameFixerTransformer implements Transformer
3333
{
34-
private Parser $parser;
35-
36-
public function __construct(
37-
private FileToClass $fileToClass,
38-
?Parser $parser = null
39-
) {
40-
$this->parser = $parser ?: new Parser();
34+
public function __construct(private FileToClass $fileToClass, private Parser $parser = new Parser())
35+
{
4136
}
4237

4338
/**

lib/CodeTransform/Adapter/TolerantParser/Refactor/TolerantChangeVisiblity.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616

1717
class TolerantChangeVisiblity implements ChangeVisiblity
1818
{
19-
private Parser $parser;
20-
21-
public function __construct(?Parser $parser = null)
19+
public function __construct(private Parser $parser = new Parser())
2220
{
23-
$this->parser = $parser ?: new Parser();
2421
}
2522

2623
public function changeVisiblity(SourceCode $source, int $offset): SourceCode

0 commit comments

Comments
 (0)