Showing 330 of 330 total issues
Function validate
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
public function validate(array $data)
{
$rules = $this->getRules();
foreach ($rules as $field => $rule) {
if ((isset($rule['required']) && $rule['required'] === true && isset($data[$field]))
- 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
Method getTranslator
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getTranslator($type, array $params = [])
{
$result = null;
if (!isset($params['language'])) {
Function getTranslator
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function getTranslator($type, array $params = [])
{
$result = null;
if (!isset($params['language'])) {
- 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 using short method names like Route::to(). The configured minimum method name length is 3. Open
public static function to($path)
{
$currentLanguage = \Translation::getLanguage();
if (\Translation::getDefaultLanguage() === $currentLanguage) {
$currentLanguage = '';
- Read upRead up
- Exclude checks
ShortMethodName
Since: 0.2
Detects when very short method names are used.
Example
class ShortMethod {
public function a( $index ) { // Violation
}
}
Source https://phpmd.org/rules/naming.html#shortmethodname
Avoid using short method names like EventTrait::on(). The configured minimum method name length is 3. Open
public function on($type, $callback)
{
if (!isset($this->callbacks[$type])) {
$this->callbacks[$type] = [];
}
- Read upRead up
- Exclude checks
ShortMethodName
Since: 0.2
Detects when very short method names are used.
Example
class ShortMethod {
public function a( $index ) { // Violation
}
}
Source https://phpmd.org/rules/naming.html#shortmethodname
Avoid using short method names like EventHandler::on(). The configured minimum method name length is 3. Open
public function on($type, $callback);
- Read upRead up
- Exclude checks
ShortMethodName
Since: 0.2
Detects when very short method names are used.
Example
class ShortMethod {
public function a( $index ) { // Violation
}
}
Source https://phpmd.org/rules/naming.html#shortmethodname
Function getHandlerByPath
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public static function getHandlerByPath($path)
{
$result = null;
$path = self::prepareRoute('/'.trim($path, " /"));
- 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
Method run
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function run()
{
try {
$this->trigger(self::EVENT_APPLICATION_RUN);
Consider simplifying this complex logical expression. Open
if ((isset($rule['required']) && $rule['required'] === true && isset($data[$field]))
|| ((!isset($rule['required']) || !$rule['required'])) && isset($data[$field])) {
foreach ($rule as $key => $value) {
if ($key !== 'required') {
foreach ($value as $validator) {
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Route
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Config
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Translation
- Exclude checks
Avoid variables with short names like $o. Configured minimum length is 3. Open
private $o;
- 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
Avoid variables with short names like $id. Configured minimum length is 3. Open
$id = $this->getId();
- 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
Avoid variables with short names like $o. Configured minimum length is 3. Open
public function setObject($o)
- 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
Avoid variables with short names like $fc. Configured minimum length is 3. Open
private $fc;
- 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 class QueryBuilder has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13. Open
class QueryBuilder
{
/**
* MySQL driver
*/
- 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
Function forceComponentLoading
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function forceComponentLoading()
{
$config = $this->getConfiguration();
foreach ($config[self::COMPONENT_CONFIG_BLOCK] as $key => $params) {
if (isset($params['class']) && isset($params['force'])) {
- 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
Multi-line function declaration not indented correctly; expected 8 spaces but found 30 Open
$type = 'text/javascript')
- Exclude checks
Expected 1 space after FUNCTION keyword; 0 found Open
function($paramName) use ($params) {
- Exclude checks