BitMask::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 1
1
<?php
2
namespace SoliDry\Extension;
3
4
use SoliDry\Exceptions\AttributesException;
5
use SoliDry\Types\ConfigInterface;
6
use SoliDry\Types\ErrorsInterface;
7
8
/**
9
 * Class BitMask
10
 * @package SoliDry\Extension
11
 */
12
class BitMask
13
{
14
    /**
15
     * @var array
16
     */
17
    private array $entity;
18
19
    private $field;
20
    private $isEnabled;
21
22
    /**
23
     * SpellCheck constructor.
24
     * @param array $params
25
     */
26
    public function __construct(array $params)
27
    {
28
        $this->entity    = $params;
29
        $this->field     = key($this->entity);
30
        $this->isEnabled = empty($this->entity[$this->field][ConfigInterface::ENABLED]) ? false : true;
31
    }
32
33
    /**
34
     * @return boolean
35
     */
36
    public function isEnabled(): bool
37
    {
38
        return $this->isEnabled;
39
    }
40
41
    /**
42
     * @return mixed|null
43
     */
44
    public function getField()
45
    {
46
        return $this->field;
47
    }
48
49
    /**
50
     * @return mixed
51
     * @throws AttributesException
52
     */
53
    public function getFlags()
54
    {
55
        if(empty($this->entity[$this->field][ConfigInterface::FLAGS])) {
56
            throw new AttributesException(ErrorsInterface::JSON_API_ERRORS[ErrorsInterface::HTTP_CODE_FSM_FLAGS], ErrorsInterface::HTTP_CODE_FSM_FLAGS);
57
        }
58
        return $this->entity[$this->field][ConfigInterface::FLAGS];
59
    }
60
61
    /**
62
     * Whether mask should be hidden or not
63
     *
64
     * @return bool
65
     */
66
    public function isHidden(): bool
67
    {
68
        return empty($this->entity[$this->field][ConfigInterface::HIDE_MASK]) ? false : true;
69
    }
70
}