Passed
Push — master ( ff8036...6e1454 )
by Nikita
02:09
created

GdaemonCommands   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 36
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A exec() 0 22 3
1
<?php
2
3
namespace Knik\Gameap;
4
5
use Knik\Binn\BinnList;
6
use RuntimeException;
7
use InvalidArgumentException;
8
9
class GdaemonCommands extends Gdaemon
10
{
11
    const COMMAND_EXEC = 1;
12
13
    /**
14
     * @var int
15
     */
16
    protected $mode = self::DAEMON_SERVER_MODE_CMD;
17
18
    /**
19
     * @param $command
20
     * @param $exitCode Command exit code
0 ignored issues
show
Bug introduced by
The type Knik\Gameap\Command 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...
21
     * @return string Command execute results
22
     */
23 6
    public function exec($command, &$exitCode = null)
24
    {
25 6
        $writeBinn = new BinnList;
26
27 6
        $writeBinn->addUint8(self::COMMAND_EXEC);
28 6
        $writeBinn->addStr($command);
29
        //$writeBinn->addUint8($timeout); // Options
30
31 6
        $read = $this->writeAndReadSocket($writeBinn->serialize());
32
33 6
        $readBinn = new BinnList;
34 6
        $readBinn->binnOpen($read);
35 6
        $results = $readBinn->unserialize();
36
37 6
        if ($results[0] != self::STATUS_OK) {
38 3
            throw new RuntimeException('Execute command error: ' . isset($results[1]) ? $results[1] : 'Unknown');
39
        }
40
41 3
        $exitCode = $results[1];
42
43
        // Return command execute results
44 3
        return $results[2];
45
    }
46
}