Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| BorshSerializable | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
3.02 | |
0.00% |
0 / 1 |
| __get | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
3.02 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Attestto\SolanaPhpSdk\Borsh; |
| 4 | use ReflectionClass; |
| 5 | |
| 6 | trait BorshSerializable |
| 7 | { |
| 8 | |
| 9 | |
| 10 | /** |
| 11 | * Magic getter to retrieve dynamically set properties. |
| 12 | * Note, changed from dynamic properties make use of an Array due to Dynamic properties being deprecated. |
| 13 | * @param string $name |
| 14 | * |
| 15 | * @return mixed|null |
| 16 | */ |
| 17 | public function __get(string $name) |
| 18 | { |
| 19 | // Check if the property exists in the dynamic properties |
| 20 | if (array_key_exists($name, $this->fields)) { |
| 21 | return $this->fields[$name]; |
| 22 | } |
| 23 | |
| 24 | // Check if the property exists as a private property |
| 25 | if ($this->isPrivateProperty($name)) { |
| 26 | // Use reflection to access the private property |
| 27 | $reflectionClass = new ReflectionClass($this); |
| 28 | $property = $reflectionClass->getProperty($name); |
| 29 | $property->setAccessible(true); |
| 30 | return $property->getValue($this); |
| 31 | } |
| 32 | |
| 33 | // Property not found |
| 34 | return null; |
| 35 | } |
| 36 | } |