MySQLProvider::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
rs 10
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->prepare('SELECT expires_at FROM nv_request_limit_items WHERE item_key = :item_key');
36
        $statement->bindValue('item_key', $key);
37
        $statement->execute();
38
        $result     = $statement->fetchAll(\PDO::FETCH_COLUMN);
39
        $connection->close();
40
        $date       = \DateTime::createFromFormat('Y-m-d H:i:s', $result[0]);
41
42
        return $date->getTimestamp();
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function set($key, $expiresAt)
49
    {
50
        $connection = $this->_em->getConnection();
51
        $statement  = $connection->prepare(
52
            'INSERT INTO nv_request_limit_items (item_key, expires_at) VALUES (:item_key, :expires_at);'
53
        );
54
        $statement->bindValue('item_key', $key);
55
        $statement->bindValue('expires_at', date('Y-m-d H:i:s',$expiresAt));
56
        $statement->execute();
57
        $connection->close();
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function remove($key)
64
    {
65
        $connection = $this->_em->getConnection();
66
        $statement  = $connection->prepare('DELETE FROM nv_request_limit_items WHERE item_key = :item_key');
67
        $statement->bindValue('item_key', $key);
68
        $statement->execute();
69
        $connection->close();
70
    }
71
72
    /**
73
     * @return array
74
     */
75 View Code Duplication
    public function fetchAllItems()
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...
76
    {
77
        $connection = $this->_em->getConnection();
78
        $statement  = $connection->prepare('SELECT * FROM nv_request_limit_items');
79
        $statement->execute();
80
        $result     = $statement->fetchAll();
81
        $connection->close();
82
83
        return $result;
84
    }
85
86
    /**
87
     * @return int
88
     */
89 View Code Duplication
    public function getItemsCount()
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...
90
    {
91
        $connection = $this->_em->getConnection();
92
        $statement  = $connection->prepare('SELECT COUNT(*) FROM nv_request_limit_items');
93
        $statement->execute();
94
        $result     = $statement->fetchColumn(0);
95
        $connection->close();
96
97
        return $result;
98
    }
99
}
100