Skip to content

Commit b26c00e

Browse files
committed
wip
1 parent 83ad8c7 commit b26c00e

File tree

13 files changed

+78
-21
lines changed

13 files changed

+78
-21
lines changed

phpstan.neon

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,39 @@ parameters:
8484
- # template compiled with precise types, is_string always true
8585
identifier: function.alreadyNarrowedType
8686
path: src/Bridges/DITracy/dist/panel.phtml
87+
- # constructor entity param deliberately broad (native array, no value type)
88+
identifier: missingType.iterableValue
89+
path: src/DI/Definitions/Statement.php
90+
- # promoted property stores broad array, getEntity() declares precise tuple
91+
identifier: return.type
92+
path: src/DI/Definitions/Statement.php
93+
- # exhaustive type check after precise getEntity() return type
94+
identifier: elseif.alwaysTrue
95+
path: src/DI/Config/Adapters/NeonAdapter.php
96+
- # array_values after unset not recognized as list
97+
identifier: assign.propertyType
98+
path: src/DI/Config/Adapters/NeonAdapter.php
99+
- # getByType template type unresolvable in closure
100+
identifier: argument.templateType
101+
path: src/DI/Container.php
102+
- # normalizeClass: ReflectionClass->name is string not class-string
103+
identifier: return.type
104+
path: src/DI/Helpers.php
105+
- # normalizeEntity: reference tracking defeats type narrowing
106+
identifier: return.type
107+
path: src/DI/Resolver.php
108+
- # string as class-string for ReflectionClass in canBeLazy
109+
identifier: argument.type
110+
path: src/DI/Definitions/ServiceDefinition.php
111+
- # string as class-string for ReflectionClass in calculateHash
112+
identifier: argument.type
113+
path: src/DI/DependencyChecker.php
114+
- # exportMeta complex return shape with optional keys
115+
identifier: return.type
116+
path: src/DI/ContainerBuilder.php
117+
- # addDefinition template type unresolvable
118+
identifier: argument.templateType
119+
path: src/DI/Extensions/ServicesExtension.php
87120

88121
includes:
89122
- phpstan-baseline.neon

src/DI/CompilerExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function loadFromFile(string $file): array
113113
/**
114114
* Loads list of service definitions from configuration.
115115
* Prefixes its names and replaces @extension with name in definition.
116-
* @param array<string, mixed> $configList
116+
* @param array<int|string, mixed> $configList
117117
*/
118118
public function loadDefinitionsFromConfig(array $configList): void
119119
{

src/DI/Config/Adapters/NeonAdapter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public function load(string $file): array
4444
$node = $traverser->traverse($node, $this->convertAtSignVisitor(...));
4545
$node = $traverser->traverse($node, $this->deprecatedParametersVisitor(...));
4646
$node = $traverser->traverse($node, $this->resolveConstantsVisitor(...));
47-
return $this->process((array) $node->toValue());
47+
/** @var array<string, mixed> $result */
48+
$result = $this->process((array) $node->toValue());
49+
return $result;
4850
}
4951

5052

src/DI/Container.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ public function callInjects(object $service): void
359359

360360
/**
361361
* Calls the method and passes dependencies to it via autowiring.
362+
* @param callable(mixed...): mixed $function
362363
* @param array<mixed> $args
363364
*/
364365
public function callMethod(callable $function, array $args = []): mixed
@@ -369,7 +370,7 @@ public function callMethod(callable $function, array $args = []): mixed
369370

370371
/**
371372
* @param array<int|string, mixed> $args
372-
* @return list<mixed>
373+
* @return array<int|string, mixed>
373374
*/
374375
private function autowireArguments(\ReflectionFunctionAbstract $function, array $args = []): array
375376
{

src/DI/ContainerLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function getClassName(mixed $key): string
4242
}
4343

4444

45+
/** @param (\Closure(Compiler): ?string) $generator */
4546
private function loadFile(string $class, \Closure $generator): void
4647
{
4748
$file = "$this->tempDirectory/$class.php";

src/DI/Definitions/AccessorDefinition.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ public function complete(Nette\DI\Resolver $resolver): void
102102
$method = new \ReflectionMethod($type, self::MethodGet);
103103
$returnType = Type::fromReflection($method);
104104
assert($returnType !== null);
105-
$this->setReference($returnType->getSingleName());
105+
$name = $returnType->getSingleName();
106+
assert($name !== null);
107+
$this->setReference($name);
106108
}
107109

