These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Created by Marcin. |
||
4 | * Date: 18.02.2018 |
||
5 | * Time: 20:00 |
||
6 | */ |
||
7 | |||
8 | namespace mrcnpdlk\Xmdb; |
||
9 | |||
10 | |||
11 | use Imdb\CacheInterface; |
||
12 | |||
13 | class ImdbCache implements CacheInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var \Psr\SimpleCache\CacheInterface |
||
17 | */ |
||
18 | private $oPsrCache; |
||
19 | /** |
||
20 | * @var integer |
||
21 | */ |
||
22 | private $ttl; |
||
23 | |||
24 | public function __construct(\Psr\SimpleCache\CacheInterface $oCache, integer $ttl = null) |
||
25 | { |
||
26 | $this->oPsrCache = $oCache; |
||
27 | $this->ttl = $ttl ?? 3600; |
||
0 ignored issues
–
show
|
|||
28 | } |
||
29 | |||
30 | public function get($key) |
||
31 | { |
||
32 | return $this->oPsrCache->get($key); |
||
33 | } |
||
34 | |||
35 | public function purge() |
||
36 | { |
||
37 | return $this; |
||
38 | } |
||
39 | |||
40 | public function set($key, $value) |
||
41 | { |
||
42 | $this->oPsrCache->set($key, $value, $this->ttl); |
||
43 | |||
44 | return $this; |
||
0 ignored issues
–
show
The return type of
return $this; (mrcnpdlk\Xmdb\ImdbCache ) is incompatible with the return type declared by the interface Imdb\CacheInterface::set of type boolean .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function
Loading history...
|
|||
45 | } |
||
46 | } |
||
47 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.