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

Properties::blockReadOnlyProperties()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 12
loc 12
ccs 8
cts 8
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace FluentDOM\DOM\Node\ParentNode {
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 '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
}