Passed
Push — master ( 400934...9d586b )
by Anton
02:32
created

EnvironmentCollector::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Debug\StateCollector;
13
14
use Psr\Container\ContainerInterface;
15
use Spiral\Boot\DispatcherInterface;
16
use Spiral\Boot\EnvironmentInterface;
17
use Spiral\Debug\StateCollectorInterface;
18
use Spiral\Debug\StateInterface;
19
use Spiral\GRPC\GRPCDispatcher;
20
use Spiral\Http\RrDispacher;
21
use Spiral\Http\SapiDispatcher;
22
use Spiral\Jobs\JobDispatcher;
23
24
final class EnvironmentCollector implements StateCollectorInterface
25
{
26
    /** @var ContainerInterface */
27
    private $container;
28
29
    /** @var EnvironmentInterface */
30
    private $env;
31
32
    /**
33
     * @param ContainerInterface   $container
34
     * @param EnvironmentInterface $env
35
     */
36
    public function __construct(ContainerInterface $container, EnvironmentInterface $env)
37
    {
38
        $this->container = $container;
39
        $this->env = $env;
40
    }
41
42
    public function populate(StateInterface $state): void
43
    {
44
        $state->setTag('php', phpversion());
45
46
        if ($this->container->get(DispatcherInterface::class)) {
47
            switch (get_class($this->container->get(DispatcherInterface::class))) {
48
                case RrDispacher::class:
49
                    $state->setTag('dispatcher', 'roadrunner');
50
                    break;
51
                case SapiDispatcher::class:
52
                    $state->setTag('dispatcher', 'sapi');
53
                    break;
54
                case JobDispatcher::class:
55
                    $state->setTag('dispatcher', 'jobs');
56
                    break;
57
                case GRPCDispatcher::class:
58
                    $state->setTag('dispatcher', 'grpc');
59
                    break;
60
            }
61
        }
62
63
        $state->setVariable('environment', $this->env->getAll());
0 ignored issues
show
Bug introduced by
The method getAll() does not exist on Spiral\Boot\EnvironmentInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
        $state->setVariable('environment', $this->env->/** @scrutinizer ignore-call */ getAll());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
    }
65
}
66