TikiWiki/tiki-manager

View on GitHub
src/Command/Helper/CommandHelper.php

Summary

Maintainability
D
1 day
Test Coverage

setInstanceSetupError accesses the super-global variable $_ENV.
Open

    public static function setInstanceSetupError($instanceId, \Exception $e = null)
    {
        $errors = [];
        $io = App::get('io');

Severity: Minor
Found in src/Command/Helper/CommandHelper.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

File CommandHelper.php has 403 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @copyright (c) Copyright by authors of the Tiki Manager Project. All Rights Reserved.
 *     See copyright.txt for details and a complete list of authors.
 * @licence Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See LICENSE for details.
Severity: Minor
Found in src/Command/Helper/CommandHelper.php - About 5 hrs to fix

    The class CommandHelper has 17 public methods. Consider refactoring CommandHelper to keep number of public methods under 10.
    Open

    class CommandHelper
    {
        /**
         * Get information from Instance Object
         *
    Severity: Minor
    Found in src/Command/Helper/CommandHelper.php by phpmd

    TooManyPublicMethods

    Since: 0.1

    A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

    By default it ignores methods starting with 'get' or 'set'.

    Example

    Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

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

    class CommandHelper
    {
        /**
         * Get information from Instance Object
         *
    Severity: Minor
    Found in src/Command/Helper/CommandHelper.php by phpmd

    CommandHelper has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class CommandHelper
    {
        /**
         * Get information from Instance Object
         *
    Severity: Minor
    Found in src/Command/Helper/CommandHelper.php - About 2 hrs to fix

      Function validateInstanceSelection has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function validateInstanceSelection($answer, $instances)
          {
              if (empty($answer)) {
                  throw new \RuntimeException(
                      'You must select an instance #ID'
      Severity: Minor
      Found in src/Command/Helper/CommandHelper.php - About 1 hr 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

      Method validateInstanceSelection has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function validateInstanceSelection($answer, $instances)
          {
              if (empty($answer)) {
                  throw new \RuntimeException(
                      'You must select an instance #ID'
      Severity: Minor
      Found in src/Command/Helper/CommandHelper.php - About 1 hr to fix

        Method renderReportOptions has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function renderReportOptions($output)
            {
                $headers = [
                    'Option',
                    'Description'
        Severity: Minor
        Found in src/Command/Helper/CommandHelper.php - About 1 hr to fix

          Function clearFolderContents has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function clearFolderContents($dirs, LoggerInterface $logger)
              {
                  if (!is_array($dirs)) {
                      $dirs = [$dirs];
                  }
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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 setInstanceSetupError has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function setInstanceSetupError($instanceId, \Exception $e = null)
              {
                  $errors = [];
                  $io = App::get('io');
          
          
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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 removeFiles has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function removeFiles($files, LoggerInterface $logger)
              {
                  if (!is_array($files)) {
                      $files = [$files];
                  }
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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

          Function getInstances has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function getInstances($type = 'all', $excludeBlank = false)
              {
                  $result = [];
          
                  switch ($type) {
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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 CommandHelper has a coupling between objects value of 16. Consider to reduce the number of dependencies under 13.
          Open

          class CommandHelper
          {
              /**
               * Get information from Instance Object
               *
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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

          Missing class import via use statement (line '244', column '27').
          Open

                          throw new \RuntimeException(
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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

          Missing class import via use statement (line '301', column '23').
          Open

                      throw new \RuntimeException(
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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

          Missing class import via use statement (line '324', column '23').
          Open

                      throw new \RuntimeException(
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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

          Missing class import via use statement (line '318', column '23').
          Open

                      throw new \RuntimeException(
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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

          Missing class import via use statement (line '225', column '23').
          Open

                      throw new \RuntimeException(
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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

          Missing class import via use statement (line '383', column '33').
          Open

                          $iterator = new \FilesystemIterator($dir);
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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

          Missing class import via use statement (line '268', column '23').
          Open

                      throw new \RuntimeException(
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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

          Missing class import via use statement (line '526', column '31').
          Open

                              throw new \RuntimeException(sprintf("Email address '%s' is not valid!", $emailAddr));
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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 getInstances has a boolean flag argument $excludeBlank, which is a certain sign of a Single Responsibility Principle violation.
          Open

              public static function getInstances($type = 'all', $excludeBlank = false)
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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 '332', column '23').
          Open

                      throw new \RuntimeException(
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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

          Missing class import via use statement (line '284', column '23').
          Open

                      throw new \RuntimeException(
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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

          Missing class import via use statement (line '338', column '23').
          Open

                      throw new \RuntimeException(
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.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 validateInstanceSelection uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      $reindexedInstances = array();
                      foreach ($instances as $id => $instance) {
                          $reindexedInstances[ $id ] = $instance;
                          $reindexedInstances[ $instance->name ] = $instance;
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phpmd

          ElseExpression

          Since: 1.4.0

          An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

          Example

          class Foo
          {
              public function bar($flag)
              {
                  if ($flag) {
                      // one branch
                  } else {
                      // another branch
                  }
              }
          }

          Source https://phpmd.org/rules/cleancode.html#elseexpression

          The method getQuestion uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      $question = $question . $character . ' ';
                  }
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phpmd

          ElseExpression

          Since: 1.4.0

          An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

          Example

          class Foo
          {
              public function bar($flag)
              {
                  if ($flag) {
                      // one branch
                  } else {
                      // another branch
                  }
              }
          }

          Source https://phpmd.org/rules/cleancode.html#elseexpression

          Avoid using static access to class '\TikiManager\Application\Instance' in method 'getInstances'.
          Open

                          $result = Instance::getUpgradableInstances();
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phpmd

          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

          Avoid using static access to class '\TikiManager\Application\Instance' in method 'getInstances'.
          Open

                          $result = Instance::getTikiInstances();
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phpmd

          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

          Avoid using static access to class '\TikiManager\Application\Instance' in method 'getInstances'.
          Open

                          $result = Instance::getNoTikiInstances();
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phpmd

          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

          Avoid using static access to class '\TikiManager\Application\Instance' in method 'getInstances'.
          Open

                          $result = Instance::getRestorableInstances();
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phpmd

          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

          Avoid using static access to class '\TikiManager\Application\Instance' in method 'getInstances'.
          Open

                          $result = Instance::getInstances($excludeBlank);
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phpmd

          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

          Avoid using static access to class '\TikiManager\Application\Instance' in method 'logException'.
          Open

                      $instance = Instance::getInstance($instance);
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phpmd

          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

          Avoid using static access to class '\TikiManager\Libs\Helpers\ApplicationHelper' in method 'supportedInstanceTypes'.
          Open

                  $instanceTypes = ApplicationHelper::isWindows() ? 'local' : Instance::TYPES;
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phpmd

          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

          Avoid using static access to class '\TikiManager\Application\Instance' in method 'getInstances'.
          Open

                          $result = Instance::getUpdatableInstances();
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phpmd

          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

          Avoid using static access to class '\Cron\CronExpression' in method 'validateCrontabInput'.
          Open

                  if (!CronExpression::isValidExpression($answer)) {
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phpmd

          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

          Suspicious array access to null
          Open

                      $instancesInfo[] = [
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phan

          Argument 2 (subject) is int but \preg_match() takes string
          Open

                  if (preg_match('/(\d+)(\d{2})(\d{2})$/', $phpVersion, $matches)) {
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phan

          Possibly zero references to use statement for classlike/namespace Environment (\TikiManager\Config\Environment)
          Open

          use TikiManager\Config\Environment;
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phan

          Suspicious array access to ?mixed
          Open

                      $payload[] = is_object($instance) ? $instance->id : $instance['id'];
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phan

          Assigning string to property but \TikiManager\Application\Instance->vcs_type is null
          Open

                      $instance->vcs_type = $vcsType;
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phan

          Suspicious array access to null
          Open

                          $versionsInfo[] = [
          Severity: Minor
          Found in src/Command/Helper/CommandHelper.php by phan

          There are no issues that match your filters.

          Category
          Status