• 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

90.48
/src/Forms/Component/FormControlGetValueTypeResolver.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\MethodCall;
8
use PhpParser\Node\Identifier;
9
use PHPStan\Analyser\Scope;
10
use PHPStan\Type\ExpressionTypeResolverExtension;
11
use PHPStan\Type\Type;
12
use function spl_object_id;
13

14
/**
15
 * $form['field']->getValue() resolves to the same value type as the matching
16
 * member of $form->getValues() — both are `$control->getValue()` at runtime.
17
 *
18
 * Implemented as an ExpressionTypeResolverExtension (not a
19
 * DynamicMethodReturnTypeExtension) on purpose: getValue() is declared
20
 * `@return mixed` on Nette\Forms\Controls\BaseControl, and for controls that do
21
 * not override it (e.g. Checkbox) PHPStan unions a dynamic-extension result with
22
 * that native mixed, widening it back to mixed. An ExpressionTypeResolverExtension
23
 * runs first and short-circuits, so the precise type wins for every control.
24
 */
25
final class FormControlGetValueTypeResolver implements ExpressionTypeResolverExtension
26
{
27

28
        private ConfigurationGuard $guard;
29

30
        private bool $enabled;
31

32
        private ContainerModel $model;
33

34
        /** @var array<string, true> */
35
        private array $resolving = [];
36

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

46
        public function getType(Expr $expr, Scope $scope): ?Type
47
        {
48
                if (!$this->enabled || !$expr instanceof MethodCall) {
168 ✔
49
                        return null;
168 ✔
50
                }
51

52
                return $this->model->trackDependencies($scope, fn (): ?Type => $this->getTypeUntracked($expr, $scope));
160 ✔
53
        }
54

55
        private function getTypeUntracked(Expr $expr, Scope $scope): ?Type
56
        {
57
                if (!$this->enabled) {
160 ✔
58
                        return null;
×
59
                }
60

61
                if (
62
                        !$expr instanceof MethodCall
160 ✔
63
                        || !$expr->name instanceof Identifier
160 ✔
64
                        || $expr->name->toString() !== 'getValue'
160 ✔
65
                        || $expr->isFirstClassCallable()
160 ✔
66
                        || $expr->getArgs() !== []
160 ✔
67
                ) {
68
                        return null;
160 ✔
69
                }
70

71
                $this->guard->validate();
2 ✔
72

73
                $guardKey = $scope->getFile() . '|' . spl_object_id($expr);
2 ✔
74
                if (isset($this->resolving[$guardKey])) {
2 ✔
75
                        return null;
×
76
                }
77

78
                $this->resolving[$guardKey] = true;
2 ✔
79
                try {
80
                        return $this->model->resolveControlValueType($expr->var, $scope);
2 ✔
81
                } finally {
82
                        unset($this->resolving[$guardKey]);
2 ✔
83
                }
84
        }
85

86
}
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