Skip to content

Commit 5beed9b

Browse files
committed
Common update
- Change PHP requirement - Add PHPDoc blocks - Add type-hints - Other minor fixes - Make constructors final
1 parent 8a36063 commit 5beed9b

Some content is hidden

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

47 files changed

+530
-213
lines changed

composer.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"minimum-stability": "stable",
1313
"require": {
14-
"php": "^7.4",
14+
"php": ">=7.4",
1515
"ext-json": "*"
1616
},
1717
"autoload": {
@@ -20,11 +20,13 @@
2020
}
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": "^9.1"
23+
"phpunit/phpunit": "^9.4.3",
24+
"phpstan/phpstan": "^0.12.58"
2425
},
2526
"scripts": {
2627
"test": "bin/phpunit --color=always -v --debug",
27-
"install-cs": "test -f php-cs-fixer.phar || wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.16.3/php-cs-fixer.phar -O php-cs-fixer.phar",
28+
"install-cs": "test -f php-cs-fixer.phar || wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.17.3/php-cs-fixer.phar -O php-cs-fixer.phar",
29+
"static-analysis": "vendor/bin/phpstan analyse src tests",
2830
"fix-cs": [
2931
"@install-cs",
3032
"@php php-cs-fixer.phar fix --diff -v --allow-risky=yes --ansi"

phpstan.neon

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
parameters:
2+
level: 8
3+
reportUnmatchedIgnoredErrors: false
4+
checkMissingIterableValueType: false
5+
checkGenericClassInNonGenericObjectType: false
6+
paths:
7+
- %currentWorkingDirectory%/src
8+
- %currentWorkingDirectory%/tests

src/AbstractFunction.php

+39-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public function getReturnType(): string
1313
return $this->signature->getReturnType();
1414
}
1515

16+
/**
17+
* @return $this
18+
*/
1619
public function setReturnType(string $returnType): self
1720
{
1821
$this->signature->setReturnType($returnType);
@@ -25,61 +28,90 @@ public function getArgument(int $index = 1): ?Argument
2528
return $this->signature->getArgument($index);
2629
}
2730

31+
/**
32+
* @return $this
33+
*/
2834
public function removeArgument(int $index): self
2935
{
3036
$this->signature->removeArgument($index);
3137

3238
return $this;
3339
}
3440

41+
/**
42+
* @return $this
43+
*/
3544
public function removeArguments(): self
3645
{
3746
$this->signature->removeArguments();
3847

3948
return $this;
4049
}
4150

51+
/**
52+
* @param mixed $defaultValue
53+
*/
4254
public function createArgument(string $name, string $type = '', $defaultValue = Argument::NO_PARAM): Argument
4355
{
4456
return $this->signature->createArgument($name, $type, $defaultValue);
4557
}
4658

59+
/**
60+
* @param mixed $defaultValue
61+
*
62+
* @return $this
63+
*/
4764
public function addArgument(string $name, string $type = '', $defaultValue = Argument::NO_PARAM): self
4865
{
4966
$this->signature->addArgument($name, $type, $defaultValue);
5067

5168
return $this;
5269
}
5370

71+
/**
72+
* @return $this
73+
*/
5474
public function addArguments(string ...$names): self
5575
{
5676
$this->signature->addArguments(...$names);
5777

5878
return $this;
5979
}
6080

81+
/**
82+
* @return $this
83+
*/
6184
public function add(FunctionMemberInterface $member): self
6285
{
6386
$this->signature->add($member);
6487

6588
return $this;
6689
}
6790

91+
/**
92+
* @return $this
93+
*/
6894
public function bindVar(string $name, bool $isByReference = false): self
6995
{
7096
$this->signature->bindVar($name, $isByReference);
7197

7298
return $this;
7399
}
74100

101+
/**
102+
* @return $this
103+
*/
75104
public function bindVars(string ...$names): self
76105
{
77106
$this->signature->bindVars(...$names);
78107

79108
return $this;
80109
}
81110

82-
public function removeBindVars()
111+
/**
112+
* @return $this
113+
*/
114+
public function removeBindVars(): self
83115
{
84116
$this->signature->removeBindVars();
85117

@@ -91,13 +123,19 @@ public function isStatic(): bool
91123
return $this->signature->isStatic;
92124
}
93125

126+
/**
127+
* @return $this
128+
*/
94129
public function setStatic(): self
95130
{
96131
$this->signature->isStatic = true;
97132

98133
return $this;
99134
}
100135

136+
/**
137+
* @return $this
138+
*/
101139
public function unsetStatic()
102140
{
103141
$this->signature->isStatic = false;

src/Argument.php

+43-7
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class Argument extends DependencyAwareGenerator implements FunctionMemberInterfa
1111
*/
1212
public const NO_PARAM = INF;
1313

14-
private string $type;
15-
private string $name;
16-
private bool $isSpread = false;
17-
private bool $isByReference = false;
18-
private bool $isNullable = false;
14+
private string $type;
15+
private string $name;
16+
private bool $isSpread = false;
17+
private bool $isByReference = false;
18+
private bool $isNullable = false;
1919

2020
/**
2121
* @var mixed
@@ -26,8 +26,10 @@ class Argument extends DependencyAwareGenerator implements FunctionMemberInterfa
2626
* Argument constructor.
2727
*
2828
* @param mixed $defaultValue
29+
*
30+
* @throws Exception\UnrecognizedValueTypeException
2931
*/
30-
public function __construct(string $name, string $type = '', $defaultValue = self::NO_PARAM)
32+
public final function __construct(string $name, string $type = '', $defaultValue = self::NO_PARAM)
3133
{
3234
$this->name = $name;
3335
$this->type = $this->resolveQualifier($type);
@@ -37,9 +39,15 @@ public function __construct(string $name, string $type = '', $defaultValue = sel
3739
}
3840
}
3941

42+
/**
43+
* @param mixed $defaultValue
44+
*
45+
* @return static
46+
* @throws Exception\UnrecognizedValueTypeException
47+
*/
4048
public static function new(string $name, string $type = '', $defaultValue = self::NO_PARAM): self
4149
{
42-
return new self($name, $type, $defaultValue);
50+
return new static($name, $type, $defaultValue);
4351
}
4452

4553
public function generate(): string
@@ -80,13 +88,19 @@ public function isSpread(): bool
8088
return $this->isSpread;
8189
}
8290

91+
/**
92+
* @return $this
93+
*/
8394
public function setSpread(): self
8495
{
8596
$this->isSpread = true;
8697

8798
return $this;
8899
}
89100

101+
/**
102+
* @return $this
103+
*/
90104
public function unsetSpread(): self
91105
{
92106
$this->isSpread = false;
@@ -99,27 +113,43 @@ public function isByReference(): bool
99113
return $this->isByReference;
100114
}
101115

116+
/**
117+
* @return $this
118+
*/
102119
public function setByReference(): self
103120
{
104121
$this->isByReference = true;
105122

106123
return $this;
107124
}
108125

126+
/**
127+
* @return $this
128+
*/
109129
public function unsetByReference(): self
110130
{
111131
$this->isByReference = false;
112132

113133
return $this;
114134
}
115135

136+
/**
137+
* @return $this
138+
*/
116139
public function setType(string $type): self
117140
{
118141
$this->type = $type;
119142

120143
return $this;
121144
}
122145

146+
/**
147+
* @param mixed $value
148+
*
149+
* @return $this
150+
*
151+
* @throws Exception\UnrecognizedValueTypeException
152+
*/
123153
public function setDefaultValue($value): self
124154
{
125155
if (INF !== $value) {
@@ -131,13 +161,19 @@ public function setDefaultValue($value): self
131161
return $this;
132162
}
133163

164+
/**
165+
* @return $this
166+
*/
134167
public function unsetNullable(): self
135168
{
136169
$this->isNullable = false;
137170

138171
return $this;
139172
}
140173

174+
/**
175+
* @return $this
176+
*/
141177
public function setNullable(): self
142178
{
143179
$this->isNullable = true;

src/ArrowFunction.php

+18-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,25 @@ class ArrowFunction extends AbstractFunction
99
/** @var GeneratorInterface|string */
1010
private $expression;
1111

12-
public function __construct($expression = null, string $returnType = '')
12+
/**
13+
* @param mixed $expression
14+
*/
15+
public final function __construct($expression = null, string $returnType = '')
1316
{
1417
$this->signature = new Signature('', Modifier::NONE, $returnType, 'fn');
1518
$this->expression = $this->manageExprDependency($expression);
1619

1720
$this->dependencyAwareChildren[] = $this->signature;
1821
}
1922

20-
public static function new($expression = null, string $returnType = '')
23+
/**
24+
* @param mixed $expression
25+
*
26+
* @return static
27+
*/
28+
public static function new($expression = null, string $returnType = ''): ArrowFunction
2129
{
22-
return new self($expression, $returnType);
30+
return new static($expression, $returnType);
2331
}
2432

2533
public function generate(): string
@@ -39,6 +47,8 @@ public function getExpression()
3947

4048
/**
4149
* @param mixed $expression
50+
*
51+
* @return $this
4252
*/
4353
public function setExpression($expression): self
4454
{
@@ -47,6 +57,11 @@ public function setExpression($expression): self
4757
return $this;
4858
}
4959

60+
/**
61+
* @param mixed $value
62+
*
63+
* @return mixed
64+
*/
5065
protected function manageExprDependency($value)
5166
{
5267
if ($value instanceof DependencyAwareGenerator) {

src/Block.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class Block extends AbstractGenerator implements BlockInterface
88
{
99
use ScopedContentTrait;
1010

11+
public final function __construct()
12+
{
13+
}
14+
1115
public function generate(): string
1216
{
1317
return <<<CODE
@@ -17,7 +21,10 @@ public function generate(): string
1721
CODE;
1822
}
1923

20-
public static function new()
24+
/**
25+
* @return static
26+
*/
27+
public static function new(): self
2128
{
2229
return new static();
2330
}

src/Closure.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ class Closure extends AbstractFunction
88
{
99
use ScopedContentTrait;
1010

11-
public function __construct(string $returnType = '')
11+
public final function __construct(string $returnType = '')
1212
{
1313
$this->signature = new Signature('', Modifier::NONE, $returnType);
1414
$this->dependencyAwareChildren = [$this->signature];
1515
}
1616

17-
public static function new(string $returnType = '')
17+
/**
18+
* @return static
19+
*/
20+
public static function new(string $returnType = ''): self
1821
{
19-
return new self($returnType);
22+
return new static($returnType);
2023
}
2124

2225
public function generate(): string

0 commit comments

Comments
 (0)