Completed
Push — master ( 477ca5...2d5ed5 )
by Daniel
10s
created

ObjectView   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 72
Duplicated Lines 15.28 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A offsetGet() 11 11 2
A offsetExists() 0 4 1
A offsetSet() 0 6 1
A offsetUnset() 0 6 1
A current() 0 4 1
A key() 0 4 1
A next() 0 4 1
A rewind() 0 4 1
A valid() 0 4 1
A getTemplate() 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
declare(strict_types=1);
4
5
namespace Psi\Component\ContentType\Standard\View;
6
7
use Psi\Component\ContentType\View\ViewInterface;
8
9
class ObjectView implements ViewInterface, \ArrayAccess, \Iterator
10
{
11
    private $template;
12
    private $viewClosures;
13
14
    public function __construct(string $template, array $viewClosures)
15
    {
16
        $this->template = $template;
17
        $this->viewClosures = $viewClosures;
18
    }
19
20 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...
21
    {
22
        if (!isset($this->viewClosures[$name])) {
23
            throw new \InvalidArgumentException(sprintf(
24
                'Child view "%s" has not been set, known children: "%s"',
25
                $name, implode('", "', array_keys($this->viewClosures))
26
            ));
27
        }
28
29
        return $this->viewClosures[$name]();
30
    }
31
32
    public function offsetExists($name)
33
    {
34
        return isset($this->viewClosures[$name]);
35
    }
36
37
    public function offsetSet($name, $value)
38
    {
39
        throw new \BadMethodCallException(
40
            'Cannot modify an object view.'
41
        );
42
    }
43
44
    public function offsetUnset($name)
45
    {
46
        throw new \BadMethodCallException(
47
            'Cannot modify an object view.'
48
        );
49
    }
50
51
    public function current()
52
    {
53
        return $this->offsetGet(key($this->viewClosures));
54
    }
55
56
    public function key()
57
    {
58
        return key($this->viewClosures);
59
    }
60
61
    public function next()
62
    {
63
        return next($this->viewClosures);
64
    }
65
66
    public function rewind()
67
    {
68
        return reset($this->viewClosures);
69
    }
70
71
    public function valid()
72
    {
73
        return key($this->viewClosures) !== null;
74
    }
75
76
    public function getTemplate(): string
77
    {
78
        return $this->template;
79
    }
80
}
81