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

AbstractContent   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 34.09 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 3
dl 15
loc 44
ccs 0
cts 15
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B setParameters() 15 15 5
A __toArray() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}