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

ExperimentLogRepository::deleteAllForSession()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
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\ExperimentLogRepositoryInterface;
19
use Ramsey\Uuid\Uuid;
20
use Ramsey\Uuid\UuidInterface;
21
22
class ExperimentLogRepository implements ExperimentLogRepositoryInterface
23
{
24
    private Connection $connection;
25
26
    public function __construct(Connection $connection)
27
    {
28
        $this->connection = $connection;
29
    }
30
31
    public function saveDecision(UuidInterface $sessionId, string $experimentName, string $decisionOutput): void
32
    {
33
        $uuid = Uuid::uuid4();
34
        $now = new \DateTime('now');
35
        $query = $this->connection->prepare('INSERT INTO ab_experiment_log (id, session_id, decision_string_id, decision_output, created_at) VALUES (:id, :session_id, :decision_string_id, :decision_output, :created_at)');
36
        $query->bindValue(':id', (string) $uuid);
37
        $query->bindValue(':session_id', (string) $sessionId);
38
        $query->bindValue(':decision_string_id', (string) $experimentName);
39
        $query->bindValue(':decision_output', (string) $decisionOutput);
40
        $query->bindValue(':created_at', $now->format('Y-m-d H:i:s'));
41
        $query->execute();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Statement::execute() has been deprecated: Statement::execute() is deprecated, use Statement::executeQuery() or executeStatement() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

41
        /** @scrutinizer ignore-deprecated */ $query->execute();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
42
    }
43
44
    public function deleteAllForSession(UuidInterface $sessionId): void
45
    {
46
        $statement = $this->connection->prepare('DELETE FROM ab_experiment_log WHERE session_id = :session_id');
47
        $statement->bindValue(':session_id', (string) $sessionId);
48
        $statement->execute();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Statement::execute() has been deprecated: Statement::execute() is deprecated, use Statement::executeQuery() or executeStatement() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

48
        /** @scrutinizer ignore-deprecated */ $statement->execute();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
49
    }
50
}
51