Issues (182)

src/AssistedWebContextParam.php (3 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource;
6
7
use Override;
8
use Ray\Di\InjectorInterface;
9
use Ray\WebContextParam\Annotation\AbstractWebContextParam;
10
11
use function assert;
12
use function is_string;
13
14
/**
15
 * @psalm-import-type Query from Types
16
 * @psalm-import-type SuperGlobalsMap from Types
17
 */
18
final class AssistedWebContextParam implements ParamInterface
19
{
20
    /**
21
     * $GLOBALS for testing
22
     *
23
     * @var SuperGlobalsMap
0 ignored issues
show
The type BEAR\Resource\SuperGlobalsMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
     */
25
    private static array $globals = [];
26
27
    public function __construct(
28
        private readonly AbstractWebContextParam $webContextParam,
29
        private readonly ParamInterface $defaultParam,
30
    ) {
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36
    #[Override]
37
    public function __invoke(string $varName, array $query, InjectorInterface $injector)
38
    {
39
        $superGlobals = static::$globals ?: $GLOBALS;
0 ignored issues
show
Since $globals is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $globals to at least protected.
Loading history...
40
        /** @var SuperGlobalsMap $superGlobals */
41
        $webContextParam = $this->webContextParam;
42
        assert(is_string($webContextParam::GLOBAL_KEY));
43
        /** @psalm-suppress MixedArrayOffset */
44
        $phpWebContext = $superGlobals[$webContextParam::GLOBAL_KEY];
45
46
        return $phpWebContext[$this->webContextParam->key] ?? ($this->defaultParam)($varName, $query, $injector);
47
    }
48
49
    /** @param SuperGlobalsMap $globals */
50
    public static function setSuperGlobalsOnlyForTestingPurpose(array $globals): void
51
    {
52
        self::$globals = $globals;
0 ignored issues
show
Documentation Bug introduced by
It seems like $globals of type array is incompatible with the declared type BEAR\Resource\SuperGlobalsMap of property $globals.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
53
    }
54
}
55