Passed
Branch main (b6a268)
by Iain
04:11
created

getConvertCountOverallStatsOfSessionExperimentAndResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Humbly Arrogant Ltd 2020-2022.
7
 *
8
 * Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
9
 *
10
 * Change Date: TBD ( 3 years after 2.0.0 release )
11
 *
12
 * On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
13
 */
14
15
namespace Parthenon\AbTesting\Repository\Timescale;
16
17
use Doctrine\DBAL\Connection;
18
use Parthenon\AbTesting\Repository\StatsRepositoryInterface;
19
20
class StatsRepository implements StatsRepositoryInterface
21
{
22
    private Connection $connection;
23
24
    public function __construct(Connection $connection)
25
    {
26
        $this->connection = $connection;
27
    }
28
29
    public function getCountOverallStatsOfExperiment(string $decisionId, string $decisionOutput): int
30
    {
31
        $statement = $this->connection->prepare('SELECT count(*) FROM ab_experiment_log WHERE decision_string_id = :decisionId AND decision_output = :decision');
32
        $statement->bindValue(':decisionId', $decisionId);
33
        $statement->bindValue(':decision', $decisionOutput);
34
        $result = $statement->executeQuery();
35
36
        return $result->fetchOne();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result->fetchOne() could return the type false which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
37
    }
38
39
    public function getConvertCountOverallStatsOfSessionExperimentAndResult(string $decisionId, string $decisionOutput, string $result): int
40
    {
41
        $statement = $this->connection->prepare('SELECT count(*) FROM ab_result_log WHERE result_string_id = :resultLog AND session_id IN (SELECT session_id FROM ab_experiment_log WHERE decision_string_id = :decisionId AND decision_output = :decision)');
42
43
        $statement->bindValue(':decisionId', $decisionId);
44
        $statement->bindValue(':decision', $decisionOutput);
45
        $statement->bindValue(':resultLog', $result);
46
        $result = $statement->executeQuery();
47
48
        return $result->fetchOne();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result->fetchOne() could return the type false which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
49
    }
50
51
    public function getConvertCountOverallStatsOfUserExperimentAndResult(string $decisionId, string $decisionOutput, string $result): int
52
    {
53
        $statement = $this->connection->prepare('SELECT count(*) FROM ab_result_log WHERE result_string_id = :resultLog AND user_id IN (select abas.user_id from ab_experiment_log ael inner join ab_sessions abas on abas.id = ael.session_id  WHERE ael.decision_string_id = :decisionId AND ael.decision_output = :decision)');
54
55
        $statement->bindValue(':decisionId', $decisionId);
56
        $statement->bindValue(':decision', $decisionOutput);
57
        $statement->bindValue(':resultLog', $result);
58
        $result = $statement->executeQuery();
59
60
        return $result->fetchOne();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result->fetchOne() could return the type false which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
61
    }
62
}
63