Passed
Push — master ( 0d32dd...265c4a )
by Marcel
02:32
created

ThresholdMapper::createThreshold()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 2
b 0
f 0
nc 1
nop 5
dl 0
loc 15
rs 9.8666
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 Psr\Log\LoggerInterface;
16
17
class ThresholdMapper
18
{
19
    private $userId;
20
    private $db;
21
    private $logger;
22
    const TABLE_NAME = 'analytics_threshold';
23
24
    public function __construct(
25
        $userId,
26
        IDBConnection $db,
27
        LoggerInterface $logger
28
    )
29
    {
30
        $this->userId = $userId;
31
        $this->db = $db;
32
        $this->logger = $logger;
33
    }
34
35
    public function create($reportId, $dimension1, $value, $option, $severity)
36
    {
37
        $sql = $this->db->getQueryBuilder();
38
        $sql->insert(self::TABLE_NAME)
39
            ->values([
40
                'user_id' => $sql->createNamedParameter($this->userId),
41
                'report' => $sql->createNamedParameter($reportId),
42
                'dimension1' => $sql->createNamedParameter($dimension1),
43
                'value' => $sql->createNamedParameter($value),
44
                'option' => $sql->createNamedParameter($option),
45
                'severity' => $sql->createNamedParameter($severity),
46
                'dataset' => $sql->createNamedParameter($reportId),
47
            ]);
48
        $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

48
        /** @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...
49
        return (int)$sql->getLastInsertId();
50
    }
51
52
    public function getThresholdsByReport($reportId)
53
    {
54
        $sql = $this->db->getQueryBuilder();
55
        $sql->from(self::TABLE_NAME)
56
            ->select('id')
57
            ->addSelect('dimension1')
58
            ->addSelect('dimension2')
59
            ->addSelect('value')
60
            ->addSelect('option')
61
            ->addSelect('severity')
62
            ->where($sql->expr()->eq('report', $sql->createNamedParameter($reportId)));
63
        $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

63
        $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...
64
        $result = $statement->fetchAll();
65
        $statement->closeCursor();
66
        return $result;
67
    }
68
69
    public function getSevOneThresholdsByReport($reportId)
70
    {
71
        $sql = $this->db->getQueryBuilder();
72
        $sql->from(self::TABLE_NAME)
73
            ->select('*')
74
            ->where($sql->expr()->eq('report', $sql->createNamedParameter($reportId)))
75
            ->andWhere($sql->expr()->eq('severity', $sql->createNamedParameter('1')));
76
        $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

76
        $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...
77
        $result = $statement->fetchAll();
78
        $statement->closeCursor();
79
        return $result;
80
    }
81
82
    public function deleteThreshold($thresholdId)
83
    {
84
        $sql = $this->db->getQueryBuilder();
85
        $sql->delete(self::TABLE_NAME)
86
            ->where($sql->expr()->eq('id', $sql->createNamedParameter($thresholdId)))
87
            ->andWhere($sql->expr()->eq('user_id', $sql->createNamedParameter($this->userId)));
88
        $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

88
        /** @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...
89
        return true;
90
    }
91
92
    public function deleteThresholdByReport($reportId)
93
    {
94
        $sql = $this->db->getQueryBuilder();
95
        $sql->delete(self::TABLE_NAME)
96
            ->where($sql->expr()->eq('report', $sql->createNamedParameter($reportId)))
97
            ->andWhere($sql->expr()->eq('user_id', $sql->createNamedParameter($this->userId)));
98
        $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

98
        /** @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...
99
        return true;
100
    }
101
}