NovikovViktor/RequestLimitBundle

View on GitHub

Showing 102 of 102 total issues

The variable $_memcached is not named in camelCase.
Open

    public function configure($configuration)
    {
        $memcachedHost = $configuration['server'];
        $memcachedPort = $configuration['port'];
        $_memcached = new Memcached();

CamelCaseVariableName

Since: 0.2

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

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $_memcached is not named in camelCase.
Open

    public function configure($configuration)
    {
        $memcachedHost = $configuration['server'];
        $memcachedPort = $configuration['port'];
        $_memcached = new Memcached();

CamelCaseVariableName

Since: 0.2

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

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

Class extends undeclared class \Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
Open

class MySQLProviderSetupCommand extends ContainerAwareCommand
Severity: Critical
Found in Command/MySQLProviderSetupCommand.php by phan

Call to method setParameter from undeclared class \Symfony\Component\DependencyInjection\ContainerBuilder
Open

        $container->setParameter('nw_request_limit.restriction_time', $restrictionTime);

Class extends undeclared class \Symfony\Component\HttpKernel\Bundle\Bundle
Open

class NWRequestLimitBundle extends Bundle
Severity: Critical
Found in NWRequestLimitBundle.php by phan

Call to method set from undeclared class \Memcached
Open

        return $this->_memcached->set($key, $expiresAt, 60 * 60 * 24 * 30);
Severity: Critical
Found in Storage/Provider/MemcachedProvider.php by phan

@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

Call to undeclared method \NW\RequestLimitBundle\Tests\Unit\Utils\RestrictorTest::assertEquals
Open

        $this->assertEquals('userId', $result);
Severity: Critical
Found in Tests/Unit/Utils/RestrictorTest.php by phan

Call to method expects from undeclared class \PHPUnit_Framework_MockObject_MockObject
Open

        $storageManager->expects($this->never())->method('getItem');
Severity: Critical
Found in Tests/Unit/Utils/RestrictorTest.php by phan

Define a constant instead of duplicating this literal "userId" 5 times.
Open

        $result = $restrictor->blockBy('userId');
Severity: Critical
Found in Tests/Unit/Utils/RestrictorTest.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.

Parameter $input has undeclared type \Symfony\Component\Console\Input\InputInterface
Open

    protected function execute(InputInterface $input, OutputInterface $output)
Severity: Minor
Found in Command/MySQLProviderSetupCommand.php by phan

Class implements undeclared interface \Symfony\Component\Config\Definition\ConfigurationInterface
Open

class Configuration implements ConfigurationInterface
Severity: Critical
Found in DependencyInjection/Configuration.php by phan

Call to method delete from undeclared class \Memcached
Open

        return $this->_memcached->delete($key);
Severity: Critical
Found in Storage/Provider/MemcachedProvider.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

Call to method expects from undeclared class \PHPUnit_Framework_MockObject_MockObject
Open

        $storageManager->expects($this->never())->method('setItem');
Severity: Critical
Found in Tests/Unit/Utils/RestrictorTest.php by phan

Rename "$_memcached" which has the same name as the field declared at line 17.
Open

        $_memcached = new Memcached();

Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

Noncompliant Code Example

class Foo {
  public $myField;

  public function doSomething() {
    $myField = 0;
    ...
  }
}

See

Call to method setParameter from undeclared class \Symfony\Component\DependencyInjection\ContainerBuilder
Open

        $container->setParameter('nw_request_limit.provider_type', $providerType);

@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
Severity
Category
Status
Source
Language