Skip to content

Commit b606f94

Browse files
committed
Code: apply phpstan
1 parent 19761c4 commit b606f94

File tree

8 files changed

+63
-126
lines changed

8 files changed

+63
-126
lines changed

phpstan.neon

Lines changed: 23 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
includes:
2-
#- vendor/contributte/phpstan/phpstan.neon
3-
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
4-
- vendor/phpstan/phpstan-nette/extension.neon
5-
- vendor/phpstan/phpstan-nette/rules.neon
6-
#- vendor/phpstan/phpstan-strict-rules/rules.neon
2+
- vendor/contributte/phpstan/phpstan.neon
3+
- extension.neon
74

85
parameters:
96
level: 8
@@ -19,73 +16,25 @@ parameters:
1916
- src
2017
- .docs
2118

22-
ignoreErrors:
23-
-
24-
message: """
25-
#^Call to deprecated method getName\\(\\) of class Contributte\\\\Imagist\\\\Bridge\\\\Doctrine\\\\ImageType\\:
26-
this method will be removed in Doctrine DBAL 4\\.0,
27-
use \\{@see TypeRegistry\\:\\:lookupName\\(\\)\\} instead\\.$#
28-
"""
29-
count: 2
30-
path: src/Bridge/Doctrine/ImageType.php
31-
32-
-
33-
message: "#^Class Contributte\\\\Imagist\\\\Bridge\\\\Nette\\\\DI\\\\GumletImageStorageExtension extends @final class Contributte\\\\Imagist\\\\Bridge\\\\Nette\\\\DI\\\\GumletImagistExtension\\.$#"
34-
count: 1
35-
path: src/Bridge/Nette/DI/GumletImageStorageExtension.php
36-
37-
-
38-
message: "#^Class Contributte\\\\Imagist\\\\Bridge\\\\Nette\\\\DI\\\\ImageStorageConfigFiltersExtension extends @final class Contributte\\\\Imagist\\\\Bridge\\\\Nette\\\\DI\\\\ImagistNeonFiltersExtension\\.$#"
39-
count: 1
40-
path: src/Bridge/Nette/DI/ImageStorageConfigFiltersExtension.php
41-
42-
-
43-
message: "#^Class Contributte\\\\Imagist\\\\Bridge\\\\Nette\\\\DI\\\\ImageStorageExtension extends @final class Contributte\\\\Imagist\\\\Bridge\\\\Nette\\\\DI\\\\ImagistExtension\\.$#"
44-
count: 1
45-
path: src/Bridge/Nette/DI/ImageStorageExtension.php
46-
47-
-
48-
message: "#^Method Contributte\\\\Imagist\\\\Bridge\\\\Symfony\\\\Serializer\\\\ImagistNormalizer\\:\\:normalize\\(\\) return type has no value type specified in iterable type array\\.$#"
49-
count: 1
50-
path: src/Bridge/Symfony/Serializer/ImagistNormalizer.php
51-
52-
-
53-
message: "#^Method Contributte\\\\Imagist\\\\Bridge\\\\Symfony\\\\Serializer\\\\ImagistNormalizer\\:\\:normalize\\(\\) return type with generic class ArrayObject does not specify its types\\: TKey, TValue$#"
54-
count: 1
55-
path: src/Bridge/Symfony/Serializer/ImagistNormalizer.php
56-
57-
-
58-
message: "#^Method Contributte\\\\Imagist\\\\Bridge\\\\Symfony\\\\Serializer\\\\ImagistNormalizer\\:\\:normalize\\(\\) should return array\\|ArrayObject\\|bool\\|float\\|int\\|string\\|null but returns Contributte\\\\Imagist\\\\Entity\\\\PersistentImageInterface\\.$#"
59-
count: 1
60-
path: src/Bridge/Symfony/Serializer/ImagistNormalizer.php
61-
62-
-
63-
message: "#^Method Contributte\\\\Imagist\\\\Bridge\\\\Symfony\\\\Serializer\\\\ImagistNormalizer\\:\\:supportsNormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
64-
count: 1
65-
path: src/Bridge/Symfony/Serializer/ImagistNormalizer.php
66-
67-
-
68-
message: "#^PHPDoc tag @return with type mixed is not subtype of native type array\\|ArrayObject\\|bool\\|float\\|int\\|string\\|null\\.$#"
69-
count: 1
70-
path: src/Bridge/Symfony/Serializer/ImagistNormalizer.php
71-
72-
-
73-
message: "#^Method Contributte\\\\Imagist\\\\Entity\\\\PromisedImage\\:\\:getOriginal\\(\\) should return Contributte\\\\Imagist\\\\Entity\\\\PromisedImage but returns Contributte\\\\Imagist\\\\Entity\\\\PersistentImageInterface\\.$#"
74-
count: 1
75-
path: src/Entity/PromisedImage.php
76-
77-
-
78-
message: "#^Method Contributte\\\\Imagist\\\\Entity\\\\PromisedImage\\:\\:withFilter\\(\\) should return Contributte\\\\Imagist\\\\Entity\\\\PromisedImage but returns Contributte\\\\Imagist\\\\Entity\\\\PersistentImageInterface\\.$#"
79-
count: 1
80-
path: src/Entity/PromisedImage.php
81-
82-
-
83-
message: "#^Method Contributte\\\\Imagist\\\\Entity\\\\PromisedImage\\:\\:withName\\(\\) should return Contributte\\\\Imagist\\\\Entity\\\\PromisedImage but returns Contributte\\\\Imagist\\\\Entity\\\\PersistentImageInterface\\.$#"
84-
count: 1
85-
path: src/Entity/PromisedImage.php
86-
87-
-
88-
message: "#^Method Contributte\\\\Imagist\\\\Entity\\\\PromisedImage\\:\\:withScope\\(\\) should return Contributte\\\\Imagist\\\\Entity\\\\PromisedImage but returns Contributte\\\\Imagist\\\\Entity\\\\PersistentImageInterface\\.$#"
89-
count: 1
90-
path: src/Entity/PromisedImage.php
19+
excludePaths:
20+
- %currentWorkingDirectory%/tests/_*
9121

