Passed
Push — master ( 930cfd...d94ce5 )
by Sávio
08:18
created

SocketHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 44
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A maybeSetFd() 0 6 3
A __invoke() 0 8 1
1
<?php
2
3
namespace Conveyor\SocketHandlers\Abstractions;
4
5
use Slim\Container;
0 ignored issues
show
Bug introduced by
The type Slim\Container 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...
6
use Conveyor\SocketHandlers\Interfaces\SocketHandlerInterface;
7
use Conveyor\Actions\Interfaces\ActionInterface;
8
9
abstract class SocketHandler implements SocketHandlerInterface
10
{
11
    /**
12
     * @param string $data
13
     * @param int $fd
14
     */
15
    public function __invoke(string $data, $fd = null)
16
    {
17
        /** @var ActionInterface */
18
        $action = $this->parseData($data);
19
20
        $this->maybeSetFd($fd);
21
        
22
        return $action->execute();
0 ignored issues
show
Bug introduced by
The call to Conveyor\Actions\Interfa...ionInterface::execute() has too few arguments starting with data. ( Ignorable by Annotation )

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

22
        return $action->/** @scrutinizer ignore-call */ execute();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
23
    }
24
25
    public function maybeSetFd($fd) {
26
        $parsedData = $this->getParsedData();
0 ignored issues
show
Bug introduced by
The method getParsedData() does not exist on Conveyor\SocketHandlers\Abstractions\SocketHandler. Since it exists in all sub-types, consider adding an abstract or default implementation to Conveyor\SocketHandlers\Abstractions\SocketHandler. ( Ignorable by Annotation )

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

26
        /** @scrutinizer ignore-call */ 
27
        $parsedData = $this->getParsedData();
Loading history...
27
        $action = $this->getAction($parsedData['action']);
0 ignored issues
show
Bug introduced by
The method getAction() does not exist on Conveyor\SocketHandlers\Abstractions\SocketHandler. Since it exists in all sub-types, consider adding an abstract or default implementation to Conveyor\SocketHandlers\Abstractions\SocketHandler. ( Ignorable by Annotation )

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

27
        /** @scrutinizer ignore-call */ 
28
        $action = $this->getAction($parsedData['action']);
Loading history...
28
29
        if ($fd && method_exists($action, 'setFd')) {
30
            $action->setFd($fd);
31
        }
32
    }
33
34
    /**
35
     * This method identifies the action to be executed
36
     *
37
     * @param string $data
38
     *
39
     * @return ActionInterface
40
     *
41
     * @throws InvalidArgumentException
42
     */
43
    abstract public function parseData(string $data) : ActionInterface;
44
45
    /**
46
     * @param array $data
47
     *
48
     * @return void
49
     *
50
     * @throws InvalidArgumentException
51
     */
52
    abstract public function validateData(array $data) : void;
53
}
54