Completed
Push — master ( 037a4c...3e40ee )
by Bruno
11:44
created

ArrayCache::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace SitePoint\Rauth;
4
5
final class ArrayCache implements Cache
6
{
7
    private $data = [];
8
9
    public function __construct(array $data = null)
10
    {
11
        $this->data = $data;
0 ignored issues
show
Documentation Bug introduced by
It seems like $data can be null. However, the property $data is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

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

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
12
    }
13
14
    public function get(string $key)
15
    {
16
        return $this->data[$key] ?? null;
17
    }
18
19
    public function set(string $key, $value) : Cache
20
    {
21
        $this->data[$key] = $value;
22
        return $this;
23
    }
24
25
    public function has(string $key) : bool
26
    {
27
        return isset($this->data[$key]);
28
    }
29
}
30