Skip to content

Commit b640078

Browse files
Fixed phpstan and psalm errors
1 parent 29f263a commit b640078

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

Diff for: phpstan.neon.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ parameters:
99
treatPhpDocTypesAsCertain: false
1010

1111
ignoreErrors:
12-
- "#^Construct empty\\(\\) is not allowed. Use more strict comparison.$#"
12+
- "#^Construct empty\\(\\) is not allowed. Use more strict comparison|Call to an undefined method ReflectionMethod|ReflectionProperty\\:\\:getAttributes\\(\\).$#"
1313
- "#^Property Rade\\\\DI\\\\Loader\\\\FileLoader|ClosureLoader\\:\\:\\$container \\(Rade\\\\DI\\\\Container\\|Rade\\\\DI\\\\ContainerBuilder\\) does not accept Rade\\\\DI\\\\AbstractContainer.$#"
1414
-
1515
message: "#^Parameter \\#2 \\$service \\(Rade\\\\DI\\\\Definition\\|Rade\\\\DI\\\\RawDefinition\\) of method Rade\\\\DI\\\\ContainerBuilder\\:\\:doCreate\\(\\) should be contravariant with parameter \\$service \\(callable\\(\\): mixed\\) of method Rade\\\\DI\\\\AbstractContainer\\:\\:doCreate\\(\\)$#"

Diff for: psalm.xml.dist

+21
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,26 @@
3939
<referencedClass name="Psr\Container\ContainerExceptionInterface"/>
4040
</errorLevel>
4141
</InvalidCatch>
42+
43+
<UndefinedMethod>
44+
<errorLevel type="suppress">
45+
<referencedMethod name="Rade\DI\Services\ServiceProviderInterface::getid"/>
46+
<file name="src/Loader/YamlFileLoader.php"/>
47+
</errorLevel>
48+
</UndefinedMethod>
49+
50+
<PropertyNotSetInConstructor>
51+
<errorLevel type="suppress">
52+
<file name="src/Builder/CodePrinter.php"/>
53+
<file name="src/Definition.php"/>
54+
<referencedProperty name="Rade\DI\Loader\YamlFileLoader::$yamlParser" />
55+
</errorLevel>
56+
</PropertyNotSetInConstructor>
57+
58+
<PossiblyUndefinedStringArrayOffset>
59+
<errorLevel type="suppress">
60+
<file name="src/ContainerBuilder.php"/>
61+
</errorLevel>
62+
</PossiblyUndefinedStringArrayOffset>
4263
</issueHandlers>
4364
</psalm>

Diff for: src/Loader/YamlFileLoader.php

+28-8
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ class YamlFileLoader extends FileLoader
7878
'calls' => 'bind',
7979
];
8080

81-
/** @var YamlParser */
82-
private $yamlParser;
81+
private ?YamlParser $yamlParser = null;
8382

8483
/**
8584
* {@inheritdoc}
@@ -118,13 +117,11 @@ public function supports($resource, string $type = null)
118117
/**
119118
* Loads a YAML file.
120119
*
121-
* @param string $file
122-
*
123120
* @throws \InvalidArgumentException when the given file is not a local file or when it does not exist
124121
*
125-
* @return array The file content
122+
* @return array<int|string,mixed> The file content
126123
*/
127-
protected function loadFile($file)
124+
protected function loadFile(string $file): array
128125
{
129126
if (!\class_exists(\Symfony\Component\Yaml\Parser::class)) {
130127
throw new \RuntimeException('Unable to load YAML config files as the Symfony Yaml Component is not installed.');
@@ -155,6 +152,9 @@ protected function loadFile($file)
155152
return $configuration;
156153
}
157154

155+
/**
156+
* @param array<string,mixed> $content
157+
*/
158158
private function parseImports(array $content, string $file): void
159159
{
160160
if (!isset($content['imports'])) {
@@ -194,7 +194,10 @@ private function parseImports(array $content, string $file): void
194194
unset($content['imports']);
195195
}
196196

197-
private function loadContent($content, $path): void
197+
/**
198+
* @param array<string,mixed> $content
199+
*/
200+
private function loadContent(array $content, string $path): void
198201
{
199202
// imports
200203
$this->parseImports($content, $path);
@@ -223,6 +226,8 @@ private function loadContent($content, $path): void
223226

224227
/**
225228
* Loads Service Providers.
229+
*
230+
* @param array<string,mixed> $content
226231
*/
227232
private function loadServiceProviders(array $content, string $path): void
228233
{
@@ -261,6 +266,8 @@ private function loadServiceProviders(array $content, string $path): void
261266
/**
262267
* Resolves services.
263268
*
269+
* @param TaggedValue|array|string|null $value
270+
*
264271
* @return array|string|Reference|Statement|object|null
265272
*/
266273
private function resolveServices($value, string $file, bool $isParameter = false)
@@ -352,6 +359,9 @@ private function resolveServices($value, string $file, bool $isParameter = false
352359
return $this->resolveParameters($value);
353360
}
354361

362+
/**
363+
* @param array<string,mixed> $content
364+
*/
355365
private function parseDefinitions(array $content, string $file): void
356366
{
357367
if (!isset($content['services'])) {
@@ -460,6 +470,9 @@ private function parseDefaults(array &$content, string $file): array
460470
/**
461471
* Parses a definition.
462472
*
473+
* @param array<string,mixed> $service
474+
* @param array<string,mixed> $defaults
475+
*
463476
* @throws \InvalidArgumentException
464477
*/
465478
private function parseDefinition(string $id, array $service, string $file, array $defaults, Definition $definition = null): void
@@ -561,7 +574,7 @@ private function parseDefinition(string $id, array $service, string $file, array
561574
/**
562575
* @param array<int,string[]> $bindings
563576
*
564-
* @return array<int,string[]>
577+
* @return array<int,mixed>
565578
*/
566579
private function parseDefinitionBinds(string $id, array $bindings, string $file, Definition $definition = null): array
567580
{
@@ -604,6 +617,11 @@ private function parseDefinitionBinds(string $id, array $bindings, string $file,
604617
return $bindings;
605618
}
606619

620+
/**
621+
* @param array<int|string,mixed> $tags
622+
*
623+
* @return mixed[]
624+
*/
607625
private function parseDefinitionTags(string $id, array $tags, string $file): array
608626
{
609627
if ('in "_defaults"' !== $id) {
@@ -637,6 +655,8 @@ private function parseDefinitionTags(string $id, array $tags, string $file): arr
637655

638656
/**
639657
* Checks the keywords used to define a service.
658+
*
659+
* @param array<string,mixed> $definition
640660
*/
641661
private function checkDefinition(string $id, array $definition, string $file): void
642662
{

0 commit comments

Comments
 (0)