Passed
Pull Request — master (#391)
by Kirill
05:23
created

RoadRunnerBootloader   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 56
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A boot() 0 51 1
1
<?php
2
3
/**
4
 * This file is part of Spiral Framework package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Bootloader\Server;
13
14
use Spiral\Boot\Bootloader\Bootloader;
15
use Spiral\Boot\EnvironmentInterface as GlobalEnvironmentInterface;
16
use Spiral\Core\Container;
17
use Spiral\Goridge\RPC\RPC;
0 ignored issues
show
Bug introduced by
The type Spiral\Goridge\RPC\RPC 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...
18
use Spiral\Goridge\RPC\RPCInterface;
0 ignored issues
show
Bug introduced by
The type Spiral\Goridge\RPC\RPCInterface 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...
19
use Spiral\Http\Diactoros\ServerRequestFactory;
20
use Spiral\Http\Diactoros\StreamFactory;
21
use Spiral\Http\Diactoros\UploadedFileFactory;
22
use Spiral\RoadRunner\Environment;
0 ignored issues
show
Bug introduced by
The type Spiral\RoadRunner\Environment 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...
23
use Spiral\RoadRunner\EnvironmentInterface;
0 ignored issues
show
Bug introduced by
The type Spiral\RoadRunner\EnvironmentInterface 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
use Spiral\RoadRunner\Http\PSR7Worker;
0 ignored issues
show
Bug introduced by
The type Spiral\RoadRunner\Http\PSR7Worker 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...
25
use Spiral\RoadRunner\Http\PSR7WorkerInterface;
0 ignored issues
show
Bug introduced by
The type Spiral\RoadRunner\Http\PSR7WorkerInterface 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...
26
use Spiral\RoadRunner\Worker;
27
use Spiral\RoadRunner\WorkerInterface;
0 ignored issues
show
Bug introduced by
The type Spiral\RoadRunner\WorkerInterface 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...
28
29
class RoadRunnerBootloader extends Bootloader
30
{
31
    /**
32
     * @param Container $container
33
     */
34
    public function boot(Container $container)
35
    {
36
        //
37
        // Register RoadRunner Environment
38
        //
39
        $registrar = static function (GlobalEnvironmentInterface $env): EnvironmentInterface {
40
            return new Environment($env->getAll());
41
        };
42
43
        $container->bindSingleton(EnvironmentInterface::class, $registrar);
44
        $container->bindSingleton(Environment::class, $registrar);
45
46
        //
47
        // Register RPC
48
        //
49
        $registrar = static function (EnvironmentInterface $env): RPCInterface {
50
            return RPC::create($env->getRPCAddress());
51
        };
52
53
        $container->bindSingleton(RPCInterface::class, $registrar);
54
        $container->bindSingleton(RPC::class, $registrar);
55
56
        //
57
        // Register Worker
58
        //
59
        $registrar = static function (EnvironmentInterface $env): WorkerInterface {
60
            return Worker::createFromEnvironment($env);
0 ignored issues
show
Bug introduced by
The method createFromEnvironment() does not exist on Spiral\RoadRunner\Worker. ( Ignorable by Annotation )

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

60
            return Worker::/** @scrutinizer ignore-call */ createFromEnvironment($env);

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...
61
        };
62
63
        $container->bindSingleton(WorkerInterface::class, $registrar);
64
        $container->bindSingleton(Worker::class, $registrar);
65
66
        //
67
        // Register PSR Worker
68
        //
69
        $registrar = static function (
70
            WorkerInterface $worker,
71
            ServerRequestFactory $requests,
72
            StreamFactory $streams,
73
            UploadedFileFactory $uploads
74
        ): PSR7WorkerInterface {
75
            return new PSR7Worker(
76
                $worker,
77
                $requests,
78
                $streams,
79
                $uploads
80
            );
81
        };
82
83
        $container->bindSingleton(PSR7WorkerInterface::class, $registrar);
84
        $container->bindSingleton(PSR7Worker::class, $registrar);
85
    }
86
}
87