Completed
Push — master ( ed7e26...883d13 )
by Maciej
12:17
created

Entity::offsetSet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
/**
3
 * Created by Maciej Paprocki for Bureau-VA.
4
 * Date: 17/02/2016
5
 * Project Name: MaciekPaprocki\WordpressGuzzle
6
 * Time: 11:27
7
 */
8
9
namespace BureauVa\WordpressGuzzle\Entity;
10
11
use BureauVa\WordpressGuzzle\Helper\StringHelper;
12
13
/**
14
 * Class Entity
15
 * @package MaciekPaprocki\WordpressGuzzle
16
 */
17
18
abstract class Entity implements \ArrayAccess
19
{
20
    protected $internaleCounter = 0;
21
22
    /**
23
     * @param $offset
24
     * @param $value
25
     */
26
    public function offsetSet($offset, $value)
27
    {
28
        if (is_null($offset)) {
29
            $this->{$this->internaleCounter} = $value;
30
            $this->internaleCounter++;
31
        } else {
32
            $this->{$offset} = $value;
33
        }
34
    }
35
36
    /**
37
     * @param $offset
38
     * @return bool
39
     */
40
    public function offsetExists($offset)
41
    {
42
        return isset($this->{$offset});
43
    }
44
45
    /**
46
     * @param $offset
47
     */
48
    public function offsetUnset($offset)
49
    {
50
        unset($this->{$offset});
51
    }
52
53
    /**
54
     * @param $offset
55
     * @return null
56
     */
57
    public function offsetGet($offset)
58
    {
59
        return isset($this->{$offset}) ? $this->{$offset} : null;
60
    }
61
62
    /**
63
     * @param $name
64
     * @param $val
65
     * @return $this
66
     */
67
    public function setSecure($name, $val)
68
    {
69
        $name = StringHelper::noFirstCamelCase($name);
70
        $this->{$name} = $val;
71
        return $this;
72
    }
73
}
74