Issues (35)

src/Components/Serving.php (3 issues)

Labels
Severity
1
<?php
2
/**
3
 * RPC serving init
4
 * User: moyo
5
 * Date: 18/03/2018
6
 * Time: 3:20 PM
7
 */
8
9
namespace Carno\HRPC\Components;
10
11
use Carno\Console\Component;
12
use Carno\Console\Contracts\Application;
13
use Carno\Console\Contracts\Bootable;
14
use Carno\Container\DI;
15
use Carno\HRPC\Handlers\ExceptionDump;
16
use Carno\HRPC\Handlers\RequestLogger;
17
use Carno\HRPC\Handlers\ServerReplier;
18
use Carno\HRPC\Handlers\ServerUnavailable;
19
use Carno\HRPC\Handlers\ServerWrapper;
20
use Carno\HRPC\Handlers\TrafficMonitor;
21
use Carno\Monitor\Daemon;
0 ignored issues
show
The type Carno\Monitor\Daemon 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...
22
use Carno\RPC\Handlers\ServiceInvoker;
23
use Carno\RPC\Options;
24
use Carno\RPC\Server;
25
use Carno\RPC\Service\Dispatcher;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Carno\HRPC\Components\Dispatcher. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
26
27
class Serving extends Component implements Bootable
28
{
29
    /**
30
     * @var array
31
     */
32
    protected $dependencies = [Dispatcher::class];
33
34
    /**
35
     * @param Application $app
36
     */
37
    public function starting(Application $app) : void
38
    {
39
        // assign global extensions manager of server
40
        Server::layers()->append(
41
            null,
42
            DI::object(ExceptionDump::class),
43
            DI::object(ServerReplier::class),
44
            DI::object(ServerWrapper::class),
45
            DI::object(RequestLogger::class),
46
            DI::object(ServiceInvoker::class, DI::get(Dispatcher::class), $options = new Options())
47
        );
48
49
        // initial mark server "unavailable"
50
        Server::layers()->append(ServerWrapper::class, DI::object(ServerUnavailable::class));
51
52
        $app->starting()->add(static function () use ($app, $options) {
53
            // add traffic monitor layer
54
            DI::has(Daemon::class) && Server::layers()->append(
55
                ServerWrapper::class,
56
                DI::object(TrafficMonitor::class)
57
            );
58
            // configurable options link
59
            $app->conf()->bind($options, ['rpc.serv.opts' => ['tt.exec' => 'ttExec']]);
0 ignored issues
show
The method conf() does not exist on Carno\Console\Contracts\Application. ( Ignorable by Annotation )

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

59
            $app->/** @scrutinizer ignore-call */ 
60
                  conf()->bind($options, ['rpc.serv.opts' => ['tt.exec' => 'ttExec']]);

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...
60
        });
61
62
        $app->starting()->done()->then(static function () {
63
            // mark server "available" when bootstrap done
64
            Server::layers()->remove(ServerUnavailable::class);
65
        });
66
    }
67
}
68