Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
61.54% covered (warning)
61.54%
8 / 13
66.67% covered (warning)
66.67%
4 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApieDataCollector
61.54% covered (warning)
61.54%
8 / 13
66.67% covered (warning)
66.67%
4 / 6
11.64
0.00% covered (danger)
0.00%
0 / 1
 wrap
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 wrapContextBuilders
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 startLogApieContext
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 logApieContext
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getApieContextChanges
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 collect
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Apie\ApieBundle\DataCollector;
4
5use Apie\Core\Context\ApieContext;
6use Apie\Core\ContextBuilders\ContextBuilderInterface;
7use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
8use Symfony\Component\HttpFoundation\Request;
9use Symfony\Component\HttpFoundation\Response;
10
11class 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}