Avoid unused parameters such as '$configuration'. Open
public function configure($configuration)
- Read upRead up
- Exclude checks
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)
- Exclude checks
Method \NW\RequestLimitBundle\Storage\Provider\MySQLProvider::remove
is declared to return mixed
but has no return value Open
public function remove($key)
- Exclude checks
Parameter $em
has undeclared type \Doctrine\ORM\EntityManager
Open
public function __construct(EntityManager $em)
- Exclude checks
@throws type of remove
has undeclared type \Doctrine\DBAL\Driver\Exception
(Did you mean class \Exception) Open
public function remove($key)
- Exclude checks
@throws type of fetchAllItems
has undeclared type \Doctrine\DBAL\Driver\Exception
(Did you mean class \Exception) Open
public function fetchAllItems()
- Exclude checks
@throws type of set
has undeclared type \Doctrine\DBAL\Exception
(Did you mean class \Exception) Open
public function set($key, $expiresAt)
- Exclude checks
@throws type of getItemsCount
has undeclared type \Doctrine\DBAL\Exception
(Did you mean class \Exception) Open
public function getItemsCount()
- Exclude checks
@throws type of fetchAllItems
has undeclared type \Doctrine\DBAL\Exception
(Did you mean class \Exception) Open
public function fetchAllItems()
- Exclude checks
Call to method getConnection
from undeclared class \Doctrine\ORM\EntityManager
Open
$connection = $this->_em->getConnection();
- Exclude checks
Property \NW\RequestLimitBundle\Storage\Provider\MySQLProvider->_em
has undeclared type \Doctrine\ORM\EntityManager
Open
private $_em;
- Exclude checks
Call to method getConnection
from undeclared class \Doctrine\ORM\EntityManager
Open
$connection = $this->_em->getConnection();
- Exclude checks
@throws type of remove
has undeclared type \Doctrine\DBAL\Exception
(Did you mean class \Exception) Open
public function remove($key)
- Exclude checks
@throws type of getItemsCount
has undeclared type \Doctrine\DBAL\Driver\Exception
(Did you mean class \Exception) Open
public function getItemsCount()
- Exclude checks
Call to method getConnection
from undeclared class \Doctrine\ORM\EntityManager
Open
$connection = $this->_em->getConnection();
- Exclude checks
@throws type of get
has undeclared type \Doctrine\DBAL\Exception
(Did you mean class \Exception) Open
public function get($key)
- Exclude checks
@throws type of set
has undeclared type \Doctrine\DBAL\Driver\Exception
(Did you mean class \Exception) Open
public function set($key, $expiresAt)
- Exclude checks
Method \NW\RequestLimitBundle\Storage\Provider\MySQLProvider::set
is declared to return mixed
but has no return value Open
public function set($key, $expiresAt)
- Exclude checks
Call to method getConnection
from undeclared class \Doctrine\ORM\EntityManager
Open
$connection = $this->_em->getConnection();
- Exclude checks
Call to method getConnection
from undeclared class \Doctrine\ORM\EntityManager
Open
$connection = $this->_em->getConnection();
- Exclude checks
Avoid using static access to class '\DateTime' in method 'get'. Open
$date = \DateTime::createFromFormat('Y-m-d H:i:s', $result[0]);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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
*/
- Read upRead up
- Exclude checks
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;
- Exclude checks