Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| BaseOptions | |
0.00% |
0 / 9 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| toArray | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | namespace Ably\Models; |
| 3 | |
| 4 | use Ably\Log; |
| 5 | |
| 6 | /** |
| 7 | * Base class for models with options |
| 8 | * Provides automatic loading of options from array or an object |
| 9 | */ |
| 10 | abstract class BaseOptions { |
| 11 | public function __construct( $options = [] ) { |
| 12 | $class = get_class( $this ); |
| 13 | |
| 14 | foreach ($options as $key => $value) { |
| 15 | if (property_exists( $class, $key )) { |
| 16 | $this->$key = $value; |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | public function toArray() { |
| 22 | $properties = call_user_func('get_object_vars', $this); |
| 23 | foreach ($properties as $k => $v) { |
| 24 | if ($v === null) { |
| 25 | unset($properties[$k]); |
| 26 | } |
| 27 | } |
| 28 | return $properties; |
| 29 | } |
| 30 | } |