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.

Jar::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\Cookie;
4
5
class Jar {
6
7
    protected $_defaults;
8
9
    public static $instance;
10
11
    public function  __construct() {
12
        $this->initDefaults();
13
    }
14
15
    /**
16
     * @return Cookie
17
    */
18
    public function newCookie() {
19
        $cookie = new Cookie();
20
        $defaults = $this->getDefaults();
21
        $cookie->setPath($defaults['path']);
22
        $cookie->setDomain($defaults['domain']);
23
        $cookie->setExpireTimer($defaults['expireTimer']);
24
        return $cookie;
25
    }
26
27
    public function initDefaults() {
0 ignored issues
show
Coding Style introduced by
initDefaults uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
28
        $this->_defaults = array(
29
            'path'   => '/',
30
            'domain' => $_SERVER['SERVER_NAME'],
31
            'expireTimer' => 6 * 60 *60,
32
        );
33
    }
34
35
    public function setDefaults($defaults) {
36
        foreach ($defaults as $name => $value) {
37
            $this->setDefault($name, $value);
38
        }
39
    }
40
41
    public function setDefault($name, $value = NULL) {
42
        if ($value !== NULL) {
43
            $this->_defaults[$name] = $value;
44
        }
45
    }
46
47
    public function getDefaults() {
48
        return $this->_defaults;
49
    }
50
51
	/**
52
	 * Singleton
53
	 *
54
	 * @return self
55
	 */
56
    public static function instance() {
57
        if (!self::$instance instanceof self) {
58
            self::$instance = new self;
59
        }
60
        return self::$instance;
61
    }
62
}