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.

Memcached   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 98
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A open() 0 5 1
A close() 0 6 1
A read() 0 4 1
A write() 0 4 1
A destroy() 0 4 1
A gc() 0 4 1
1
<?php
2
/**
3
 * Kotori.php
4
 *
5
 * A Tiny Model-View-Controller PHP Framework
6
 *
7
 * This content is released under the Apache 2 License
8
 *
9
 * Copyright (c) 2015-2017 Kotori Technology. All rights reserved.
10
 *
11
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14
 *
15
 *     http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22
 */
23
24
/**
25
 * Memcached Session Class
26
 *
27
 * @package     Kotori
28
 * @subpackage  Session
29
 * @author      Kokororin
30
 * @link        https://kotori.love
31
 */
32
namespace Kotori\Http\Session;
33
34
use Kotori\Core\Cache\Memcached as MemcachedDriver;
35
use SessionHandlerInterface;
36
37
class Memcached implements SessionHandlerInterface
38
{
39
    /**
40
     * Default configuration
41
     *
42
     * @var array
43
     */
44
    protected $config = [
45
        'host' => '127.0.0.1',
46
        'port' => 11211,
47
        'expire' => 3600,
48
        'prefix' => '',
49
    ];
50
51
    /**
52
     * Class constructor
53
     *
54
     * Setup Memcache(d)
55
     *
56
     * @param  array $config
57
     */
58
    public function __construct($config = [])
59
    {
60
        $this->config = array_merge($this->config, $config);
61
    }
62
63
    /**
64
     * Open session
65
     *
66
     * @param  string    $savePath
67
     * @param  mixed     $sessName
68
     * @return boolean
69
     */
70
    // @codingStandardsIgnoreStart
71
    public function open($savePath, $sessName)
72
    {
73
        $this->memcachedDriver = new MemcachedDriver($this->config);
0 ignored issues
show
Bug introduced by
The property memcachedDriver does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
74
        return true;
75
    }
76
    // @codingStandardsIgnoreEnd
77
78
    /**
79
     * Close session
80
     *
81
     * @return boolean
82
     */
83
    public function close()
84
    {
85
        $this->gc(ini_get('session.gc_maxlifetime'));
0 ignored issues
show
Unused Code introduced by
The call to the method Kotori\Http\Session\Memcached::gc() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
86
        $this->memcachedDriver = null;
87
        return true;
88
    }
89
90
    /**
91
     * Read session
92
     *
93
     * @param  string $sessID
94
     * @return string
95
     */
96
    public function read($sessID)
97
    {
98
        return (string) $this->memcachedDriver->get($this->config['prefix'] . $sessID);
99
    }
100
101
    /**
102
     * Write session
103
     *
104
     * @param string $sessID
105
     * @param String $sessData
106
     * @return boolean
107
     */
108
    public function write($sessID, $sessData)
109
    {
110
        return $this->memcachedDriver->set($this->config['prefix'] . $sessID, $sessData, $this->config['expire']);
111
    }
112
113
    /**
114
     * Delete session
115
     *
116
     * @param  string $sessID
117
     * @return boolean
118
     */
119
    public function destroy($sessID)
120
    {
121
        return $this->memcachedDriver->delete($this->config['prefix'] . $sessID);
122
    }
123
124
    /**
125
     * do garbage collection
126
     *
127
     * @param  string $sessMaxLifeTime
128
     * @return boolean
129
     */
130
    public function gc($sessMaxLifeTime)
131
    {
132
        return true;
133
    }
134
}
135