Completed
Push — master ( 357a0a...11ae27 )
by Thomas
02:19
created

Properties   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 66
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 66
loc 66
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0
wmc 11
lcom 0
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __isset() 9 9 3
A __get() 9 9 3
A __set() 4 4 1
A __unset() 4 4 1
A blockReadOnlyProperties() 12 12 3

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 FluentDOM\DOM\Node\ParentNode {
4
5 View Code Duplication
  trait Properties {
6
7
    use Implementation;
8
9
    /**
10
     * @param string $name
11
     * @return bool
12
     */
13 5
    public function __isset(string $name) {
14
      switch ($name) {
15 5
      case 'firstElementChild' :
16 2
        return $this->getFirstElementChild() !== NULL;
17 3
      case 'lastElementChild' :
18 2
        return $this->getLastElementChild() !== NULL;
19
      }
20 1
      return isset($this->$name);
21
    }
22
23
    /**
24
     * @param string $name
25
     * @return \FluentDOM\DOM\Element|NULL
26
     */
27 9
    public function __get(string $name) {
28
      switch ($name) {
29 9
      case 'firstElementChild' :
30 4
        return $this->getFirstElementChild();
31 5
      case 'lastElementChild' :
32 4
        return $this->getLastElementChild();
33
      }
34 1
      return $this->$name;
35
    }
36
37
    /**
38
     * @param string $name
39
     * @param $value
40
     */
41 3
    public function __set(string $name, $value) {
42 3
      $this->blockReadOnlyProperties($name);
43 1
      $this->$name = $value;
44 1
    }
45
46
    /**
47
     * @param string $name
48
     */
49 1
    public function __unset(string $name) {
50 1
      $this->blockReadOnlyProperties($name);
51 1
      unset($this->$name);
52 1
    }
53
54
    /**
55
     * @param string $name
56
     * @throws \BadMethodCallException
57
     */
58 4
    protected function blockReadOnlyProperties(string $name) {
59
      switch ($name) {
60 4
      case 'firstElementChild' :
61 3
      case 'lastElementChild' :
62 2
        throw new \BadMethodCallException(
63 2
          sprintf(
64 2
            'Can not write readonly property %s::$%s.',
65 2
            get_class($this), $name
66
          )
67
        );
68
      }
69 2
    }
70
  }
71
72
}