Showing 33 of 36 total issues
Avoid excessively long class names like RequestHandlerClassDoesNotExistsException. Keep class name length under 40. Open
final class RequestHandlerClassDoesNotExistsException extends OEmbedException
{
public function __construct(Provider $provider)
{
$message = 'The configured renderer class %s of provider: %s does not exists.';
- Read upRead up
- Exclude checks
LongClassName
Since: 2.9
Detects when classes or interfaces are declared with excessively long names.
Example
class ATooLongClassNameThatHintsAtADesignProblem {
}
interface ATooLongInterfaceNameThatHintsAtADesignProblem {
}
Source https://phpmd.org/rules/naming.html#longclassname
Avoid excessively long variable names like $afterFormEnginePageInitializedEvent. Keep variable name length under 30. Open
public function __invoke(AfterFormEnginePageInitializedEvent $afterFormEnginePageInitializedEvent): void
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Function handleUrlInputBlur
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
handleUrlInputBlur(urlInput) {
if (!urlInput.value.includes('<iframe')) {
return;
}
Avoid using undefined variables such as '$queryParams' which will lead to PHP notices. Open
return $this->urlService->mergeQueryParameters($url, $queryParams);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$queryParams' which will lead to PHP notices. Open
$queryParams['rel'] = $response->getConfiguration()->shouldPlayRelated() ? '1' : '0';
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Method startRequestLoop
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function startRequestLoop(Configuration $configuration): void
{
$response = null;
$request = null;
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 14 and the first side effect is on line 14. Open
<?php
- Exclude checks
Method __construct
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
int $uid,
string $url,
int $maxHeight = 0,
int $maxWidth = 0,
bool $playRelated = true,
The class OembedController has a coupling between objects value of 21. Consider to reduce the number of dependencies under 13. Open
class OembedController extends ActionController
{
private ConfigurationFactory $configurationFactory;
private ContainerInterface $container;
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Opening brace of a class must be on the line after the definition Open
class LinkResponse extends GenericResponse {}
- Exclude checks
Opening brace of a class must be on the line after the definition Open
class ProcessorException extends OEmbedException {}
- Exclude checks
Opening brace of a class must be on the line after the definition Open
class InvalidConfigurationException extends OEmbedException {}
- Exclude checks
Opening brace of a class must be on the line after the definition Open
abstract class OEmbedException extends Exception {}
- Exclude checks
Opening brace of a class must be on the line after the definition Open
class RequestException extends OEmbedException {}
- Exclude checks
The method __construct has a boolean flag argument $playRelated, which is a certain sign of a Single Responsibility Principle violation. Open
bool $playRelated = true,
- Read upRead up
- Exclude checks
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
Avoid too many return
statements within this function. Open
return;
Function handleUrlInputBlur
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
handleUrlInputBlur(urlInput) {
if (!urlInput.value.includes('<iframe')) {
return;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid unused parameters such as '$afterFormEnginePageInitializedEvent'. Open
public function __invoke(AfterFormEnginePageInitializedEvent $afterFormEnginePageInitializedEvent): void
- 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
Arguments with default values must be at the end of the argument list Open
string $aspectRatio = '',
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
},
- Exclude checks