modxcms/revolution

View on GitHub
core/model/modx/transport/modtransportpackage.class.php

Summary

Maintainability
F
6 days
Test Coverage

File modtransportpackage.class.php has 476 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/*
 * This file is part of MODX Revolution.
 *
 * Copyright (c) MODX, LLC. All Rights Reserved.
Severity: Minor
Found in core/model/modx/transport/modtransportpackage.class.php - About 7 hrs to fix

    Function transferPackage has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
    Open

        public function transferPackage($sourceFile, $targetDir) {
            $transferred= false;
            $content= '';
            if (is_dir($targetDir) && is_writable($targetDir)) {
                if (!is_array($this->xpdo->version)) { $this->xpdo->getVersionData(); }
    Severity: Minor
    Found in core/model/modx/transport/modtransportpackage.class.php - About 6 hrs 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 getTransport has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getTransport($state = -1) {
            if (!is_object($this->package) || !($this->package instanceof xPDOTransport)) {
                $workspace = $this->getOne('Workspace');
                if ($workspace) {
                    $packageDir = $workspace->get('path') . 'packages/';
    Severity: Minor
    Found in core/model/modx/transport/modtransportpackage.class.php - About 5 hrs 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 transferPackage has 72 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function transferPackage($sourceFile, $targetDir) {
            $transferred= false;
            $content= '';
            if (is_dir($targetDir) && is_writable($targetDir)) {
                if (!is_array($this->xpdo->version)) { $this->xpdo->getVersionData(); }
    Severity: Major
    Found in core/model/modx/transport/modtransportpackage.class.php - About 2 hrs to fix

      Function setPackageVersionData has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public function setPackageVersionData() {
              $sig = explode('-',$this->signature);
              if (is_array($sig)) {
                  if (!empty($sig[1])) {
                      $v = explode('.',$sig[1]);
      Severity: Minor
      Found in core/model/modx/transport/modtransportpackage.class.php - About 2 hrs 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 install has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          public function install(array $options = array()) {
              $installed = false;
              if ($this->getTransport()) {
                  $this->xpdo->log(xPDO::LOG_LEVEL_INFO,$this->xpdo->lexicon('workspace_grabbing'));
                  $this->getOne('Workspace');
      Severity: Minor
      Found in core/model/modx/transport/modtransportpackage.class.php - About 2 hrs 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

      modTransportPackage has 21 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class modTransportPackage extends xPDOObject {
          /** @var xPDO|modX */
          public $xpdo = null;
          /**
           * @var string The unique identifier of a package.
      Severity: Minor
      Found in core/model/modx/transport/modtransportpackage.class.php - About 2 hrs to fix

        Function parseSignature has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            public function parseSignature() {
                $parsed = false;
                $sig = $this->get('signature');
                if ($sig != null) {
                    $parsedSig = xPDOTransport::parseSignature($sig);
        Severity: Minor
        Found in core/model/modx/transport/modtransportpackage.class.php - About 2 hrs 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 checkDependencies has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            public function checkDependencies(array $dependencies) {
                $unsatisfied = array();
                $dependencies = xPDOTransport::checkPlatformDependencies($dependencies);
                foreach ($dependencies as $package => $constraint) {
                    if (strtolower($package) === strtolower($this->identifier)) continue;
        Severity: Minor
        Found in core/model/modx/transport/modtransportpackage.class.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 install has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function install(array $options = array()) {
                $installed = false;
                if ($this->getTransport()) {
                    $this->xpdo->log(xPDO::LOG_LEVEL_INFO,$this->xpdo->lexicon('workspace_grabbing'));
                    $this->getOne('Workspace');
        Severity: Minor
        Found in core/model/modx/transport/modtransportpackage.class.php - About 1 hr to fix

          Function findResolution has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              public function findResolution($package, $constraint, &$provider = null) {
                  $resolution = false;
                  $conditions = array(
                      'active' => true,
                  );
          Severity: Minor
          Found in core/model/modx/transport/modtransportpackage.class.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 getTransport has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getTransport($state = -1) {
                  if (!is_object($this->package) || !($this->package instanceof xPDOTransport)) {
                      $workspace = $this->getOne('Workspace');
                      if ($workspace) {
                          $packageDir = $workspace->get('path') . 'packages/';
          Severity: Minor
          Found in core/model/modx/transport/modtransportpackage.class.php - About 1 hr to fix

            Method findResolution has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function findResolution($package, $constraint, &$provider = null) {
                    $resolution = false;
                    $conditions = array(
                        'active' => true,
                    );
            Severity: Minor
            Found in core/model/modx/transport/modtransportpackage.class.php - About 1 hr to fix

              Method checkDependencies has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function checkDependencies(array $dependencies) {
                      $unsatisfied = array();
                      $dependencies = xPDOTransport::checkPlatformDependencies($dependencies);
                      foreach ($dependencies as $package => $constraint) {
                          if (strtolower($package) === strtolower($this->identifier)) continue;
              Severity: Minor
              Found in core/model/modx/transport/modtransportpackage.class.php - About 1 hr to fix

                Method parseSignature has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function parseSignature() {
                        $parsed = false;
                        $sig = $this->get('signature');
                        if ($sig != null) {
                            $parsedSig = xPDOTransport::parseSignature($sig);
                Severity: Minor
                Found in core/model/modx/transport/modtransportpackage.class.php - About 1 hr to fix

                  Function checkDownloadedDependencies has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function checkDownloadedDependencies(array $dependencies) {
                          $satisfied = array();
                          foreach ($dependencies as $package => $constraint) {
                              if (strtolower($package) === strtolower($this->identifier) || $package === 'php' || $package === 'modx') continue;
                  
                  
                  Severity: Minor
                  Found in core/model/modx/transport/modtransportpackage.class.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 _getByFsockopen has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function _getByFsockopen($url) {
                          $purl = parse_url($url);
                          $host = $purl['host'];
                          $path = !empty($purl['path']) ? $purl['path'] : '/';
                          if (!empty($purl['query'])) { $path .= '?'.$purl['query']; }
                  Severity: Minor
                  Found in core/model/modx/transport/modtransportpackage.class.php - About 1 hr to fix

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

                        public function resolveDependency($package, $constraint) {
                            $resolved = false;
                            /** @var modTransportProvider|null $provider */
                            $provider = null;
                            $resolution = $this->findResolution($package, $constraint, $provider);
                    Severity: Minor
                    Found in core/model/modx/transport/modtransportpackage.class.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

                    Avoid deeply nested control flow statements.
                    Open

                                                if ($state == xPDOTransport::STATE_PACKED) {
                                                    $this->set('state', xPDOTransport::STATE_UNPACKED);
                                                }
                    Severity: Major
                    Found in core/model/modx/transport/modtransportpackage.class.php - About 45 mins to fix

                      Method listPackages has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          public static function listPackages(modX &$modx, $workspace, $limit = 0, $offset = 0,$search = '') {
                      Severity: Minor
                      Found in core/model/modx/transport/modtransportpackage.class.php - About 35 mins to fix

                        Function uninstall has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function uninstall(array $options = array()) {
                                $uninstalled = false;
                                if (!$this->getTransport()) {
                                    /* files have already been removed, so ignore this */
                                    return true;
                        Severity: Minor
                        Found in core/model/modx/transport/modtransportpackage.class.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 removePackage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function removePackage($force = false, $uninstall = true) {
                                $removed = false;
                                $uninstalled = false;
                                if ($this->get('installed') == null || $this->get('installed') == '0000-00-00 00:00:00') {
                                    $uninstalled = true;
                        Severity: Minor
                        Found in core/model/modx/transport/modtransportpackage.class.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

                        Similar blocks of code found in 3 locations. Consider refactoring.
                        Open

                                    if (!empty($sig[2])) {
                                        $r = preg_split('/([0-9]+)/',$sig[2],-1,PREG_SPLIT_DELIM_CAPTURE);
                                        if (is_array($r) && !empty($r)) {
                                            $this->set('release',$r[0]);
                                            $this->set('release_index',(isset($r[1]) ? $r[1] : '0'));
                        Severity: Major
                        Found in core/model/modx/transport/modtransportpackage.class.php and 2 other locations - About 2 hrs to fix
                        core/model/modx/processors/workspace/packages/scanlocal.class.php on lines 103..111
                        setup/includes/upgrades/mysql/2.0.0-rc-1.php on lines 55..63

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 128.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 3 locations. Consider refactoring.
                        Open

                                    if (!empty($sig[1])) {
                                        $v = explode('.',$sig[1]);
                                        if (isset($v[0])) $this->set('version_major',$v[0]);
                                        if (isset($v[1])) $this->set('version_minor',$v[1]);
                                        if (isset($v[2])) $this->set('version_patch',$v[2]);
                        Severity: Major
                        Found in core/model/modx/transport/modtransportpackage.class.php and 2 other locations - About 1 hr to fix
                        core/model/modx/processors/workspace/packages/scanlocal.class.php on lines 97..102
                        setup/includes/upgrades/mysql/2.0.0-rc-1.php on lines 49..54

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 115.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Identical blocks of code found in 2 locations. Consider refactoring.
                        Open

                            protected function _bytes($value) {
                                $value = trim($value);
                                $modifier = strtolower($value[strlen($value) - 1]);
                                switch($modifier) {
                                    case 'g':
                        Severity: Minor
                        Found in core/model/modx/transport/modtransportpackage.class.php and 1 other location - About 30 mins to fix
                        core/model/modx/modstaticresource.class.php on lines 208..220

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 91.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        There are no issues that match your filters.

                        Category
                        Status