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 — 3.0 ( 9b5baa...d405c3 )
by Vermeulen
02:54
created

Memcache::connectToServers()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 32
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 32
rs 8.439
cc 6
eloc 16
nc 6
nop 0
1
<?php
2
3
namespace BFW\Memcache;
4
5
use \Exception;
6
7
/**
8
 * Class to manage connection to memcache(d) server with memcache lib
9
 */
10
class Memcache extends \Memcache
11
{
12
    //Include traits to add some methods
13
    use \BFW\Traits\Memcache;
14
    
15
    /**
16
     * @var \BFW\Application $app Instance of BFW Application
17
     */
18
    protected $app;
19
20
    /**
21
     * @var array $config Config define on bfw config file for memcache(d)
22
     */
23
    protected $config;
24
25
    /**
26
     * Constructor.
27
     * Connect to servers
28
     * 
29
     * @param \BFW\Application $app The BFW Application instance
30
     * 
31
     * @throws Exception If PHP Version is >= 7.x (no memcache extension)
32
     */
33
    public function __construct(\BFW\Application $app)
34
    {
35
        //Check php version. No memcache lib for >= 7.x
36
        if (PHP_VERSION_ID > 70000) {
37
            throw new Exception(
38
                'PHP Memcache Extension not supported for PHP 7'
39
            );
40
        }
41
        
42
        $this->app    = $app;
43
        $this->config = $this->app->getConfig('memcached');
44
45
        $this->connectToServers();
46
    }
47
48
    /**
49
     * Connect to memcache(d) server defined on config
50
     * 
51
     * @return void
52
     */
53
    protected function connectToServers()
54
    {
55
        //Loop on declared server(s)
56
        foreach ($this->config['server'] as $server) {
57
            $this->getServerInfos($server);
58
            
59
            $host       = $server['host'];
60
            $port       = $server['port'];
61
            $timeout    = $server['timeout'];
62
            $persistent = $server['persistent'];
63
            
64
            //Not checked if port = (int) 0; Doc said to define to 0 for socket
65
            if (empty($host) || $port === null) {
66
                continue;
67
            }
68
            
69
            //Change method used to connect if it's a persistent connection
70
            $methodName = 'connect';
71
            if ($persistent === true) {
72
                $methodName = 'pconnect';
73
            }
74
            
75
            //If a timeout is declared
76
            //not found the default value for this parameters, so a if...
77
            if ($timeout !== null) {
78
                $this->{$methodName}($host, $port, $timeout);
79
                return;
80
            }
81
            
82
            $this->{$methodName}($host, $port);
83
        }
84
    }
85
}
86