Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| ApieContextState | |
100.00% |
15 / 15 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createFromApieContext | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| logNextContext | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getContextChanges | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Apie\ApieBundle\DataCollector; |
| 4 | |
| 5 | use Apie\ApieBundle\DataCollector\FieldData\AbstractFieldData; |
| 6 | use Apie\ApieBundle\DataCollector\FieldData\ArrayType; |
| 7 | use Apie\Core\Context\ApieContext; |
| 8 | |
| 9 | final class ApieContextState |
| 10 | { |
| 11 | |
| 12 | /** |
| 13 | * @param array{0: class-string<object>|null, 1: AbstractFieldData}[] $states |
| 14 | */ |
| 15 | private function __construct( |
| 16 | private array $states = [] |
| 17 | ) { |
| 18 | } |
| 19 | public static function createFromApieContext(ApieContext $apieContext): ApieContextState |
| 20 | { |
| 21 | $context = (new \ReflectionProperty(ApieContext::class, 'context'))->getValue($apieContext); |
| 22 | $states = [[null, AbstractFieldData::createFromInput($context)]]; |
| 23 | return new self($states); |
| 24 | } |
| 25 | |
| 26 | public function logNextContext(string $className, ApieContext $apieContext): ApieContextState |
| 27 | { |
| 28 | $context = (new \ReflectionProperty(ApieContext::class, 'context'))->getValue($apieContext); |
| 29 | $this->states[] = [$className, AbstractFieldData::createFromInput($context)]; |
| 30 | return $this; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @return array<int, ContextChange> |
| 35 | */ |
| 36 | public function getContextChanges(): array |
| 37 | { |
| 38 | $previous = AbstractFieldData::createFromInput([]); |
| 39 | assert($previous instanceof ArrayType); |
| 40 | $diff = []; |
| 41 | foreach ($this->states as $state) { |
| 42 | assert($state[1] instanceof ArrayType); |
| 43 | $diff[] = $previous->getChanges($state[0] ?? '-', $state[1]); |
| 44 | $previous = $state[1]; |
| 45 | } |
| 46 | return $diff; |
| 47 | } |
| 48 | } |