Passed
Push — master ( 912bd1...0b1a33 )
by Marcel
06:53
created

ThresholdMapper::getSevOneThresholdsByDataset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 9.9666
1
<?php
2
/**
3
 * Analytics
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the LICENSE.md file.
7
 *
8
 * @author Marcel Scherello <[email protected]>
9
 * @copyright 2021 Marcel Scherello
10
 */
11
12
namespace OCA\Analytics\Db;
13
14
use OCP\IDBConnection;
15
use OCP\IL10N;
16
use Psr\Log\LoggerInterface;
17
18
class ThresholdMapper
19
{
20
    private $userId;
21
    private $l10n;
22
    private $db;
23
    private $logger;
24
    const TABLE_NAME = 'analytics_threshold';
25
26
    public function __construct(
27
        $userId,
28
        IL10N $l10n,
29
        IDBConnection $db,
30
        LoggerInterface $logger
31
    )
32
    {
33
        $this->userId = $userId;
34
        $this->l10n = $l10n;
35
        $this->db = $db;
36
        $this->logger = $logger;
37
        self::TABLE_NAME;
38
    }
39
40
    public function createThreshold($reportId, $dimension1, $value, $option, $severity)
41
    {
42
        $sql = $this->db->getQueryBuilder();
43
        $sql->insert(self::TABLE_NAME)
44
            ->values([
45
                'user_id' => $sql->createNamedParameter($this->userId),
46
                'report' => $sql->createNamedParameter($reportId),
47
                'dimension1' => $sql->createNamedParameter($dimension1),
48
                'value' => $sql->createNamedParameter($value),
49
                'option' => $sql->createNamedParameter($option),
50
                'severity' => $sql->createNamedParameter($severity),
51
            ]);
52
        $sql->execute();
1 ignored issue
show
Deprecated Code introduced by
The function OCP\DB\QueryBuilder\IQueryBuilder::execute() has been deprecated: 22.0.0 Use executeQuery or executeStatement ( Ignorable by Annotation )

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

52
        /** @scrutinizer ignore-deprecated */ $sql->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...
53
        return (int)$sql->getLastInsertId();
54
    }
55
56
    public function getThresholdsByReport($reportId)
57
    {
58
        $sql = $this->db->getQueryBuilder();
59
        $sql->from(self::TABLE_NAME)
60
            ->select('id')
61
            ->addSelect('dimension1')
62
            ->addSelect('dimension2')
63
            ->addSelect('value')
64
            ->addSelect('option')
65
            ->addSelect('severity')
66
            ->where($sql->expr()->eq('report', $sql->createNamedParameter($reportId)));
67
        $statement = $sql->execute();
1 ignored issue
show
Deprecated Code introduced by
The function OCP\DB\QueryBuilder\IQueryBuilder::execute() has been deprecated: 22.0.0 Use executeQuery or executeStatement ( Ignorable by Annotation )

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

67
        $statement = /** @scrutinizer ignore-deprecated */ $sql->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...
68
        $result = $statement->fetchAll();
69
        $statement->closeCursor();
70
        return $result;
71
    }
72
73
    public function getSevOneThresholdsByReport($reportId)
74
    {
75
        $sql = $this->db->getQueryBuilder();
76
        $sql->from(self::TABLE_NAME)
77
            ->select('*')
78
            ->where($sql->expr()->eq('report', $sql->createNamedParameter($reportId)))
79
            ->andWhere($sql->expr()->eq('severity', $sql->createNamedParameter('1')));
80
        $statement = $sql->execute();
1 ignored issue
show
Deprecated Code introduced by
The function OCP\DB\QueryBuilder\IQueryBuilder::execute() has been deprecated: 22.0.0 Use executeQuery or executeStatement ( Ignorable by Annotation )

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

80
        $statement = /** @scrutinizer ignore-deprecated */ $sql->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...
81
        $result = $statement->fetchAll();
82
        $statement->closeCursor();
83
        return $result;
84
    }
85
86
    public function deleteThreshold($thresholdId)
87
    {
88
        $sql = $this->db->getQueryBuilder();
89
        $sql->delete(self::TABLE_NAME)
90
            ->where($sql->expr()->eq('id', $sql->createNamedParameter($thresholdId)))
91
            ->andWhere($sql->expr()->eq('user_id', $sql->createNamedParameter($this->userId)));
92
        $sql->execute();
1 ignored issue
show
Deprecated Code introduced by
The function OCP\DB\QueryBuilder\IQueryBuilder::execute() has been deprecated: 22.0.0 Use executeQuery or executeStatement ( Ignorable by Annotation )

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

92
        /** @scrutinizer ignore-deprecated */ $sql->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...
93
        return true;
94
    }
95
}