Completed
Pull Request — master (#36)
by Daniel
03:57
created

View   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 77
Duplicated Lines 15.58 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 0
dl 12
loc 77
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTemplate() 0 4 1
A offsetGet() 11 11 2
A offsetExists() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A getIterator() 0 4 1
A count() 0 4 1
A setValue() 0 4 1
A getValue() 0 4 1
A __toString() 0 8 2
A getChildren() 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 Psi\Component\ContentType\View;
4
5
class View implements \ArrayAccess, \IteratorAggregate, \Countable
6
{
7
    private $children = [];
8
    private $value;
9
    private $template;
10
11
    public function __construct(string $template = null)
12
    {
13
        $this->template = $template;
14
    }
15
16
    public function getTemplate()
17
    {
18
        return $this->template;
19
    }
20
21 View Code Duplication
    public function offsetGet($name)
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...
22
    {
23
        if (!isset($this->children[$name])) {
24
            throw new \InvalidArgumentException(sprintf(
25
                'View value "%s" has not been set, available children: "%s"',
26
                $name, implode('", "', array_keys($this->children))
27
            ));
28
        }
29
30
        return $this->children[$name];
31
    }
32
33
    public function offsetExists($name)
34
    {
35
        return isset($this->children[$name]);
36
    }
37
38
    public function offsetSet($name, $value)
39
    {
40
        $this->children[$name] = $value;
41
    }
42
43
    public function offsetUnset($name)
44
    {
45
        unset($this->children[$name]);
46
    }
47
48
    public function getIterator()
49
    {
50
        return new \ArrayIterator($this->children);
51
    }
52
53
    public function count()
54
    {
55
        return count($this->children);
56
    }
57
58
    public function setValue($value)
59
    {
60
        $this->value = $value;
61
    }
62
63
    public function getValue()
64
    {
65
        return $this->value;
66
    }
67
68
    public function getChildren()
69
    {
70
        return $this->children;
71
    }
72
73
    public function __toString()
74
    {
75
        if (isset($this->value)) {
76
            return $this->value;
77
        }
78
79
        return '<no primary value>';
80
    }
81
}
82