Completed
Push — master ( 640da7...eb7508 )
by Danilo
03:54
created

EntityAccess   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 41
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A offsetSet() 0 3 1
A offsetExists() 0 5 1
A offsetUnset() 0 4 1
A offsetGet() 0 13 3
1
<?php
2
3
/*
4
 * This file is part of the PhpBotFramework.
5
 *
6
 * PhpBotFramework is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as
8
 * published by the Free Software Foundation, version 3.
9
 *
10
 * PhpBotFramework is distributed in the hope that it will be useful, but
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public License
16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace PhpBotFramework\Entities;
20
21
/**
22
 * \addtogroup Core
23
 * @{
24
 */
25
trait EntityAccess
26
{
27
    /** @} */
28
29
    /** \brief Contains the array passed __construct */
30
    private $container;
31
32
    public function __construct($data)
33
    {
34
        $this->container = $data;
35
    }
36
37
    public function offsetSet($offset, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $offset is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
    }
40
41
    public function offsetExists($offset)
42
    {
43
        // Is it set?
44
        return isset($this->container[$offset]);
45
    }
46
47
    public function offsetUnset($offset)
0 ignored issues
show
Unused Code introduced by
The parameter $offset is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
    {
49
        // Log a warning
50
    }
51
52
    public function offsetGet($offset)
53
    {
54
        // Get name of the method, the class should have. Like "getText"
55
        $method = Text::camelCase("get $offset");
56
57
        // If it exists, call it and return its return value
58
        if (method_exists($this, $method)) {
59
            return $this->{$method}();
60
        }
61
62
        // If not return the data from the array after checking it is set
63
        return isset($this->container[$offset]) ? $this->container[$offset] : null;
64
    }
65
}
66