NovikovViktor/RequestLimitBundle

View on GitHub
Tests/Unit/Utils/RestrictorTest.php

Summary

Maintainability
A
0 mins
Test Coverage

The method getStorageManagerMock has a boolean flag argument $hasItem, which is a certain sign of a Single Responsibility Principle violation.
Open

    private function getStorageManagerMock($item = 'userId', $hasItem = false)
Severity: Minor
Found in Tests/Unit/Utils/RestrictorTest.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

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

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.

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

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

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

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

Class extends undeclared class \PHPUnit_Framework_TestCase
Open

class RestrictorTest extends \PHPUnit_Framework_TestCase
Severity: Critical
Found in Tests/Unit/Utils/RestrictorTest.php by phan

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

        $storageManager->expects($this->once())
Severity: Critical
Found in Tests/Unit/Utils/RestrictorTest.php by phan

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

        $storageManager = $this->createMock(
Severity: Critical
Found in Tests/Unit/Utils/RestrictorTest.php by phan

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

        $storageManager->expects($this->once())
Severity: Critical
Found in Tests/Unit/Utils/RestrictorTest.php by phan

Argument 2 (hasItem) is true but \NW\RequestLimitBundle\Tests\Unit\Utils\RestrictorTest::getStorageManagerMock() takes false defined at /code/Tests/Unit/Utils/RestrictorTest.php:45
Open

        $storageManager = $this->getStorageManagerMock('userId', true);
Severity: Minor
Found in Tests/Unit/Utils/RestrictorTest.php by phan

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

        $this->setExpectedException(RequestLimitReachedException::class);
Severity: Critical
Found in Tests/Unit/Utils/RestrictorTest.php by phan

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

        $storageManager->expects($this->once())
Severity: Critical
Found in Tests/Unit/Utils/RestrictorTest.php by phan

Return type of getStorageManagerMock() is undeclared type \PHPUnit_Framework_MockObject_MockObject
Open

    private function getStorageManagerMock($item = 'userId', $hasItem = false)
Severity: Minor
Found in Tests/Unit/Utils/RestrictorTest.php by phan

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

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

There are no issues that match your filters.

Category
Status