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 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\RemexHtml; |
| 5 | |
| 6 | use InvalidArgumentException; |
| 7 | |
| 8 | /** |
| 9 | * This is a statically configurable mechanism for preventing the setting of |
| 10 | * undeclared properties on objects. The point of it is to detect programmer |
| 11 | * errors. |
| 12 | */ |
| 13 | trait PropGuard { |
| 14 | /** @var bool */ |
| 15 | public static $armed = true; |
| 16 | |
| 17 | public function __set( $name, $value ) { |
| 18 | if ( self::$armed ) { |
| 19 | throw new InvalidArgumentException( "Property \"$name\" on object of class " . get_class( $this ) . |
| 20 | " is undeclared" ); |
| 21 | } else { |
| 22 | $this->$name = $value; |
| 23 | } |
| 24 | } |
| 25 | } |