Skip to content
This repository was archived by the owner on Mar 6, 2022. It is now read-only.

Commit b477d7c

Browse files
authored
Update coding standard (#32)
1 parent 464e7f9 commit b477d7c

File tree

64 files changed

+1545
-1678
lines changed

Some content is hidden

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

64 files changed

+1545
-1678
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343

4444
-
4545
name: "Run friendsofphp/php-cs-fixer"
46-
run: "vendor/bin/php-cs-fixer fix --dry-run --diff --verbose"
46+
run: "vendor/bin/php-cs-fixer fix --dry-run --diff --verbose --allow-risky=yes"
4747
phpstan:
4848
name: "PHPStan (${{ matrix.php-version }})"
4949

.php_cs.dist

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
$finder = PhpCsFixer\Finder::create()
44
->in('lib')
5+
->in('tests')
56
->exclude([
6-
'tests/Workspace'
7+
'tests/Workspace',
78
])
89
;
910

@@ -12,6 +13,11 @@ return PhpCsFixer\Config::create()
1213
'@PSR2' => true,
1314
'no_unused_imports' => true,
1415
'array_syntax' => ['syntax' => 'short'],
16+
'void_return' => true,
17+
'ordered_class_elements' => true,
18+
'single_quote' => true,
19+
'heredoc_indentation' => true,
20+
'global_namespace_import' => true,
1521
])
1622
->setFinder($finder)
1723
;

lib/Adapter/TolerantParser/Edits.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ public function __construct(TextFormat $format = null)
2424
;
2525
}
2626

27-
public function remove($node)
27+
public function remove($node): void
2828
{
2929
$this->edits[] = TextEdit::create($node->getFullStart(), $node->getFullWidth(), '');
3030
}
3131

32-
public function before($node, string $text)
32+
public function before($node, string $text): void
3333
{
3434
$this->edits[] = TextEdit::create($node->getStart(), 0, $text);
3535
}
3636

37-
public function after($node, string $text)
37+
public function after($node, string $text): void
3838
{
3939
$this->edits[] = TextEdit::create($node->getEndPosition(), 0, $text);
4040
}
4141

42-
public function replace($node, string $text)
42+
public function replace($node, string $text): void
4343
{
4444
$this->edits[] = TextEdit::create($node->getFullStart(), $node->getFullWidth(), $text);
4545
}
@@ -49,7 +49,7 @@ public function textEdits(): TextEdits
4949
return TextEdits::fromTextEdits($this->edits);
5050
}
5151

52-
public function add(TextEdit $textEdit)
52+
public function add(TextEdit $textEdit): void
5353
{
5454
$this->edits[] = $textEdit;
5555
}

lib/Adapter/TolerantParser/TolerantUpdater.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function textEditsFor(Prototype $prototype, Code $code): TextEdits
8888
return $edits->textEdits();
8989
}
9090