22+
ignoreErrors:
23+
- '#^Only booleans are allowed in a negated boolean, string\|null given.#'
24+
- '#(.+)should be contravariant(.+)#'
25+
26+
- '#^Property Contributte\\Codeception\\Module\\NetteApplicationModule::\$path is never read, only written.#'
27+
28+
# Should not happen
29+
- '#^Method Contributte\\Codeception\\Module\\NetteDIModule::getContainer\(\) should return Nette\\DI\\Container but returns Nette\\DI\\Container\|null#'
30+
- '#^Method Contributte\\Codeception\\Http\\Request::getFile\(\) should return Nette\\Http\\FileUpload\|null but returns array\|Nette\\Http\\FileUpload\|null.#'
31+
- '#Parameter \#1 \$path of static method Nette\\Utils\\FileSystem::delete\(\) expects string, string\|false given\.#'
32+
- '#Call to an undefined method Nette\\DI\\Definitions\\Definition::setFactory\(\)\.#'
33+
- '#Call to protected method setType\(\) of class Nette\\DI\\Definitions\\Definition\.#'
34+
- '#.+Contributte\\Codeception\\Module\\NetteApplicationModule::\$config.+#'
35+
- '#.+Contributte\\Codeception\\Module\\NetteDIModule::\$config.+#'
36+
- '#.+Contributte\\Codeception\\Module\\NetteDIModule::\$requiredFields.+#'
37+
38+
earlyTerminatingMethodCalls:
39+
Codeception\Module:
40+
- fail

src/Connector/NetteConnector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function setContainerAccessor(callable $containerAccessor): void
2929
* @param Request $request
3030
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
3131
*/
32-
public function doRequest($request): Response
32+
public function doRequest(object $request): Response
3333
{
3434
$phpSelf = $_SERVER['PHP_SELF'];
3535
$_COOKIE = $request->getCookies();
@@ -67,6 +67,7 @@ public function doRequest($request): Response
6767
$content = (string) ob_get_clean();
6868
} catch (Throwable $e) {
6969
ob_end_clean();
70+
7071
throw $e;
7172
}
7273

