Passed
Push — develop ( d29a7c...c4887a )
by Mathieu
01:49
created

DBObjectProtected::markProtectedVariableAsLoaded()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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

69
    protected function accessToProtectedVariable(/** @scrutinizer ignore-unused */ $name)

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...
70
    {
71
        return false;
72
    }
73
}