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 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A connection() 0 10 2
A connect() 0 16 4
A __callStatic() 0 4 1
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;
10
11
/**
12
 * For use please add the following code to the end of the config.core.php file:
13
 *
14
 * <code>
15
 *
16
 * 'cache' => array(
17
 *
18
 *    'storage' => 'memcached',
19
 *       'servers' => array(
20
 *           array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100),
21
 *        ),
22
 *      ),
23
 *  ),
24
 *
25
 * </code>
26
 *
27
 * Memcached usage:
28
 *
29
 * <code>
30
 *    // Get the Memcache connection and get an item from the cache
31
 *    $name = Memcached::connection()->get('name');
32
 *
33
 *    // Get the Memcache connection and place an item in the cache
34
 *    Memcached::connection()->set('name', 'Robin');
35
 *
36
 *    // Get an item from the Memcache instance
37
 *    $name = Memcached::get('name');
38
 *
39
 *    // Store data on the Memcache server
40
 *    Memcached::set('name', 'Robin');
41
 * </code>
42
 *
43
 * @package Pimf
44
 * @author  Gjero Krsteski <[email protected]>
45
 *
46
 * @method get($key)
47
 * @method put($key, $value, $expiration)
48
 * @method forget($key);
49
 */
50
class Memcached
51
{
52
    /**
53
     * @var \Memcached
54
     */
55
    protected static $connection;
56
57
    /**
58
     * @return \Memcached
59
     */
60
    public static function connection()
61
    {
62
        if (static::$connection === null) {
63
            static::$connection = static::connect(
64
                Config::get('cache.memcached.servers')
65
            );
66
        }
67
68
        return static::$connection;
69
    }
70
71
    /**
72
     * Create a new Memcached connection instance.
73
     *
74
     * @param array $servers
75
     * @param null  $memcache
76
     *
77
     * @return \Memcached|null
78
     * @throws \RuntimeException
79
     */
80
    protected static function connect(array $servers, $memcache = null)
81
    {
82
        if (!$memcache) {
83
            $memcache = new \Memcached();
84
        }
85
86
        foreach ($servers as $server) {
87
            $memcache->addServer($server['host'], $server['port'], $server['weight']);
88
        }
89
90
        if ($memcache->getVersion() === false) {
91
            throw new \RuntimeException('could not establish memcached connection!');
92
        }
93
94
        return $memcache;
95
    }
96
97
    /**
98
     * Dynamically pass all other method calls to the Memcache instance.
99
     *
100
     * @param $method
101
     * @param $parameters
102
     *
103
     * @return mixed
104
     */
105
    public static function __callStatic($method, $parameters)
106
    {
107
        return call_user_func_array(array(static::connection(), $method), $parameters);
108
    }
109
}
110