Version   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A thruControlMaxAllowed() 0 3 1
A isServerLogging() 0 3 1
A getVersion() 0 3 1
A isPrivateMode() 0 3 1
A process() 0 19 4
A thruControlMaxPayload() 0 3 1
A parseBit() 0 3 1
A isReadOnly() 0 3 1
A acceptsExtra() 0 3 1
A canThruControl() 0 3 1
A wantReverseLookup() 0 3 1
1
<?php
2
3
namespace kalanis\RemoteRequest\Protocols\Fsp\Answer;
4
5
6
use kalanis\RemoteRequest\Protocols\Fsp;
7
8
9
/**
10
 * Class Version
11
 * @package kalanis\RemoteRequest\Protocols\Fsp\Answer
12
 * Process FSP version
13
 */
14
class Version extends AAnswer
15
{
16
    protected string $version = '';
17
    protected ?bool $serverLogs = null;
18
    protected ?bool $readOnly = null;
19
    protected ?bool $reverseLookup = null;
20
    protected ?bool $privateMode = null;
21
    protected ?bool $thruControl = null;
22
    protected ?bool $acceptExtra = null;
23
    protected int $thruMaxAllowed = 0;
24
    protected int $thruMaxPayload = 0;
25
26 2
    public function process(): parent
27
    {
28 2
        $this->version = substr($this->answer->getContent(), 0, -1);
29 2
        $extraSize = $this->answer->getFilePosition();
30 2
        $extraData = $this->answer->getExtraData();
31 2
        if ($extraSize && $extraData) {
32 2
            $settings = Fsp\Strings::mb_ord($extraData[0]);
33 2
            $this->serverLogs = $this->parseBit($settings, 0b10000000);
34 2
            $this->readOnly = $this->parseBit($settings, 0b01000000);
35 2
            $this->reverseLookup = $this->parseBit($settings, 0b00100000);
36 2
            $this->privateMode = $this->parseBit($settings, 0b00010000);
37 2
            $this->thruControl = $this->parseBit($settings, 0b00001000);
38 2
            $this->acceptExtra = $this->parseBit($settings, 0b00000100);
39 2
            if ($this->thruControl) {
40 1
                $this->thruMaxAllowed = Fsp\Strings::mb_ord(substr($extraData, 1, 4));
41 1
                $this->thruMaxPayload = Fsp\Strings::mb_ord(substr($extraData, 5, 2));
42
            }
43
        }
44 2
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type kalanis\RemoteRequest\Protocols\Fsp\Answer\Version which is incompatible with the type-hinted return parent.
Loading history...
45
    }
46
47 2
    protected function parseBit(int $input, int $bitPosition): bool
48
    {
49 2
        return boolval($input & $bitPosition);
50
    }
51
52 2
    public function getVersion(): string
53
    {
54 2
        return $this->version;
55
    }
56
57 2
    public function isServerLogging(): ?bool
58
    {
59 2
        return $this->serverLogs;
60
    }
61
62 2
    public function isReadOnly(): ?bool
63
    {
64 2
        return $this->readOnly;
65
    }
66
67 2
    public function wantReverseLookup(): ?bool
68
    {
69 2
        return $this->reverseLookup;
70
    }
71
72 2
    public function isPrivateMode(): ?bool
73
    {
74 2
        return $this->privateMode;
75
    }
76
77 2
    public function acceptsExtra(): ?bool
78
    {
79 2
        return $this->acceptExtra;
80
    }
81
82 1
    public function canThruControl(): ?bool
83
    {
84 1
        return $this->thruControl;
85
    }
86
87 1
    public function thruControlMaxAllowed(): int
88
    {
89 1
        return $this->thruMaxAllowed;
90
    }
91
92 1
    public function thruControlMaxPayload(): int
93
    {
94 1
        return $this->thruMaxPayload;
95
    }
96
}
97