Completed
Push — master ( d8d395...66c173 )
by Walter
9s
created

DataCollector::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.5786

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
ccs 1
cts 6
cp 0.1666
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
crap 1.5786
1
<?php
2
3
namespace PhpAb\Analytics\DB;
4
5
use PhpAb\Event\SubscriberInterface;
6
use PhpAb\Test\TestInterface;
7
use PhpAb\Variant\VariantInterface;
8
use Webmozart\Assert\Assert;
9
10
class DataCollector implements SubscriberInterface
11
{
12
    /**
13
     * @var array Test identifiers and variation indexes
14
     */
15
    private $participations = [];
16
17
    /**
18
     * @inheritDoc
19
     */
20
    public function getSubscribedEvents()
21
    {
22
        return [
23
            'phpab.participation.variant_run' => function ($options) {
24
25
                /** @var TestInterface $test */
26
                $test = $options[1]->getTest();
27
28
                /** @var VariantInterface $chosenVariant */
29
                $chosenVariant = $options[2];
30
31
                // Call the add method
32
                $this->addParticipation($test->getIdentifier(), $chosenVariant->getIdentifier());
33
            }
34 1
        ];
35
    }
36
37
    /**
38
     * @param string $testIdentifier
39
     * @param string $variationIdentifier
40
     * @throws InvalidArgumentException
41
     *
42
     * @return void
43
     */
44 1
    public function addParticipation($testIdentifier, $variationIdentifier)
45
    {
46 1
        Assert::string($testIdentifier, 'Test identifier must be a string');
47
48 1
        Assert::string($variationIdentifier, 'Variation name must be a string');
49
50 1
        $this->participations[$testIdentifier] = $variationIdentifier;
51 1
    }
52
53
    /**
54
     * @return array
55
     */
56 1
    public function getTestsData()
57
    {
58 1
        return $this->participations;
59
    }
60
}
61