Test Setup Failed
Push — master ( 1b5216...e31da6 )
by Gabriel
12:30
created

AbstractContent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Sportic\Timing\RaceTecClient\Content;
4
5
use ArrayAccess;
6
use Sportic\Timing\RaceTecClient\Content\Traits\AccessMethodsTrait;
7
use Sportic\Timing\RaceTecClient\Content\Traits\ArrayAccessTrait;
8
use Sportic\Timing\RaceTecClient\Helper;
9
10
/**
11
 * Class AbstractContent
12
 * @package Sportic\Timing\RaceTecClient\Content
13
 */
14
abstract class AbstractContent implements ArrayAccess
15
{
16
    use ArrayAccessTrait, AccessMethodsTrait;
17
    protected $data = [];
18
19
    /**
20
     * AbstractContent constructor.
21
     *
22
     * @param $parameters
23
     */
24
    public function __construct($parameters = [])
25
    {
26
        $this->setParameters($parameters);
27
28
    }
29
30
    /**
31
     * @param array $parameters
32
     */
33 View Code Duplication
    public function setParameters($parameters)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        if (is_array($parameters)) {
36
            foreach ($parameters as $name => $value) {
37
                $method = 'set' . ucfirst(Helper::camelCase($name));
38
                if (method_exists($this, $method)) {
39
                    $this->$method($value);
40
                } elseif (property_exists($this, $name)) {
41
                    $this->{$name} = $value;
42
                } else {
43
                    $this->data[$name] = $value;
44
                }
45
            }
46
        }
47
    }
48
49
    /**
50
     * @return mixed
51
     */
52
    public function __toArray()
53
    {
54
        return Helper::objectToArray($this->data);
55
    }
56
57
}