Completed
Push — master ( 357a0a...11ae27 )
by Thomas
02:19
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\NonDocumentTypeChildNode {
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 '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
}