TProperty   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 0 5 2
A __isset() 0 5 2
A __unset() 0 5 2
A __get() 0 5 2
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
    if (method_exists($this, ($method = 'get'.ucfirst($name))))
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
    if (method_exists($this, ($method = 'isset'.ucfirst($name))))
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
    if (method_exists($this, ($method = 'set'.ucfirst($name))))
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
    if (method_exists($this, ($method = 'unset'.ucfirst($name))))
43
      $this->$method();
44
    else
45
      throw new \BadMethodCallException("Method $method is not implemented for property $name.");
46
  }
47
48
}