Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
PropGuard | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
__set | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Wikimedia\RemexHtml; |
4 | |
5 | use InvalidArgumentException; |
6 | |
7 | /** |
8 | * This is a statically configurable mechanism for preventing the setting of |
9 | * undeclared properties on objects. The point of it is to detect programmer |
10 | * errors. |
11 | */ |
12 | trait PropGuard { |
13 | public static $armed = true; |
14 | |
15 | public function __set( $name, $value ) { |
16 | if ( self::$armed ) { |
17 | throw new InvalidArgumentException( "Property \"$name\" on object of class " . get_class( $this ) . |
18 | " is undeclared" ); |
19 | } else { |
20 | $this->$name = $value; |
21 | } |
22 | } |
23 | } |