Completed
Push — master ( 5c8a13...04755b )
by Novikov
01:34
created

MySQLProvider::getItemsCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace NV\RequestLimitBundle\Storage\Provider;
4
5
use Doctrine\ORM\EntityManager;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
class MySQLProvider implements ProviderInterface
8
{
9
    /**
10
     * @var EntityManager $_em
11
     */
12
    private $_em;
13
14
    /**
15
     * @param EntityManager $em
16
     */
17
    public function __construct($em)
18
    {
19
        $this->_em = $em;
20
    }
21
22
    /**
23
     * @param $configuration
24
     */
25
    public function configure($configuration)
0 ignored issues
show
Unused Code introduced by
The parameter $configuration is not used and could be removed. ( Ignorable by Annotation )

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

25
    public function configure(/** @scrutinizer ignore-unused */ $configuration)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function get($key)
33
    {
34
        $connection = $this->_em->getConnection();
35
        $statement  = $connection->exec(
36
    'SELECT expires_at FROM nv_request_limit_items
37
               WHERE item_key = :item_key'
38
        );
39
        $statement->bindParam('item_key', $key);
40
        $result = $statement->fetchAll(\PDO::FETCH_COLUMN);
41
        $connection->close();
42
43
        return $result;
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49 View Code Duplication
    public function set($key, $expiresAt)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        $connection = $this->_em->getConnection();
52
        $statement  = $connection->exec(
53
            'INSERT INTO nv_request_limit_items (item_key, expires_at) VALUES item_key = :item_key, expires_at = :expires_at'
54
        );
55
        $statement->bindParam('item_key', $key);
56
        $statement->bindParam('expires_at', $key);
57
        $connection->close();
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63 View Code Duplication
    public function remove($key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $connection = $this->_em->getConnection();
66
        $statement  = $connection->exec('DELETE FROM nv_request_limit_items WHERE item_key = :item_key');
67
        $statement->bindParam('item_key', $key);
68
        $connection->close();
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    public function fetchAllItems()
75
    {
76
        $connection = $this->_em->getConnection();
77
        $result     = $connection->executeQuery('SELECT * FROM nv_request_limit_items')->fetchAll();
78
        $connection->close();
79
80
        return $result;
81
    }
82
83
    /**
84
     * @return int
85
     */
86
    public function getItemsCount()
87
    {
88
        $connection = $this->_em->getConnection();
89
        $result     = $connection->executeQuery('SELECT COUNT(*) FROM nv_request_limit_items')->fetchColumn(0);
90
        $connection->close();
91
92
        return $result;
93
    }
94
}
95