vpietri/magento2-developer-quickdevbar

View on GitHub
Helper/Data.php

Summary

Maintainability
C
1 day
Test Coverage

The class Data has an overall complexity of 69 which is very high. The configured complexity threshold is 50.
Open

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{


    /**
Severity: Minor
Found in Helper/Data.php by phpmd

Data has 28 functions (exceeds 20 allowed). Consider refactoring.
Open

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{


    /**
Severity: Minor
Found in Helper/Data.php - About 3 hrs to fix

    File Data.php has 264 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;
    Severity: Minor
    Found in Helper/Data.php - About 2 hrs to fix

      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) {
      Severity: Minor
      Found in Helper/Data.php - About 1 hr to fix

        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,
        Severity: Major
        Found in Helper/Data.php - About 50 mins to fix

          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');
          
          
          Severity: Minor
          Found in Helper/Data.php - About 45 mins to fix

          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) {
          Severity: Minor
          Found in Helper/Data.php - About 35 mins to fix

          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 getWrapperContent has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getWrapperContent($ajax = false)
              {
                  //Clean old files
                  /** @var \SplFileInfo $fileInfo */
                  foreach (new \DirectoryIterator($this->getQdbTempDir()) as $fileInfo) {
          Severity: Minor
          Found in Helper/Data.php - About 25 mins to fix

          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 class Data has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.
          Open

          class Data extends \Magento\Framework\App\Helper\AbstractHelper
          {
          
          
              /**
          Severity: Minor
          Found in Helper/Data.php by phpmd

          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 247.
          Open

              function tailFile($filepath, $lines = 1, $adaptive = true)
              {
                  // Open file
                  $f = @fopen($filepath, "rb");
                  if ($f === false) {
          Severity: Minor
          Found in Helper/Data.php by phpmd

          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

          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)
          Severity: Minor
          Found in Helper/Data.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

          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)
          Severity: Minor
          Found in Helper/Data.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

          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)
          Severity: Minor
          Found in Helper/Data.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

          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)
          Severity: Minor
          Found in Helper/Data.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

          Missing class import via use statement (line '340', column '22').
          Open

                  foreach (new \DirectoryIterator($this->getQdbTempDir()) as $fileInfo) {
          Severity: Minor
          Found in Helper/Data.php by phpmd

          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)
          Severity: Minor
          Found in Helper/Data.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

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

              protected function getWrapperFilename($ajax = false)
          Severity: Minor
          Found in Helper/Data.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

          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)
          Severity: Minor
          Found in Helper/Data.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

          Missing class import via use statement (line '407', column '30').
          Open

                      $reflector = new \ReflectionClass($class);
          Severity: Minor
          Found in Helper/Data.php by phpmd

          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

          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;
          Severity: Minor
          Found in Helper/Data.php by phpmd

          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 '391', 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);
          Severity: Minor
          Found in Helper/Data.php by phpmd

          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;
          Severity: Minor
          Found in Helper/Data.php by phpmd

          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 '408', column '16').
          Open

              public function getIDELinkForClass($class)
              {
                  //return $class;
                  try {
                      $reflector = new \ReflectionClass($class);
          Severity: Minor
          Found in Helper/Data.php by phpmd

          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) {
          
                  }
          Severity: Minor
          Found in Helper/Data.php by phpmd

          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: save Register Data to use Ajax
          Severity: Minor
          Found in Helper/Data.php by fixme

          Avoid variables with short names like $f. Configured minimum length is 3.
          Open

                  $f = @fopen($filepath, "rb");
          Severity: Minor
          Found in Helper/Data.php by phpmd

          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

          There are no issues that match your filters.

          Category
          Status