110+
assert($this->reference !== null);
108111
$this->reference = $resolver->normalizeReference($this->reference);
109112
}
110113

src/DI/Definitions/Definition.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract class Definition
2727
/** @var bool|class-string[] */
2828
private bool|array $autowired = true;
2929

30-
/** @var ?(Closure(): void) */
30+
/** @var (\Closure(): void)|null */
3131
private ?\Closure $notifier = null;
3232

3333

@@ -162,7 +162,7 @@ abstract public function complete(Nette\DI\Resolver $resolver): void;
162162
abstract public function generateMethod(Nette\PhpGenerator\Method $method, Nette\DI\PhpGenerator $generator): void;
163163

164164

165-
/** @param ?(Closure(): void) $notifier */
165+
/** @param (\Closure(): void)|null $notifier */
166166
final public function setNotifier(?\Closure $notifier): void
167167
{
168168
$this->notifier = $notifier;
@@ -174,6 +174,7 @@ final public function setNotifier(?\Closure $notifier): void
174174

175175
/**
176176
* @deprecated Use setType()
177+
* @param class-string|null $type
177178
* @return static
178179
*/
179180
public function setClass(?string $type)

src/DI/Definitions/ServiceDefinition.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function setType(?string $type): static
4545

4646
/**
4747
* Alias for setCreator()
48+
* @param string|array{string|Reference|Statement, string}|Definition|Reference|Statement $factory
4849
* @param array<int|string, mixed> $args
4950
*/
5051
public function setFactory(string|array|Definition|Reference|Statement $factory, array $args = []): static
@@ -62,7 +63,10 @@ public function getFactory(): Statement
6263
}
6364

6465

65-
/** @param array<int|string, mixed> $args */
66+
/**
67+
* @param string|array{string|Reference|Statement, string}|Definition|Reference|Statement $creator
68+
* @param array<int|string, mixed> $args
69+
*/
6670
public function setCreator(string|array|Definition|Reference|Statement $creator, array $args = []): static
6771
{
6872
$this->creator = $creator instanceof Statement
@@ -124,7 +128,10 @@ public function getSetup(): array
124128
}
125129

126130

127-
/** @param array<int|string, mixed> $args */
131+
/**
132+
* @param string|array{string|Reference|Statement, string}|Definition|Reference|Statement $entity
133+
* @param array<int|string, mixed> $args
134+
*/
128135
public function addSetup(string|array|Definition|Reference|Statement $entity, array $args = []): static
129136
{
130137
$entity = $entity instanceof Statement
@@ -151,6 +158,7 @@ public function resolveType(Nette\DI\Resolver $resolver): void
151158
throw new ServiceCreationException('Unknown service type, specify it or declare return type of factory method.');
152159
}
153160

161+
/** @var class-string $type */
154162
$this->setType($type);
155163
$resolver->addDependency(new \ReflectionClass($type));
156164
}
@@ -196,6 +204,7 @@ public function generateMethod(Nette\PhpGenerator\Method $method, Nette\DI\PhpGe
196204
if ($this->canBeLazy() && !preg_grep('#(?:func_get_arg|func_num_args)#i', $lines)) { // latteFactory workaround
197205
$class = $this->creator->getEntity();
198206
assert(is_string($class));
207+
/** @var class-string $class */
199208
$lines[0] = (new \ReflectionClass($class))->hasMethod('__construct')
200209
? $generator->formatPhp("\$service->__construct(...?:);\n", [$this->creator->arguments])
201210
: '';

src/DI/Definitions/Statement.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ final class Statement implements Nette\Schema\DynamicParameter
2424
public array $arguments;
2525

2626

27+
/** @param array<int|string, mixed> $arguments */
2728
public function __construct(
2829
private string|array|Definition|Reference|null $entity,
2930
array $arguments = [],
@@ -59,6 +60,7 @@ public function __construct(
5960
}
6061

6162

63+
/** @return string|array{string|Reference|Statement, string}|Definition|Reference|null */
6264
public function getEntity(): string|array|Definition|Reference|null
6365
{
6466
return $this->entity;

src/DI/Extensions/DefinitionSchema.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ public function completeDefault(Context $context): mixed
112112
}
113113

114114

115-
/** @param string|int $key */
115+
/**
116+
* @param string|int $key
117+
* @param array<string, mixed> $def
118+
*/
116119
private function sniffType($key, array $def): string
117120
{
118121
if (is_string($key)) {

0 commit comments

Comments
 (0)