• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

orisai / phpstan-nette / 43698240932

15 Nov 2026 05:30AM UTC coverage: 78.278% (-0.9%) from 79.16%
43698240932

push

github

mabar
Record the measured cost of the reflection cache bypass

21744 of 27778 relevant lines covered (78.28%)

84.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/src/Forms/Component/HandlerParamFormTypeResolver.php
1
<?php declare(strict_types = 1);
2

3
namespace OriPhpstan\Nette\Forms\Component;
4

5
use OriPhpstan\Nette\Configuration\ConfigurationGuard;
6
use PhpParser\Node\Expr;
7
use PhpParser\Node\Expr\Variable;
8
use PHPStan\Analyser\Scope;
9
use PHPStan\Type\ExpressionTypeResolverExtension;
10
use PHPStan\Type\ObjectType;
11
use PHPStan\Type\Type;
12
use function is_string;
13

14
/**
15
 * Types a bare handler-param form variable ($form inside an onSuccess/onClick handler) as the class
16
 * the form is actually registered with, rather than the declared base Nette\…\Form the signature
17
 * spells. The registered class is the constructed class proven scope-free at the registration site;
18
 * narrowing the variable to it makes the offset walk that reflects the builder's add* returns reflect
19
 * them on the constructed class, so every nested container/submit/replicator label — at the handler
20
 * vantage AND the same-file class-component reads the shared summaries would otherwise coarsen —
21
 * resolves to its concrete class. Only ever narrows to a strict subtype of the declared type
22
 * (ContainerModel::paramClassForVariable enforces it), so the type is never widened or made unrelated.
23
 */
24
final class HandlerParamFormTypeResolver implements ExpressionTypeResolverExtension
25
{
26

27
        private ConfigurationGuard $guard;
28

29
        private bool $enabled;
30

31
        private ContainerModel $model;
32

33
        public function __construct(ConfigurationGuard $guard, bool $enabled, ContainerModel $model)
34
        {
35
                // PHPStan builds type extensions with the container, before the reflection provider knows the
36
                // analysed paths (and in the stub validator's container too), so validate on first use.
37
                $this->guard = $guard;
25 ✔
38
                $this->enabled = $enabled;
25 ✔
39
                $this->model = $model;
25 ✔
40
        }
41

42
        public function getType(Expr $expr, Scope $scope): ?Type
43
        {
44
                if (!$this->enabled || !$expr instanceof Variable) {
168 ✔
45
                        return null;
168 ✔
46
                }
47

48
                return $this->model->trackDependencies($scope, fn (): ?Type => $this->getTypeUntracked($expr, $scope));
159 ✔
49
        }
50

51
        private function getTypeUntracked(Expr $expr, Scope $scope): ?Type
52
        {
53
                if (!$this->enabled) {
159 ✔
54
                        return null;
×
55
                }
56

57
                if (!$expr instanceof Variable || !is_string($expr->name) || $expr->name === 'this') {
159 ✔
58
                        return null;
60 ✔
59
                }
60

61
                $this->guard->validate();
156 ✔
62

63
                $class = $this->model->paramClassForVariable($expr, $scope);
156 ✔
64

65
                return $class === null ? null : new ObjectType($class);
156 ✔
66
        }
67

68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc