Completed
Push — master ( 1ce70a...0adf65 )
by Litera
11:25 queued 21s
created

SkautisService::setSkautis()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Services\SkautIS;
4
5
use Nette\Object;
6
use Skautis\Skautis;
7
8
/**
9
 * SkautIS service
10
 */
11
abstract class SkautisService extends Object
12
{
13
14
	/**
15
	 * Class Table reference
16
	 * @var instance of BaseTable
17
	 */
18
	protected $table;
19
20
21
	/**
22
	 * Holds SkautIS instance
23
	 * @var Skautis\Skautis
24
	 */
25
	protected $skautis;
26
27
28
	/**
29
	 * Use local storage (cache)?
30
	 * @var bool
31
	 */
32
	private $useCache = TRUE;
33
34
35
	/**
36
	 * Short term storage for saving SkautIS answers
37
	 * @var type
38
	 */
39
	private static $storage;
40
41
42
	/**
43
	 * Construct
44
	 */
45
	public function __construct(Skautis $skautIS = NULL)
46
	{
47
		$this->setSkautis($skautIS);
0 ignored issues
show
Bug introduced by
It seems like $skautIS defined by parameter $skautIS on line 45 can be null; however, App\Services\SkautIS\SkautisService::setSkautis() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
48
		self::$storage = array();
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type object<App\Services\SkautIS\type> of property $storage.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49
	}
50
51
52
	/**
53
	 * Get user information
54
	 *
55
	 * @param   void
56
	 * @return  array  Login ID, Role ID, Unit ID
57
	 */
58
	public function getInfo()
59
	{
60
		$skautis = $this->getSkautis();
61
62
		return [
63
			"ID_Login" => $skautis->getUser()->getLoginId(),
64
			"ID_Role"  => $skautis->getUser()->getRoleId(),
65
			"ID_Unit"  => $skautis->getUser()->getUnitId(),
66
		];
67
	}
68
69
70
	/**
71
	 * Save value to local storage
72
	 *
73
	 * @param   mixed  $id
74
	 * @param   mixed  $val
75
	 * @return  mixed
76
	 */
77
	protected function save($id, $val)
78
	{
79
		if ($this->useCache) {
80
			self::$storage[$id] = $val;
81
		}
82
		return $val;
83
	}
84
85
86
	/**
87
	 * Get object from local storage
88
	 *
89
	 * @param   string|int   $id
90
	 * @return  mixed|FALSE
91
	 */
92
	protected function load($id)
93
	{
94
		if ($this->useCache && array_key_exists($id, self::$storage)) {
95
			return self::$storage[$id];
96
		}
97
		return FALSE;
98
	}
99
100
	/**
101
	 * @return Skautis\Skautis
102
	 */
103
	public function getSkautis(): Skautis
104
	{
105
		return $this->skautis;
106
	}
107
108
	/**
109
	 * @param Skautis\Skautis $skautis
110
	 *
111
	 * @return self
112
	 */
113
	public function setSkautis(Skautis $skautis): self
114
	{
115
		$this->skautis = $skautis;
0 ignored issues
show
Documentation Bug introduced by
It seems like $skautis of type object<Skautis\Skautis> is incompatible with the declared type object<Skautis\Skautis\Skautis> of property $skautis.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
116
117
		return $this;
118
	}
119
120
}
121