Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| ApieDataCollector | |
100.00% |
13 / 13 |
|
100.00% |
6 / 6 |
8 | |
100.00% |
1 / 1 |
| wrap | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| wrapContextBuilders | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| startLogApieContext | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| logApieContext | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getApieContextChanges | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| collect | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Apie\ApieBundle\DataCollector; |
| 4 | |
| 5 | use Apie\Core\Context\ApieContext; |
| 6 | use Apie\Core\ContextBuilders\ContextBuilderInterface; |
| 7 | use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector; |
| 8 | use Symfony\Component\HttpFoundation\Request; |
| 9 | use Symfony\Component\HttpFoundation\Response; |
| 10 | |
| 11 | class ApieDataCollector extends AbstractDataCollector |
| 12 | { |
| 13 | private ApieContextState $currentState; |
| 14 | |
| 15 | /** |
| 16 | * @param array<int, ContextBuilderInterface> $items |
| 17 | * @return \Generator<int, ContextBuilderInterface> |
| 18 | */ |
| 19 | private function wrap(array $items): \Generator |
| 20 | { |
| 21 | yield new StartLogContextBuilder($this); |
| 22 | foreach ($items as $item) { |
| 23 | yield $item; |
| 24 | yield new LogContextBuilder(get_class($item), $this); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @param array<int, ContextBuilderInterface> $contextBuilders |
| 30 | * @return array<int, ContextBuilderInterface> |
| 31 | */ |
| 32 | public function wrapContextBuilders(array $contextBuilders): array |
| 33 | { |
| 34 | return iterator_to_array($this->wrap($contextBuilders)); |
| 35 | } |
| 36 | |
| 37 | public function startLogApieContext(ApieContext $apieContext): void |
| 38 | { |
| 39 | $this->currentState = ApieContextState::createFromApieContext($apieContext); |
| 40 | $this->data['apie'][] = $this->currentState; |
| 41 | } |
| 42 | |
| 43 | public function logApieContext(string $className, ApieContext $apieContext): void |
| 44 | { |
| 45 | $this->currentState->logNextContext($className, $apieContext); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @return array<int, array<int, ContextChange>> |
| 50 | */ |
| 51 | public function getApieContextChanges(): array |
| 52 | { |
| 53 | $result = []; |
| 54 | foreach ($this->data['apie'] ?? [] as $contextList) { |
| 55 | $result[] = $contextList->getContextChanges(); |
| 56 | } |
| 57 | return $result; |
| 58 | } |
| 59 | public function collect(Request $request, Response $response, ?\Throwable $exception = null): void |
| 60 | { |
| 61 | unset($this->currentState); |
| 62 | } |
| 63 | } |