PropertyAbstract   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 56
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getProperties() 0 4 1
A setProperties() 0 10 2
A addProperty() 0 9 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Crossjoin\Browscap\PropertyFilter;
5
6
/**
7
 * Class PropertyAbstract
8
 *
9
 * @package Crossjoin\Browscap\PropertyFilter
10
 * @author Christoph Ziegenberg <[email protected]>
11
 * @link https://github.com/crossjoin/browscap
12
 */
13
abstract class PropertyAbstract implements PropertyFilterInterface
14
{
15
    /**
16
     * @var array
17
     */
18
    protected $properties = [];
19
20
    /**
21
     * Allowed constructor.
22
     *
23
     * @param array $properties
24
     */
25
    public function __construct(array $properties = [])
26
    {
27
        $this->setProperties($properties);
28
    }
29
30
    /**
31
     * @return array
32
     */
33
    public function getProperties() : array
34
    {
35
        return $this->properties;
36
    }
37
38
    /**
39
     * @param array $properties
40
     *
41
     * @return PropertyAbstract
42
     */
43
    public function setProperties(array $properties) : self
44
    {
45
        $this->properties = [];
46
47
        foreach ($properties as $property) {
48
            $this->addProperty($property);
49
        }
50
51
        return $this;
52
    }
53
54
    /**
55
     * @param string $property
56
     *
57
     * @return PropertyAbstract
58
     */
59
    public function addProperty(string $property) : self
60
    {
61
        $property = strtolower($property);
62
        if (!in_array($property, $this->properties, true)) {
63
            $this->properties[] = $property;
64
        }
65
66
        return $this;
67
    }
68
}
69