Data
has 28 functions (exceeds 20 allowed). Consider refactoring. Open
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
The class Data has an overall complexity of 77 which is very high. The configured complexity threshold is 50. Open
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
- Exclude checks
File Data.php
has 281 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace ADM\QuickDevBar\Helper;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Config\ScopeConfigInterface;
Function getWrapperContent
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function getWrapperContent($ajax = false)
{
//Clean old files
// /** @var \SplFileInfo $fileInfo */
// foreach (new \DirectoryIterator($this->getQdbTempDir()) as $fileInfo) {
- 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 getWrapperContent
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getWrapperContent($ajax = false)
{
//Clean old files
// /** @var \SplFileInfo $fileInfo */
// foreach (new \DirectoryIterator($this->getQdbTempDir()) as $fileInfo) {
Method tailFile
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function tailFile($filepath, $lines = 1, $adaptive = true)
{
// Open file
$f = @fopen($filepath, "rb");
if ($f === false) {
Method __construct
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool,
\Magento\Framework\Module\ModuleListInterface $moduleList,
\Magento\Framework\Filesystem $filesystem,
array $ideList,
Function isToolbarAccessAllowed
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function isToolbarAccessAllowed($testWithRestriction=false)
{
$allow = false;
$enable = $this->getQdbConfig('enable');
- 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
Function tailFile
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function tailFile($filepath, $lines = 1, $adaptive = true)
{
// Open file
$f = @fopen($filepath, "rb");
if ($f === false) {
- 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
The method getWrapperContent() has an NPath complexity of 240. The configured NPath complexity threshold is 200. Open
public function getWrapperContent($ajax = false)
{
//Clean old files
// /** @var \SplFileInfo $fileInfo */
// foreach (new \DirectoryIterator($this->getQdbTempDir()) as $fileInfo) {
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method getWrapperContent() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public function getWrapperContent($ajax = false)
{
//Clean old files
// /** @var \SplFileInfo $fileInfo */
// foreach (new \DirectoryIterator($this->getQdbTempDir()) as $fileInfo) {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The class Data has a coupling between objects value of 15. Consider to reduce the number of dependencies under 13. Open
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
- 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
Remove error control operator '@' on line 252. Open
function tailFile($filepath, $lines = 1, $adaptive = true)
{
// Open file
$f = @fopen($filepath, "rb");
if ($f === false) {
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Missing class import via use statement (line '440', column '30'). Open
$reflector = new \ReflectionClass($class);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method getAllowedIps has a boolean flag argument $separator, which is a certain sign of a Single Responsibility Principle violation. Open
public function getAllowedIps($separator = false)
- 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
The method getLogFiles has a boolean flag argument $key, which is a certain sign of a Single Responsibility Principle violation. Open
public function getLogFiles($key = false)
- 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
Missing class import via use statement (line '346', column '22'). Open
foreach (new \DirectoryIterator($this->getQdbTempDir()) as $fileInfo) {
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '356', column '27'). Open
$serializer = new \Magento\Framework\Serialize\Serializer\Json();
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method isToolbarAccessAllowed has a boolean flag argument $testWithRestriction, which is a certain sign of a Single Responsibility Principle violation. Open
public function isToolbarAccessAllowed($testWithRestriction=false)
- 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
The method getWrapperBaseFilename has a boolean flag argument $ajax, which is a certain sign of a Single Responsibility Principle violation. Open
protected function getWrapperBaseFilename($ajax = false)
- 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
The method tailFile has a boolean flag argument $adaptive, which is a certain sign of a Single Responsibility Principle violation. Open
function tailFile($filepath, $lines = 1, $adaptive = 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
Missing class import via use statement (line '375', column '22'). Open
foreach (new \DirectoryIterator($this->getQdbTempDir()) as $fileInfo) {
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method getWrapperContent has a boolean flag argument $ajax, which is a certain sign of a Single Responsibility Principle violation. Open
public function getWrapperContent($ajax = false)
- 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
The method setWrapperContent has a boolean flag argument $ajax, which is a certain sign of a Single Responsibility Principle violation. Open
public function setWrapperContent($content, $ajax = false)
- 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 assigning values to variables in if clauses and the like (line '424', column '12'). Open
public function getIDELinkForFile($file, $line=1, $btFormat = '%2$s(%3$d)')
{
$relativeFile = $file;
if(strpos($relativeFile, BP)===0) {
$relativeFile = preg_replace('#' . BP . DIRECTORY_SEPARATOR . '?#', '', $file);
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid assigning values to variables in if clauses and the like (line '441', column '16'). Open
public function getIDELinkForClass($class)
{
//return $class;
try {
$reflector = new \ReflectionClass($class);
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid assigning values to variables in if clauses and the like (line '80', column '49'). Open
public function getIdeRegex()
{
if($ide = $this->getQdbConfig('ide')) {
if (strtolower($ide) == 'custom' && $ideCustom = $this->getQdbConfig('ide_custom')) {
return $ideCustom;
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid assigning values to variables in if clauses and the like (line '79', column '12'). Open
public function getIdeRegex()
{
if($ide = $this->getQdbConfig('ide')) {
if (strtolower($ide) == 'custom' && $ideCustom = $this->getQdbConfig('ide_custom')) {
return $ideCustom;
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid using empty try-catch blocks in getIDELinkForClass. Open
} catch (\ReflectionException $e) {
}
- Read upRead up
- Exclude checks
EmptyCatchBlock
Since: 2.7.0
Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.
Example
class Foo {
public function bar()
{
try {
// ...
} catch (Exception $e) {} // empty catch block
}
}
Source https://phpmd.org/rules/design.html#emptycatchblock
TODO found Open
//TODO: unlink only files starting with 'qdb_register_' . $sessionId
- Exclude checks
TODO found Open
// //TODO: unlink only files starting with 'qdb_register_' . $sessionId
- Exclude checks
TODO found Open
//TODO: save Register Data to use Ajax
- Exclude checks
TODO found Open
//TODO: remove foreach
- Exclude checks
TODO found Open
* TODO: To removed
- Exclude checks
Avoid variables with short names like $f. Configured minimum length is 3. Open
$f = @fopen($filepath, "rb");
- 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;
}
}
}