NamedList::contains()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * PHP version 5.4 and 8
5
 *
6
 * @category  Base
7
 * @package   Payever\Core
8
 * @author    payever GmbH <[email protected]>
9
 * @copyright 2017-2021 payever GmbH
10
 * @license   MIT <https://opensource.org/licenses/MIT>
11
 * @link      https://docs.payever.org/shopsystems/api/getting-started
12
 */
13
14
namespace Payever\ExternalIntegration\Core\Base;
15
16
/**
17
 * Class represents Named List
18
 */
19
class NamedList
20
{
21
    /** @var array $list */
22
    protected $list = [];
23
24
    /**
25
     * Adds an item to the list
26
     *
27
     * @param string $name
28
     * @param mixed  $value
29
     *
30
     * @return $this
31
     */
32
    public function add($name, $value = null)
33
    {
34
        $this->list[$name] = $value;
35
36
        return $this;
37
    }
38
39
    /**
40
     * Adds items to the list
41
     *
42
     * @param array $array
43
     *
44
     * @return $this
45
     */
46
    public function addAll(array $array)
47
    {
48
        $this->list = array_merge($this->list, $array);
49
50
        return $this;
51
    }
52
53
    /**
54
     * Clears the list
55
     *
56
     * @return $this
57
     */
58
    public function clear()
59
    {
60
        $this->list = [];
61
62
        return $this;
63
    }
64
65
    /**
66
     * Removes an item from the list
67
     *
68
     * @param string $name
69
     *
70
     * @return $this
71
     */
72
    public function remove($name)
73
    {
74
        unset($this->list[$name]);
75
76
        return $this;
77
    }
78
79
    /**
80
     * Returns list size
81
     *
82
     * @return int
83
     */
84
    public function count()
85
    {
86
        return count($this->list);
87
    }
88
89
    /**
90
     * Returns an item with the name from the list
91
     *
92
     * @param string $name
93
     *
94
     * @return array|bool|object
95
     */
96
    public function get($name)
97
    {
98
        if (isset($this->list[$name])) {
99
            return $this->list[$name];
100
        }
101
102
        return false;
103
    }
104
105
    /**
106
     * Returns the list
107
     *
108
     * @return array
109
     */
110
    public function getAll()
111
    {
112
        return $this->list;
113
    }
114
115
    /**
116
     * Checks if the item exists
117
     *
118
     * @param object $value
119
     *
120
     * @return bool
121
     */
122
    public function contains($value)
123
    {
124
        if (in_array($value, array_values($this->list), true)) {
125
            return true;
126
        }
127
128
        return false;
129
    }
130
}
131