Skip to content

Commit c51560c

Browse files
committed
Upgraded codebase with php 7.4 constructs
- added strict types directive - added typehints to properties - added method parameters typehints - added return types - minor refactorings
1 parent 87abc42 commit c51560c

Some content is hidden

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

43 files changed

+201
-205
lines changed

cs-fixer.php.dist

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of Polymorphine/Dev package.
5+
*
6+
* (c) Shudd3r <q3.shudder@gmail.com>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
211

312
use Polymorphine\Dev\FixerFactory;
413

src/Fixer/AlignedArrayValuesFixer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Dev package.
@@ -21,15 +21,15 @@ final class AlignedArrayValuesFixer implements FixerInterface
2121
{
2222
use FixerMethods;
2323

24-
private $groups = [];
25-
private $group = [];
24+
private array $groups = [];
25+
private array $group = [];
2626

27-
public function getName()
27+
public function getName(): string
2828
{
2929
return 'Polymorphine/aligned_array_values';
3030
}
3131

32-
public function isCandidate(Tokens $tokens)
32+
public function isCandidate(Tokens $tokens): bool
3333
{
3434
return $tokens->isTokenKindFound(T_DOUBLE_ARROW);
3535
}
@@ -49,7 +49,7 @@ public function getPriority(): int
4949
return -40;
5050
}
5151

52-
public function fix(SplFileInfo $file, Tokens $tokens)
52+
public function fix(SplFileInfo $file, Tokens $tokens): void
5353
{
5454
$this->tokens = $tokens;
5555

src/Fixer/AlignedAssignmentsFixer.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Dev package.
@@ -22,15 +22,12 @@ final class AlignedAssignmentsFixer implements FixerInterface
2222

2323
private const TYPES = [T_VARIABLE, T_CONST, T_PUBLIC, T_PROTECTED, T_PRIVATE];
2424

25-
/** @var Tokens */
26-
private $tokens;
27-
28-
public function getName()
25+
public function getName(): string
2926
{
3027
return 'Polymorphine/aligned_assignments';
3128
}
3229

33-
public function isCandidate(Tokens $tokens)
30+
public function isCandidate(Tokens $tokens): bool
3431
{
3532
return $tokens->isTokenKindFound('=');
3633
}
@@ -50,7 +47,7 @@ public function getPriority(): int
5047
return -40;
5148
}
5249

53-
public function fix(SplFileInfo $file, Tokens $tokens)
50+
public function fix(SplFileInfo $file, Tokens $tokens): void
5451
{
5552
$this->tokens = $tokens;
5653

@@ -72,7 +69,7 @@ public function fix(SplFileInfo $file, Tokens $tokens)
7269
}
7370
}
7471

75-
private function findSiblings($newLine, $assign)
72+
private function findSiblings(int $newLine, int $assign): ?array
7673
{
7774
$siblings = [];
7875
$signature = $this->getTokenSignature($newLine, $assign);
@@ -89,7 +86,7 @@ private function findSiblings($newLine, $assign)
8986
return $siblings;
9087
}
9188

92-
private function findNextSibling($idx, $signature)
89+
private function findNextSibling(int $idx, array $signature): ?array
9390
{
9491
$newLine = $this->nextLineBreak($idx);
9592
if (!$newLine || !$this->isNextLine($newLine)) { return null; }
@@ -104,7 +101,7 @@ private function findNextSibling($idx, $signature)
104101
return [$assign, $this->indentationPointLength($newLine, $assign)];
105102
}
106103

