Completed
Push — master ( 625a76...357a0a )
by Thomas
02:47
created

Properties   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 68
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 68
loc 68
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\NonDocumentTypeChildNode {
4
5 View Code Duplication
  trait Properties {
1 ignored issue
show
Duplication introduced by
This class 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...
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 'nextElementSibling' :
16 2
        return $this->getNextElementSibling() !== NULL;
17 3
      case 'previousElementSibling' :
18 2
        return $this->getPreviousElementSibling() !== NULL;
19
      }
20 1
      return isset($this->$name);
21
    }
22
23
    /**
24
     * @param string $name
25
     * @return \DOMNode|NULL
26
     */
27 4
    public function __get(string $name) {
28
      switch ($name) {
29 4
      case 'nextElementSibling' :
30 1
        return $this->getNextElementSibling();
31 3
      case 'previousElementSibling' :
32 1
        return $this->getPreviousElementSibling();
33
      }
34 2
      return $this->$name;
35
    }
36
37
    /**
38
     * @param string $name
39
     * @param mixed $value
40
     * @throws \BadMethodCallException
41
     */
42 4
    public function __set(string $name, $value) {
43 4
      $this->blockReadOnlyProperties($name);
44 2
      $this->$name = $value;
45 2
    }
46
47
    /**
48
     * @param string $name
49
     * @throws \BadMethodCallException
50
     */
51 1
    public function __unset(string $name) {
52 1
      $this->blockReadOnlyProperties($name);
53 1
      unset($this->$name);
54 1
    }
55
56
    /**
57
     * @param string $name
58
     * @throws \BadMethodCallException
59
     */
60 5
    protected function blockReadOnlyProperties(string $name) {
61
      switch ($name) {
62 5
      case 'nextElementSibling' :
63 4
      case 'previousElementSibling' :
64 2
        throw new \BadMethodCallException(
65 2
          sprintf(
66 2
            'Can not write readonly property %s::$%s.',
67 2
            get_class($this), $name
68
          )
69
        );
70
      }
71 3
    }
72
  }
73
}