Session   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 140
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 2
cbo 0
dl 0
loc 140
ccs 0
cts 42
cp 0
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getUsername() 0 4 1
A getGroup() 0 4 1
A setGroup() 0 4 1
A getTrustedIps() 0 4 1
A setTrustedIps() 0 4 1
A hasTrustedIps() 0 4 1
A addData() 0 4 1
A hasData() 0 4 1
A getData() 0 6 3
1
<?php
2
3
/**
4
 *
5
 * This file is part of the Apix Project.
6
 *
7
 * (c) Franck Cassedanne <franck at ouarz.net>
8
 *
9
 * @license     http://opensource.org/licenses/BSD-3-Clause  New BSD License
10
 *
11
 */
12
13
namespace Apix;
14
15
class Session
16
{
17
18
    /**
19
     * Holds the session's username.
20
     * @var string
21
     */
22
    protected $username;
23
24
    /**
25
     * Holds this user's group.
26
     * @var string
27
     */
28
    protected $group;
29
30
    /**
31
     * Holds the user's trusted IPs.
32
     * @var array
33
     */
34
    protected $ips = null;
35
36
    /**
37
     * Holds some user's arbitrary data.
38
     * @var array
39
     */
40
    protected $data = array();
41
42
    /**
43
     * Constructor will set the session for the given username.
44
     *
45
     * @param string      $username
46
     * @param string|null $group
47
     */
48
    public function __construct($username, $group = null)
49
    {
50
        $this->username = $username;
51
        $this->group = $group;
52
53
        // session_start();
54
    }
55
56
    /**
57
     * Returns the username.
58
     *
59
     * @return string
60
     */
61
    public function getUsername()
62
    {
63
        return $this->username;
64
    }
65
66
    /**
67
     * Returns the user's group.
68
     *
69
     * @return string
70
     */
71
    public function getGroup()
72
    {
73
        return $this->group;
74
    }
75
76
    /**
77
     * Sets the user's group.
78
     *
79
     * @param  string $group
80
     * @return void
81
     */
82
    public function setGroup($group)
83
    {
84
        $this->group = $group;
85
    }
86
87
    /**
88
     * Returns the trusted IPs.
89
     *
90
     * @return array
91
     */
92
    public function getTrustedIps()
93
    {
94
        return $this->ips;
95
    }
96
97
    /**
98
     * Sets the trusted IPs.
99
     *
100
     * @param  array $ips
101
     * @return void
102
     */
103
    public function setTrustedIps(array $ips=null)
104
    {
105
        $this->ips = $ips;
0 ignored issues
show
Documentation Bug introduced by
It seems like $ips can be null. However, the property $ips is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
106
    }
107
108
    /**
109
     * Check if the specified user data is set.
110
     *
111
     * @param  string  $group
0 ignored issues
show
Bug introduced by
There is no parameter named $group. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
112
     * @return boolean
113
     */
114
    public function hasTrustedIps()
115
    {
116
        return null !== $this->ips;
117
    }
118
119
    /**
120
     * Adds arbitrary session data.
121
     *
122
     * @param  string $group
0 ignored issues
show
Bug introduced by
There is no parameter named $group. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
123
     * @return void
124
     */
125
    public function addData($key, $value)
126
    {
127
        $this->data[$key] = $value;
128
    }
129
130
    /**
131
     * Checks wether the specified key is set in the session dataset.
132
     *
133
     * @param  string  $group
0 ignored issues
show
Bug introduced by
There is no parameter named $group. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
134
     * @return boolean
135
     */
136
    public function hasData($key)
137
    {
138
        return isset($this->data[$key]);
139
    }
140
141
    /**
142
     * Returns the specified data -- or the whole dataset if null.
143
     *
144
     * @param  string     $key
145
     * @return mixed|null
146
     */
147
    public function getData($key=null)
148
    {
149
        if(null === $key) return $this->data;
150
151
        return isset($this->data[$key]) ? $this->data[$key] : null;
152
    }
153
154
}
155