src/Http/Request.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
class Request implements IRequest
1414
{
1515

16-
/** @var RequestFactory */
17-
private $factory;
16+
private RequestFactory $factory;
1817

19-
/** @var IRequest */
20-
private $request;
18+
private IRequest $request;
2119

2220
public function __construct(RequestFactory $factory)
2321
{
@@ -30,10 +28,7 @@ public function reset(): void
3028
$this->request = $this->factory->fromGlobals();
3129
}
3230

33-
/**
34-
* @return mixed
35-
*/
36-
public function getCookie(string $key)
31+
public function getCookie(string $key): mixed
3732
{
3833
return $this->request->getCookie($key);
3934
}
@@ -77,18 +72,12 @@ public function getMethod(): string
7772
return $this->request->getMethod();
7873
}
7974

80-
/**
81-
* @return mixed
82-
*/
83-
public function getPost(?string $key = null)
75+
public function getPost(?string $key = null): mixed
8476
{
8577
return func_num_args() === 0 ? $this->request->getPost() : $this->request->getPost($key);
8678
}
8779

88-
/**
89-
* @return mixed
90-
*/
91-
public function getQuery(?string $key = null)
80+
public function getQuery(?string $key = null): mixed
9281
{
9382
return func_num_args() === 0 ? $this->request->getQuery() : $this->request->getQuery($key);
9483
}