107-
private function getTokenSignature($idx, $assign)
104+
private function getTokenSignature(int $idx, int $assign): array
108105
{
109106
$signature = [];
110107
while (++$idx <= $assign) {
@@ -113,7 +110,7 @@ private function getTokenSignature($idx, $assign)
113110
return $signature;
114111
}
115112

116-
private function isPureAssignment($newLine, $assign)
113+
private function isPureAssignment(int $newLine, int $assign): bool
117114
{
118115
$endLine = $this->nextLineBreak($assign);
119116
if ($this->tokens[$endLine - 1]->getContent() !== ';') {
@@ -127,10 +124,10 @@ private function isPureAssignment($newLine, $assign)
127124
if ($this->tokens[$idx]->getContent() === '(') { return false; }
128125
}
129126

130-
return $assign;
127+
return true;
131128
}
132129

133-
private function validAssignType($newLine)
130+
private function validAssignType(int $newLine): bool
134131
{
135132
$token = $this->tokens[$newLine + 1];
136133

@@ -141,7 +138,7 @@ private function validAssignType($newLine)
141138
return $token->isGivenKind(self::TYPES);
142139
}
143140

144-
private function isStaticAssign($newLine)
141+
private function isStaticAssign(int $newLine): bool
145142
{
146143
$operator = $this->tokens[$newLine + 2]->isGivenKind(T_PAAMAYIM_NEKUDOTAYIM);
147144
return $operator && $this->tokens[$newLine + 3]->isGivenKind(T_VARIABLE);

src/Fixer/AlignedMethodChainFixer.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Dev package.
@@ -21,15 +21,12 @@ final class AlignedMethodChainFixer implements FixerInterface
2121
{
2222
use FixerMethods;
2323

24-
/** @var Tokens */
25-
private $tokens;
26-
27-
public function getName()
24+
public function getName(): string
2825
{
2926
return 'Polymorphine/aligned_method_chain';
3027
}
3128

32-
public function isCandidate(Tokens $tokens)
29+
public function isCandidate(Tokens $tokens): bool
3330
{
3431
if (!$arrows = $tokens->findGivenKind(T_OBJECT_OPERATOR)) {
3532
return false;
@@ -68,10 +65,10 @@ public function fix(SplFileInfo $file, Tokens $tokens)
6865
}
6966
}
7067

71-
private function findNextChain($search)
68+
private function findNextChain(int $search): ?int
7269
{
7370
$idx = $this->tokens->getNextTokenOfKind($search, [[T_OBJECT_OPERATOR]]);
74-
if (!$idx) { return false; }
71+
if (!$idx) { return null; }
7572

7673
if ($this->tokens[$idx - 1]->isWhitespace() || !$this->isStartOfMultilineChain($idx)) {
7774
return $this->findNextChain($idx);
@@ -80,7 +77,7 @@ private function findNextChain($search)
8077
return $idx;
8178
}
8279

83-
private function isStartOfMultilineChain($idx)
80+
private function isStartOfMultilineChain(int $idx): bool
8481
{
8582
$next = ($this->tokens[$idx + 2]->getContent() === '(') ? $this->findClosing($idx + 2) + 1 : $idx + 2;
8683
if ($this->tokens[$next]->isWhitespace() && $this->tokens[$next + 1]->isGivenKind(T_OBJECT_OPERATOR)) {
@@ -90,14 +87,14 @@ private function isStartOfMultilineChain($idx)
9087
return $this->tokens[$next]->isGivenKind(T_OBJECT_OPERATOR) ? $this->isStartOfMultilineChain($next) : false;
9188
}
9289

93-
private function indentationLength($idx): int
90+
private function indentationLength(int $idx): int
9491
{
9592
$lineBreak = $this->prevLineBreak($idx);
9693
$code = $this->tokens->generatePartialCode($lineBreak, $idx - 1);
9794
return $this->codeLength($code);
9895
}
9996

100-
private function alignChain($idx, $indent): void
97+
private function alignChain(int $idx, int $indent): void
10198
{
10299
$next = $this->nextIndentation($idx + 2, $indent);
103100
if (!$next) { return; }
@@ -117,7 +114,7 @@ private function alignChain($idx, $indent): void
117114
if ($idx) { $this->alignChain($idx, $indent); }
118115
}
119116

120-
private function nextIndentation($idx, $indent)
117+
private function nextIndentation(int $idx, int $indent): ?int
121118
{
122119
if ($this->tokens[$idx]->getContent() !== '(') {
123120
return $this->tokens[$idx]->isWhitespace() ? $idx : null;
@@ -133,7 +130,7 @@ private function nextIndentation($idx, $indent)
133130
return $next;
134131
}
135132

136-
private function findClosing($idx)
133+
private function findClosing(int $idx): ?int
137134
{
138135
$parenthesis = $this->tokens->getNextTokenOfKind($idx, ['(', ')']);
139136

@@ -145,7 +142,7 @@ private function findClosing($idx)
145142
return $parenthesis;
146143
}
147144

148-
private function indentMultilineParam($idx, $end, $indent)
145+
private function indentMultilineParam(int $idx, int $end, int $indent): void
149146
{
150147
$minLevel = $this->codeLength($this->tokens[$idx]->getContent());
151148

src/Fixer/AlignedTypedPropertiesFixer.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Dev package.
@@ -20,32 +20,32 @@ final class AlignedTypedPropertiesFixer implements FixerInterface
2020
{
2121
use FixerMethods;
2222

23-
public function getName()
23+
public function getName(): string
2424
{
2525
return 'Polymorphine/aligned_properties';
2626
}
2727

28-
public function isRisky()
28+
public function isRisky(): bool
2929
{
3030
return false;
3131
}
3232

33-
public function getPriority()
33+
public function getPriority(): int
3434
{
3535
return -39;
3636
}
3737

38-
public function supports(SplFileInfo $file)
38+
public function supports(SplFileInfo $file): bool
3939
{
4040
return true;
4141
}
4242

43-
public function isCandidate(Tokens $tokens)
43+
public function isCandidate(Tokens $tokens): bool
4444
{
4545
return $tokens->isAnyTokenKindsFound([T_CLASS, T_TRAIT]);
4646
}
4747

48-
public function fix(SplFileInfo $file, Tokens $tokens)
48+
public function fix(SplFileInfo $file, Tokens $tokens): void
4949
{
5050
$this->tokens = $tokens;
5151

@@ -56,7 +56,7 @@ public function fix(SplFileInfo $file, Tokens $tokens)
5656
}
5757
}
5858

59-
private function findGroups($idx): array
59+
private function findGroups(int $idx): array
6060
{
6161
$groups = [];
6262
$group = [];

src/Fixer/ArrayContext.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Dev package.
@@ -19,9 +19,7 @@ final class ArrayContext
1919
{
2020
use FixerMethods;
2121

22-
private $tokens;
23-
private $start;
24-
private $end;
22+
private int $start;
2523

2624
/**
2725
* @param Tokens $tokens
@@ -75,7 +73,7 @@ private function isMultilineValue(int $lineEnd): bool
7573
return !$isComma && !$this->tokens[$lineEnd + 1]->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE);
7674
}
7775

78-
private function isMultipleAssign(int $firstArrow, int $lineEnd): int
76+
private function isMultipleAssign(int $firstArrow, int $lineEnd): bool
7977
{
8078
$last = $this->tokens->getPrevTokenOfKind($lineEnd, [[T_DOUBLE_ARROW], [CT::T_ARRAY_SQUARE_BRACE_CLOSE]]);
8179
if ($this->tokens[$last]->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE)) {

src/Fixer/BraceAfterFunctionFixer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Dev package.
@@ -19,12 +19,12 @@
1919

2020
final class BraceAfterFunctionFixer implements FixerInterface
2121
{
22-
public function getName()
22+
public function getName(): string
2323
{
2424
return 'Polymorphine/brace_after_method';
2525
}
2626

27-
public function isCandidate(Tokens $tokens)
27+
public function isCandidate(Tokens $tokens): bool
2828
{
2929
return $tokens->isTokenKindFound(T_FUNCTION);
3030
}
@@ -44,7 +44,7 @@ public function getPriority(): int
4444
return -40;
4545
}
4646

47-
public function fix(SplFileInfo $file, Tokens $tokens)
47+
public function fix(SplFileInfo $file, Tokens $tokens): void
4848
{
4949
foreach ($tokens as $index => $token) {
5050
if (!$token->isGivenKind(T_FUNCTION)) { continue; }

src/Fixer/BraceAfterMultilineParamMethodFixer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Dev package.
@@ -26,12 +26,12 @@ class BraceAfterMultilineParamMethodFixer implements FixerInterface
2626
{
2727
use FixerMethods;
2828

29-
public function getName()
29+
public function getName(): string
3030
{
3131
return 'Polymorphine/brace_after_multiline_param_method';
3232
}
3333

34-
public function isCandidate(Tokens $tokens)
34+
public function isCandidate(Tokens $tokens): bool
3535
{
3636
$classConstruct = $tokens->isAnyTokenKindsFound([T_CLASS, T_TRAIT]);
3737
return $classConstruct && $tokens->isTokenKindFound(T_FUNCTION);
@@ -52,7 +52,7 @@ public function getPriority(): int
5252
return -40;
5353
}
5454

55-
public function fix(SplFileInfo $file, Tokens $tokens)
55+
public function fix(SplFileInfo $file, Tokens $tokens): void
5656
{
5757
$this->tokens = $tokens;
5858

0 commit comments

Comments
 (0)