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 ( 650ed2...bb2ad6 )
by jake
01:53
created

FlashMessengerFactory::setSession()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Molniya - Flash Messenger
4
 *
5
 * PHP version 5
6
 *
7
 * This program is free software: you can redistribute it and/or modify it
8
 * under the terms of the GNU Affero General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or (at your
10
 * option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 * @category  Factory
21
 * @package   Jnjxp\Molniya
22
 * @author    Jake Johns <[email protected]>
23
 * @copyright 2016 Jake Johns
24
 * @license   http://www.gnu.org/licenses/agpl-3.0.txt AGPL V3
25
 * @link      https://github.com/jnjxp/jnjxp.molniya
26
 */
27
28
namespace Jnjxp\Molniya;
29
30
use Aura\Session\Session;
31
use Aura\Session\SessionFactory;
32
33
/**
34
 * FlashMessengerFactory
35
 *
36
 * @category Factory
37
 * @package  Jnjxp\Molniya
38
 * @author   Jake Johns <[email protected]>
39
 * @license  http://www.gnu.org/licenses/agpl-3.0.txt AGPL V3
40
 * @link     https://github.com/jnjxp/jnjxp.molniya
41
 */
42
class FlashMessengerFactory
43
{
44
    /**
45
     * Session
46
     *
47
     * @var Session
48
     *
49
     * @access protected
50
     */
51
    protected $session;
52
53
    /**
54
     * __construct
55
     *
56
     * @param Session $session DESCRIPTION
57
     *
58
     * @access public
59
     */
60 4
    public function __construct(Session $session = null)
61
    {
62 4
        $this->session = $session;
63 4
    }
64
65
    /**
66
     * NewInstance
67
     *
68
     * @param string $name Segment namespace
69
     *
70
     * @return FlashMessenger
71
     *
72
     * @access public
73
     */
74 4
    public function newInstance($name = 'Jnjxp\Molniya')
75
    {
76 4
        $session = $this->getSession();
77 4
        $segment = $session->getSegment($name);
78 4
        return new FlashMessenger($segment);
79
    }
80
81
    /**
82
     * Set Session
83
     *
84
     * @param Session $session DESCRIPTION
85
     *
86
     * @return mixed
87
     *
88
     * @access public
89
     */
90 2
    public function setSession(Session $session)
91
    {
92 2
        $this->session = $session;
93 2
        return $this;
94
    }
95
96
    /**
97
     * GetSession
98
     *
99
     * @return mixed
100
     *
101
     * @access protected
102
     */
103 4
    protected function getSession()
0 ignored issues
show
Coding Style introduced by
getSession uses the super-global variable $_COOKIE 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...
104
    {
105 4
        if (null == $this->session) {
106 1
            $this->session = (new SessionFactory)->newInstance($_COOKIE);
107 1
        }
108 4
        return $this->session;
109
    }
110
}
111