Protection::canDeleteFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
namespace kalanis\RemoteRequest\Protocols\Fsp\Answer;
4
5
6
use kalanis\RemoteRequest\Protocols\Fsp;
7
8
9
/**
10
 * Class Protection
11
 * @package kalanis\RemoteRequest\Protocols\Fsp\Answer
12
 * Process protection answer
13
 */
14
class Protection extends AAnswer
15
{
16
    protected string $directory = '';
17
    protected ?bool $isOwnedByMe = null;
18
    protected ?bool $canListDir = null;
19
    protected ?bool $canReadOnlyOwner = null;
20
    protected ?bool $canCreateFileHere = null;
21
    protected ?bool $canRenameFileHere = null;
22
    protected ?bool $canDeleteFileHere = null;
23
    protected ?bool $canCreateDirHere = null;
24
    protected ?bool $containsReadme = null;
25
26 1
    public function process(): parent
27
    {
28 1
        $this->directory = substr($this->answer->getContent(), 0, -1);
29 1
        $extraData = $this->answer->getExtraData();
30 1
        $settings = Fsp\Strings::mb_ord($extraData[0]);
31 1
        $this->isOwnedByMe = $this->parseBit($settings, 0x01);
32 1
        $this->canDeleteFileHere = $this->parseBit($settings, 0x02);
33 1
        $this->canCreateFileHere = $this->parseBit($settings, 0x04);
34 1
        $this->canCreateDirHere = $this->parseBit($settings, 0x08);
35 1
        $this->canReadOnlyOwner = $this->parseBit($settings, 0x10);
36 1
        $this->containsReadme = $this->parseBit($settings, 0x20);
37 1
        $this->canListDir = $this->parseBit($settings, 0x40);
38 1
        $this->canRenameFileHere = $this->parseBit($settings, 0x80);
39 1
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type kalanis\RemoteRequest\Pr...s\Fsp\Answer\Protection which is incompatible with the type-hinted return parent.
Loading history...
40
    }
41
42
    /**
43
     * @param int $input
44
     * @param int $bitPosition
45
     * @return bool
46
     */
47 1
    protected function parseBit($input, $bitPosition): bool
48
    {
49 1
        return boolval($input & $bitPosition);
50
    }
51
52 1
    public function getDirectory(): string
53
    {
54 1
        return $this->directory;
55
    }
56
57 1
    public function isMy(): ?bool
58
    {
59 1
        return $this->isOwnedByMe;
60
    }
61
62 1
    public function canList(): ?bool
63
    {
64 1
        return $this->canListDir;
65
    }
66
67 1
    public function canReadOnlyOwner(): ?bool
68
    {
69 1
        return $this->canReadOnlyOwner;
70
    }
71
72 1
    public function canCreateFile(): ?bool
73
    {
74 1
        return $this->canCreateFileHere;
75
    }
76
77 1
    public function canRenameFile(): ?bool
78
    {
79 1
        return $this->canRenameFileHere;
80
    }
81
82 1
    public function canDeleteFile(): ?bool
83
    {
84 1
        return $this->canDeleteFileHere;
85
    }
86
87 1
    public function canCreateDir(): ?bool
88
    {
89 1
        return $this->canCreateDirHere;
90
    }
91
92 1
    public function containsReadme(): ?bool
93
    {
94 1
        return $this->containsReadme;
95
    }
96
}
97