GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 784a42...226f28 )
by Gjero
03:03
created

core/Pimf/Session/Storages/Redis.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Pimf
4
 *
5
 * @copyright Copyright (c)  Gjero Krsteski (http://krsteski.de)
6
 * @license   http://opensource.org/licenses/MIT MIT License
7
 */
8
9
namespace Pimf\Session\Storages;
10
11
/**
12
 * @package Session_Storages
13
 * @author  Gjero Krsteski <[email protected]>
14
 */
15
class Redis extends Storage
16
{
17
    /**
18
     * The Redis cache storage instance.
19
     *
20
     * @var \Pimf\Cache\Storages\Redis
21
     */
22
    protected $redis;
23
24
    /**
25
     * @param \Pimf\Cache\Storages\Redis $redis
26
     */
27
    public function __construct(\Pimf\Cache\Storages\Redis $redis)
28
    {
29
        $this->redis = $redis;
30
    }
31
32
    /**
33
     * Load a session from storage by a given ID.
34
     *
35
     * @param string $key
36
     *
37
     * @return array|mixed|null
38
     */
39
    public function load($key)
40
    {
41
        return $this->redis->get($key);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->redis->get($key); (object|integer|double|string|array|boolean|null) is incompatible with the return type declared by the abstract method Pimf\Session\Storages\Storage::load of type array|null.

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 my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
42
    }
43
44
    /**
45
     * Save a given session to storage.
46
     *
47
     * @param array $session
48
     * @param array $config
49
     * @param bool  $exists
50
     */
51
    public function save($session, $config, $exists)
52
    {
53
        $this->redis->put($session['id'], $session, $config['lifetime']);
54
    }
55
56
    /**
57
     * @param string $key
58
     */
59
    public function delete($key)
60
    {
61
        $this->redis->forget($key);
62
    }
63
}
64