src/Http/Response.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@ class Response implements IResponse
1414
{
1515

1616
/** @var string The domain in which the cookie will be available */
17-
public $cookieDomain = '';
17+
public string $cookieDomain = '';
1818

1919
/** @var string The path in which the cookie will be available */
20-
public $cookiePath = '/';
20+
public string $cookiePath = '/';
2121

2222
/** @var bool Whether the cookie is available only through HTTPS */
23-
public $cookieSecure = false;
23+
public bool $cookieSecure = false;
2424

25-
/** @var int */
26-
private $code = self::S200_OK;
25+
private int $code = self::S200_OK;
2726

2827
/** @var string[] */
29-
private $headers = [];
28+
private array $headers = [];
3029

3130
public function reset(): void
3231
{
@@ -42,36 +41,40 @@ public function getCode(): int
4241
/**
4342
* @return static
4443
*/
45-
public function setCode(int $code, ?string $reason = null)
44+
public function setCode(int $code, ?string $reason = null): static
4645
{
4746
$this->code = $code;
47+
4848
return $this;
4949
}
5050

5151
/**
5252
* @return static
5353
*/
54-
public function setHeader(string $name, string $value)
54+
public function setHeader(string $name, string $value): static
5555
{
5656
$this->headers[$name] = $value;
57+
5758
return $this;
5859
}
5960

6061
/**
6162
* @return static
6263
*/
63-
public function addHeader(string $name, string $value)
64+
public function addHeader(string $name, string $value): static
6465
{
6566
$this->headers[$name] = $value;
67+
6668
return $this;
6769
}
6870

6971
/**
7072
* @return static
7173
*/
72-
public function setContentType(string $type, ?string $charset = null)
74+
public function setContentType(string $type, ?string $charset = null): static
7375
{
7476
$this->setHeader('Content-Type', $type . ($charset !== null ? '; charset=' . $charset : ''));
77+
7578
return $this;
7679
}
7780

@@ -84,7 +87,7 @@ public function redirect(string $url, int $code = self::S302_Found): void
8487
/**
8588
* @return static
8689
*/
87-
public function setExpiration(?string $time)
90+
public function setExpiration(?string $time): static
8891
{
8992
if (!$time) {
9093
$this->setHeader('Cache-Control', 's-maxage=0, max-age=0, must-revalidate');
@@ -122,13 +125,14 @@ public function getHeaders(): array
122125
* @param string|int|DateTimeInterface $time
123126
* @return static
124127
*/
125-
public function setCookie(string $name, string $value, $time, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null, ?string $sameSite = null)
128+
public function setCookie(string $name, string $value, mixed $time, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null, ?string $sameSite = null): static
126129
{
127130
return $this;
128131
}
129132

130133
public function deleteCookie(string $name, ?string $path = null, ?string $domain = null, ?bool $secure = null): void
131134
{
135+
// No-op
132136
}
133137

134138
}

src/Module/NetteApplicationModule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
class NetteApplicationModule extends Framework
1616
{
1717

18-
/** @var array<string, mixed> */
18+
/** @var array<string, mixed> */
1919
protected array $config = [
2020
'followRedirects' => true,
2121
];
2222

23-
private string $path;
23+
private ?string $path = null;
2424

2525
/**
2626
* @param array{path?: string} $settings
2727
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
2828
*/
29-
public function _beforeSuite($settings = []): void
29+
public function _beforeSuite(mixed $settings = []): void
3030
{
3131
assert(isset($settings['path']));
3232

src/Module/NetteDIModule.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class NetteDIModule extends Module
1717
{
1818

1919
/** @var callable[] function(Container $configurator): void; */
20-
public $onCreateConfigurator = [];
20+
public array $onCreateConfigurator = [];
2121

2222
/** @var callable[] function(Container $container): void; */
23-
public $onCreateContainer = [];
23+
public array $onCreateContainer = [];
2424

2525
/** @var array<string, mixed> */
2626
protected array $config = [
@@ -38,14 +38,12 @@ class NetteDIModule extends Module
3838
'tempDir',
3939
];
4040

41-
/** @var string */
42-
private $path;
41+
private string $path;
4342

4443
/** @var string[] */
45-
private $configFiles = [];
44+
private array $configFiles = [];
4645

47-
/** @var Container|null */
48-
private $container;
46+
private ?Container $container = null;
4947

5048
/**
5149
* @param array{path?: string} $settings
@@ -106,10 +104,9 @@ public function getContainer(): Container
106104
}
107105

108106
/**
109-
* @return object
110107
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint
111108
*/
112-
public function grabService(string $service)
109+
public function grabService(string $service): object
113110
{
114111
try {
115112
/** @phpstan-var class-string $service */
@@ -164,13 +161,11 @@ private function createContainer(): void
164161
}
165162
}
166163

167-
168164
private function getTempDir(): string
169165
{
170166
return $this->path . '/' . $this->config['tempDir'];
171167
}
172168

173-
174169
private function clearTempDir(): void
175170
{
176171
$this->deleteTempDir();
@@ -179,7 +174,6 @@ private function clearTempDir(): void
179174
FileSystem::createDir($tempDir);
180175
}
181176

182-
183177
private function deleteTempDir(): void
184178
{
185179
$tempDir = $this->getTempDir();
@@ -188,7 +182,6 @@ private function deleteTempDir(): void
188182
}
189183
}
190184

191-
192185
private function stopContainer(): void
193186
{
194187
if ($this->container === null) {

src/Qa/PhpStan/NetteDIModuleType.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,29 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
2828
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
2929
{
3030
if ($methodCall->args === []) {
31-
return $methodReflection->getReturnType();
31+
return $methodReflection->getReturnType(); // @phpstan-ignore-line
3232
}
3333

3434
$arg = $methodCall->getArgs()[0]->value;
3535

3636
if (!$arg instanceof ClassConstFetch) {
37-
return $methodReflection->getReturnType();
37+
return $methodReflection->getReturnType(); // @phpstan-ignore-line
3838
}
3939

4040
$class = $arg->class;
4141

4242
if (!$class instanceof Name) {
43-
return $methodReflection->getReturnType();
43+
return $methodReflection->getReturnType(); // @phpstan-ignore-line
4444
}
4545

4646
$class = (string) $class;
4747

4848
if ($class === 'static') {
49-
return $methodReflection->getReturnType();
49+
return $methodReflection->getReturnType(); // @phpstan-ignore-line
5050
}
5151

5252
if ($class === 'self') {
53-
$class = $scope->getClassReflection()->getName();
53+
$class = $scope->getClassReflection()->getName(); // @phpstan-ignore-line
5454
}
5555

5656
return new ObjectType($class);

0 commit comments

Comments
 (0)