DBObjectProtected::isProtectedVariable()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Suricate\Traits;
6
7
use Suricate\DBObject;
8
9
trait DBObjectProtected
10
{
11
    protected $protectedVariables = [];
12
    protected $protectedValues = [];
13
    protected $loadedProtectedVariables = [];
14
15
    /**
16
     * @param string $name
17
     */
18 1
    private function getProtectedVariable(string $name)
19
    {
20
        // Variable exists, and is already loaded
21
        if (
22 1
            isset($this->protectedValues[$name]) &&
23 1
            $this->isProtectedVariableLoaded($name)
24
        ) {
25
            return $this->protectedValues[$name];
26
        }
27
        // Variable has not been loaded
28 1
        if (!$this->isProtectedVariableLoaded($name)) {
29 1
            if ($this->accessToProtectedVariable($name)) {
30 1
                $this->markProtectedVariableAsLoaded($name);
31
            }
32
        }
33
34 1
        if (isset($this->protectedValues[$name])) {
35 1
            return $this->protectedValues[$name];
36
        }
37
38 1
        return null;
39
    }
40
    /**
41
     * Mark a protected variable as loaded
42
     * @param  string $name varialbe name
43
     *
44
     * @return DBObject
45
     */
46 1
    public function markProtectedVariableAsLoaded(string $name)
47
    {
48 1
        if ($this->isProtectedVariable($name)) {
49 1
            $this->loadedProtectedVariables[$name] = true;
50
        }
51
52 1
        return $this;
53
    }
54
55
    /**
56
     * Check if variable is a protected variable
57
     * @param  string  $name variable name
58
     * @return boolean
59
     */
60 8
    public function isProtectedVariable(string $name): bool
61
    {
62 8
        return in_array($name, $this->protectedVariables);
63
    }
64
65
    /**
66
     * Check if a protected variable already have been loaded
67
     * @param  string  $name Variable name
68
     * @return boolean
69
     */
70 1
    protected function isProtectedVariableLoaded(string $name): bool
71
    {
72 1
        return isset($this->loadedProtectedVariables[$name]);
73
    }
74
75
    protected function accessToProtectedVariable(string $name): bool
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

75
    protected function accessToProtectedVariable(/** @scrutinizer ignore-unused */ string $name): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
    {
77
        return false;
78
    }
79
}
80