Passed
Push — master ( 98c0f4...e86dee )
by Filippo
03:29
created

TProperty::__get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 4
Ratio 80 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 4
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @file TProperty.php
5
 * @brief This file contains the TProperty trait.
6
 * @details
7
 * @author Filippo F. Fadda
8
 */
9
10
11
//! Extensions and traits
12
namespace Meta\Extension;
13
14
15
/**
16
 * @brief This trait can be used by a class to emulate the C# properties.
17
 */
18
trait TProperty {
19
20
  public function __get($name) {
21 View Code Duplication
    if (method_exists($this, ($method = 'get'.ucfirst($name))))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
22
      return $this->$method();
23
    else
24
      throw new \BadMethodCallException("Method $method is not implemented for property $name.");
25
  }
26
27
  public function __isset($name) {
28 View Code Duplication
    if (method_exists($this, ($method = 'isset'.ucfirst($name))))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
29
      return $this->$method();
30
    else
31
      throw new \BadMethodCallException("Method $method is not implemented for property $name.");
32
  }
33
34
  public function __set($name, $value) {
35 View Code Duplication
    if (method_exists($this, ($method = 'set'.ucfirst($name))))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
36
      $this->$method($value);
37
    else
38
      throw new \BadMethodCallException("Method $method is not implemented for property $name.");
39
  }
40
41
  public function __unset($name) {
42 View Code Duplication
    if (method_exists($this, ($method = 'unset'.ucfirst($name))))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
43
      $this->$method();
44
    else
45
      throw new \BadMethodCallException("Method $method is not implemented for property $name.");
46
  }
47
48
}