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

TProperty   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 28
Duplicated Lines 57.14 %

Importance

Changes 0
Metric Value
dl 16
loc 28
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 4 5 2
A __isset() 4 5 2
A __unset() 4 5 2
A __get() 4 5 2

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
/**
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
}