NovikovViktor/RequestLimitBundle

View on GitHub
Storage/Provider/MySQLProvider.php

Summary

Maintainability
A
0 mins
Test Coverage

Avoid unused parameters such as '$configuration'.
Open

    public function configure($configuration)
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phpmd

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

@throws type of get has undeclared type \Doctrine\DBAL\Driver\Exception (Did you mean class \Exception)
Open

    public function get($key)
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

Method \NW\RequestLimitBundle\Storage\Provider\MySQLProvider::remove is declared to return mixed but has no return value
Open

    public function remove($key)
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

Parameter $em has undeclared type \Doctrine\ORM\EntityManager
Open

    public function __construct(EntityManager $em)
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

@throws type of remove has undeclared type \Doctrine\DBAL\Driver\Exception (Did you mean class \Exception)
Open

    public function remove($key)
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

@throws type of fetchAllItems has undeclared type \Doctrine\DBAL\Driver\Exception (Did you mean class \Exception)
Open

    public function fetchAllItems()
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

@throws type of set has undeclared type \Doctrine\DBAL\Exception (Did you mean class \Exception)
Open

    public function set($key, $expiresAt)
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

@throws type of getItemsCount has undeclared type \Doctrine\DBAL\Exception (Did you mean class \Exception)
Open

    public function getItemsCount()
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

@throws type of fetchAllItems has undeclared type \Doctrine\DBAL\Exception (Did you mean class \Exception)
Open

    public function fetchAllItems()
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

Call to method getConnection from undeclared class \Doctrine\ORM\EntityManager
Open

        $connection = $this->_em->getConnection();
Severity: Critical
Found in Storage/Provider/MySQLProvider.php by phan

Property \NW\RequestLimitBundle\Storage\Provider\MySQLProvider->_em has undeclared type \Doctrine\ORM\EntityManager
Open

    private $_em;
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

Call to method getConnection from undeclared class \Doctrine\ORM\EntityManager
Open

        $connection = $this->_em->getConnection();
Severity: Critical
Found in Storage/Provider/MySQLProvider.php by phan

@throws type of remove has undeclared type \Doctrine\DBAL\Exception (Did you mean class \Exception)
Open

    public function remove($key)
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

@throws type of getItemsCount has undeclared type \Doctrine\DBAL\Driver\Exception (Did you mean class \Exception)
Open

    public function getItemsCount()
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

Call to method getConnection from undeclared class \Doctrine\ORM\EntityManager
Open

        $connection = $this->_em->getConnection();
Severity: Critical
Found in Storage/Provider/MySQLProvider.php by phan

@throws type of get has undeclared type \Doctrine\DBAL\Exception (Did you mean class \Exception)
Open

    public function get($key)
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

@throws type of set has undeclared type \Doctrine\DBAL\Driver\Exception (Did you mean class \Exception)
Open

    public function set($key, $expiresAt)
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

Method \NW\RequestLimitBundle\Storage\Provider\MySQLProvider::set is declared to return mixed but has no return value
Open

    public function set($key, $expiresAt)
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phan

Call to method getConnection from undeclared class \Doctrine\ORM\EntityManager
Open

        $connection = $this->_em->getConnection();
Severity: Critical
Found in Storage/Provider/MySQLProvider.php by phan

Call to method getConnection from undeclared class \Doctrine\ORM\EntityManager
Open

        $connection = $this->_em->getConnection();
Severity: Critical
Found in Storage/Provider/MySQLProvider.php by phan

Avoid using static access to class '\DateTime' in method 'get'.
Open

        $date = \DateTime::createFromFormat('Y-m-d H:i:s', $result[0]);
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Define a constant instead of duplicating this literal "item_key" 3 times.
Open

        $statement->bindValue('item_key', $key);
Severity: Critical
Found in Storage/Provider/MySQLProvider.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Avoid variables with short names like $em. Configured minimum length is 3.
Open

    public function __construct(EntityManager $em)
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phpmd

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

The property $_em is not named in camelCase.
Open

class MySQLProvider implements ProviderInterface
{
    /**
     * @var EntityManager $_em
     */
Severity: Minor
Found in Storage/Provider/MySQLProvider.php by phpmd

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

Property name "$_em" should not be prefixed with an underscore to indicate visibility
Open

    private $_em;

There are no issues that match your filters.

Category
Status