Flag::__toString()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 6
cp 0
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 0
crap 12
1
<?php
2
declare(strict_types=1);
3
namespace Hyphper\Frame;
4
5
class Flag
6
{
7
    const END_STREAM = 0x01;
8
    const ACK = 0x01;
9
    const END_HEADERS = 0x04;
10
    const PADDED = 0x08;
11
    const PRIORITY = 0x20;
12
13
    protected $bit;
14
15
    public function __construct($bit)
16
    {
17
        $this->bit = $bit;
18
    }
19
20
    /**
21
     * @return int (as hex)
22
     */
23
    public function getBit()
24
    {
25
        return $this->bit;
26
    }
27
28
    public function __toString(): string
29
    {
30
        $class = new \ReflectionClass($this);
31
        foreach ($class->getConstants() as $name => $value) {
32
            if ($value == $this->bit) {
33
                return $name;
34
            }
35
        }
36
    }
37
}
38