91-
private function updateNamespace(Edits $edits, SourceCode $prototype, SourceFileNode $node)
91+
private function updateNamespace(Edits $edits, SourceCode $prototype, SourceFileNode $node): void
9292
{
9393
$namespaceNode = $node->getFirstChildNode(NamespaceDefinition::class);
9494

@@ -114,7 +114,7 @@ private function updateNamespace(Edits $edits, SourceCode $prototype, SourceFile
114114
$edits->after($startTag, 'namespace ' . (string) $prototype->namespace() . ';' . PHP_EOL.PHP_EOL);
115115
}
116116

117-
private function updateClasses(Edits $edits, SourceCode $prototype, SourceFileNode $node)
117+
private function updateClasses(Edits $edits, SourceCode $prototype, SourceFileNode $node): void
118118
{
119119
$classNodes = [];
120120
$traitNodes = [];

lib/Adapter/TolerantParser/Updater/AbstractMethodUpdater.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(Renderer $renderer)
3030
$this->renderer = $renderer;
3131
}
3232

33-
public function updateMethods(Edits $edits, ClassLikePrototype $classPrototype, ClassLike $classNode)
33+
public function updateMethods(Edits $edits, ClassLikePrototype $classPrototype, ClassLike $classNode): void
3434
{
3535
if (count($classPrototype->methods()) === 0) {
3636
return;
@@ -104,7 +104,13 @@ public function updateMethods(Edits $edits, ClassLikePrototype $classPrototype,
104104
}
105105
}
106106

107-
private function appendLinesToMethod(Edits $edits, Method $method, Node $bodyNode)
107+
abstract protected function memberDeclarations(ClassLike $classNode);
108+
109+
abstract protected function memberDeclarationsNode(ClassLike $classNode);
110+
111+
abstract protected function renderMethod(Renderer $renderer, Method $method);
112+
113+
private function appendLinesToMethod(Edits $edits, Method $method, Node $bodyNode): void
108114
{
109115
if (false === $bodyNode instanceof CompoundStatementNode) {
110116
return;
@@ -129,7 +135,7 @@ private function appendLinesToMethod(Edits $edits, Method $method, Node $bodyNod
129135
}
130136
}
131137

132-
private function updateOrAddParameters(Edits $edits, Parameters $parameters, MethodDeclaration $methodDeclaration)
138+
private function updateOrAddParameters(Edits $edits, Parameters $parameters, MethodDeclaration $methodDeclaration): void
133139
{
134140
if (0 === $parameters->count()) {
135141
return;
@@ -162,7 +168,7 @@ private function updateOrAddParameters(Edits $edits, Parameters $parameters, Met
162168
));
163169
}
164170

165-
private function updateOrAddReturnType(Edits $edits, ReturnType $returnType, MethodDeclaration $methodDeclaration)
171+
private function updateOrAddReturnType(Edits $edits, ReturnType $returnType, MethodDeclaration $methodDeclaration): void
166172
{
167173
if (false === $returnType->notNone()) {
168174
return;
@@ -239,10 +245,4 @@ private function prototypeSameAsDeclaration(Method $methodPrototype, MethodDecla
239245

240246
return true;
241247
}
242-
243-
abstract protected function memberDeclarations(ClassLike $classNode);
244-
245-
abstract protected function memberDeclarationsNode(ClassLike $classNode);
246-
247-
abstract protected function renderMethod(Renderer $renderer, Method $method);
248248
}

lib/Adapter/TolerantParser/Updater/ClassLikeUpdater.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Phpactor\CodeBuilder\Domain\Prototype\ClassLikePrototype;
1212
use Phpactor\CodeBuilder\Domain\Prototype\Type;
1313
use Phpactor\CodeBuilder\Domain\Renderer;
14+
use InvalidArgumentException;
1415

1516
abstract class ClassLikeUpdater
1617
{
@@ -40,15 +41,15 @@ protected function resolvePropertyName(Node $property)
4041
return $this->resolvePropertyName($property->leftOperand);
4142
}
4243

43-
throw new \InvalidArgumentException(sprintf(
44+
throw new InvalidArgumentException(sprintf(
4445
'Do not know how to resolve property element of type "%s"',
4546
get_class($property)
4647
));
4748
}
4849

4950
abstract protected function memberDeclarations(Node $node): array;
5051

51-
protected function updateProperties(Edits $edits, ClassLikePrototype $classPrototype, Node $classMembers)
52+
protected function updateProperties(Edits $edits, ClassLikePrototype $classPrototype, Node $classMembers): void
5253
{
5354
if (count($classPrototype->properties()) === 0) {
5455
return;

lib/Adapter/TolerantParser/Updater/ClassMethodUpdater.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88

99
class ClassMethodUpdater extends AbstractMethodUpdater
1010
{
11-
protected function memberDeclarations(ClassLike $classNode)
12-
{
13-
return $classNode->classMembers->classMemberDeclarations;
14-
}
15-
1611
public function memberDeclarationsNode(ClassLike $classNode)
1712
{
1813
return $classNode->classMembers;
@@ -24,4 +19,8 @@ public function renderMethod(Renderer $renderer, Method $method)
2419
PHP_EOL .
2520
$renderer->render($method->body());
2621
}
22+
protected function memberDeclarations(ClassLike $classNode)
23+
{
24+
return $classNode->classMembers->classMemberDeclarations;
25+
}
2726
}

lib/Adapter/TolerantParser/Updater/ClassUpdater.php

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class ClassUpdater extends ClassLikeUpdater
1717
{
18-
public function updateClass(Edits $edits, ClassPrototype $classPrototype, ClassDeclaration $classNode)
18+
public function updateClass(Edits $edits, ClassPrototype $classPrototype, ClassDeclaration $classNode): void
1919
{
2020
if (false === $classPrototype->applyUpdate()) {
2121
return;
@@ -29,49 +29,7 @@ public function updateClass(Edits $edits, ClassPrototype $classPrototype, ClassD
2929
$this->methodUpdater->updateMethods($edits, $classPrototype, $classNode);
3030
}
3131

32-
private function updateExtends(Edits $edits, ClassPrototype $classPrototype, ClassDeclaration $classNode)
33-
{
34-
if (ExtendsClass::none() == $classPrototype->extendsClass()) {
35-
return;
36-
}
37-
38-
if (null === $classNode->classBaseClause) {
39-
$edits->after($classNode->name, ' extends ' . (string) $classPrototype->extendsClass());
40-
return;
41-
}
42-
43-
44-
$edits->replace($classNode->classBaseClause, ' extends ' . (string) $classPrototype->extendsClass());
45-
}
46-
47-
private function updateImplements(Edits $edits, ClassPrototype $classPrototype, ClassDeclaration $classNode)
48-
{
49-
if (ImplementsInterfaces::empty() == $classPrototype->implementsInterfaces()) {
50-
return;
51-
}
52-
53-
if (null === $classNode->classInterfaceClause) {
54-
$edits->after($classNode->name, ' implements ' . (string) $classPrototype->implementsInterfaces()->__toString());
55-
return;
56-
}
57-
58-
$existingNames = [];
59-
foreach ($classNode->classInterfaceClause->interfaceNameList->getElements() as $name) {
60-
$existingNames[] = $name->getText();
61-
}
62-
63-
$additionalNames = $classPrototype->implementsInterfaces()->notIn($existingNames);
64-
65-
if (0 === count($additionalNames)) {
66-
return;
67-
}
68-
69-
$names = join(', ', [ implode(', ', $existingNames), $additionalNames->__toString()]);
70-
71-
$edits->replace($classNode->classInterfaceClause, ' implements ' . $names);
72-
}
73-
74-
protected function updateConstants(Edits $edits, ClassPrototype $classPrototype, Node $classMembers)
32+
protected function updateConstants(Edits $edits, ClassPrototype $classPrototype, Node $classMembers): void
7533
{
7634
if (count($classPrototype->constants()) === 0) {
7735
return;
@@ -123,4 +81,46 @@ protected function memberDeclarations(Node $node): array
12381
{
12482
return $node->classMemberDeclarations;
12583
}
84+
85+
private function updateExtends(Edits $edits, ClassPrototype $classPrototype, ClassDeclaration $classNode): void
86+
{
87+
if (ExtendsClass::none() == $classPrototype->extendsClass()) {
88+
return;
89+
}
90+
91+
if (null === $classNode->classBaseClause) {
92+
$edits->after($classNode->name, ' extends ' . (string) $classPrototype->extendsClass());
93+
return;
94+
}
95+
96+
97+
$edits->replace($classNode->classBaseClause, ' extends ' . (string) $classPrototype->extendsClass());
98+
}
99+
100+
private function updateImplements(Edits $edits, ClassPrototype $classPrototype, ClassDeclaration $classNode): void
101+
{
102+
if (ImplementsInterfaces::empty() == $classPrototype->implementsInterfaces()) {
103+
return;
104+
}
105+
106+
if (null === $classNode->classInterfaceClause) {
107+
$edits->after($classNode->name, ' implements ' . (string) $classPrototype->implementsInterfaces()->__toString());
108+
return;
109+
}
110+
111+
$existingNames = [];
112+
foreach ($classNode->classInterfaceClause->interfaceNameList->getElements() as $name) {
113+
$existingNames[] = $name->getText();
114+
}
115+
116+
$additionalNames = $classPrototype->implementsInterfaces()->notIn($existingNames);
117+
118+
if (0 === count($additionalNames)) {
119+
return;
120+
}
121+
122+
$names = join(', ', [ implode(', ', $existingNames), $additionalNames->__toString()]);
123+
124+
$edits->replace($classNode->classInterfaceClause, ' implements ' . $names);
125+
}
126126
}

lib/Adapter/TolerantParser/Updater/InterfaceMethodUpdater.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88

99
class InterfaceMethodUpdater extends AbstractMethodUpdater
1010
{
11-
protected function memberDeclarations(ClassLike $classNode)
12-
{
13-
return $classNode->interfaceMembers->interfaceMemberDeclarations;
14-
}
15-
1611
public function memberDeclarationsNode(ClassLike $classNode)
1712
{
1813
return $classNode->interfaceMembers;
@@ -22,4 +17,8 @@ public function renderMethod(Renderer $renderer, Method $method)
2217
{
2318
return $renderer->render($method) . ';';
2419
}
20+
protected function memberDeclarations(ClassLike $classNode)
21+
{
22+
return $classNode->interfaceMembers->interfaceMemberDeclarations;
23+
}
2524
}

lib/Adapter/TolerantParser/Updater/InterfaceUpdater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function updateInterface(
2929
Edits $edits,
3030
InterfacePrototype $classPrototype,
3131
InterfaceDeclaration $classNode
32-
) {
32+
): void {
3333
$this->methodUpdater->updateMethods($edits, $classPrototype, $classNode);
3434
}
3535
}

0 commit comments

Comments
 (0)