vaimo/composer-patches

View on GitHub
src/Patch/DefinitionList/LoaderComponents/DownloaderComponent.php

Summary

Maintainability
B
4 hrs
Test Coverage

Method process has 55 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(array $patches, array $packagesByName)
    {
        $ownerName = $this->ownerPackage->getName();
        $relativePath = PathUtils::composePath($ownerName, 'downloads');
        $absolutePath = PathUtils::composePath($this->vendorDir, $relativePath);
Severity: Major
Found in src/Patch/DefinitionList/LoaderComponents/DownloaderComponent.php - About 2 hrs to fix

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

        public function process(array $patches, array $packagesByName)
        {
            $ownerName = $this->ownerPackage->getName();
            $relativePath = PathUtils::composePath($ownerName, 'downloads');
            $absolutePath = PathUtils::composePath($this->vendorDir, $relativePath);
    Severity: Minor
    Found in src/Patch/DefinitionList/LoaderComponents/DownloaderComponent.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 __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

            \Composer\Composer $composer,
            \Composer\Package\PackageInterface $ownerPackage,
            \Composer\Downloader\FileDownloader $downloadManager,
            \Vaimo\ComposerPatches\Console\Silencer $consoleSilencer,
            $vendorDir,
    Severity: Minor
    Found in src/Patch/DefinitionList/LoaderComponents/DownloaderComponent.php - About 45 mins to fix

      Missing class import via use statement (line '156', column '24').
      Open

              $package = new \Composer\Package\Package($name, $version, $version);

      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 '76', column '35').
      Open

              $this->compExecutor = new \Vaimo\ComposerPatches\Compatibility\Executor();

      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 '77', column '35').
      Open

              $this->errorHandler = new \Vaimo\ComposerPatches\ErrorHandlers\TransportErrorHandler($gracefulMode);

      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 using static access to class '\Vaimo\ComposerPatches\Utils\PathUtils' in method 'process'.
      Open

                      $destinationFile = PathUtils::composePath($destDir, basename($source));

      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 '\Vaimo\ComposerPatches\Utils\PathUtils' in method 'process'.
      Open

              $absolutePath = PathUtils::composePath($this->vendorDir, $relativePath);

      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 '\Vaimo\ComposerPatches\Utils\PathUtils' in method 'process'.
      Open

              $relativePath = PathUtils::composePath($ownerName, 'downloads');

      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 '\Vaimo\ComposerPatches\Utils\PathUtils' in method 'process'.
      Open

                      $destDir = PathUtils::composePath($absolutePath, $sourceHash);

      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

      Rename "$compExecutor" which has the same name as the field declared at line 46.
      Open

              $compExecutor = $this->compExecutor;

      Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

      Noncompliant Code Example

      class Foo {
        public $myField;
      
        public function doSomething() {
          $myField = 0;
          ...
        }
      }
      

      See

      Rename "$errorHandler" which has the same name as the field declared at line 51.
      Open

              $errorHandler = $this->errorHandler;

      Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

      Noncompliant Code Example

      class Foo {
        public $myField;
      
        public function doSomething() {
          $myField = 0;
          ...
        }
      }
      

      See

      Avoid unused parameters such as '$packagesByName'.
      Open

          public function process(array $patches, array $packagesByName)

      UnusedFormalParameter

      Since: 0.2

      Avoid passing parameters to methods or constructors and then not using those parameters.

      Example

      class Foo
      {
          private function bar($howdy)
          {
              // $howdy is not used
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

      Property \Vaimo\ComposerPatches\Patch\DefinitionList\LoaderComponents\DownloaderComponent->ownerPackage has undeclared type \Composer\Package\PackageInterface
      Open

          private $ownerPackage;

      Call to method getName from undeclared class \Composer\Package\PackageInterface
      Open

              $ownerName = $this->ownerPackage->getName();

      Call to method setInstallationSource from undeclared class \Composer\Package\Package
      Open

              $package->setInstallationSource('dist');

      Catching undeclared class \Composer\Downloader\TransportException
      Open

                      } catch (\Composer\Downloader\TransportException $exception) {

      Call to method setDistUrl from undeclared class \Composer\Package\Package
      Open

              $package->setDistUrl($remoteFile);

      Property \Vaimo\ComposerPatches\Patch\DefinitionList\LoaderComponents\DownloaderComponent->composer has undeclared type \Composer\Composer
      Open

          private $composer;

      Parameter $packagesByName has undeclared type \Composer\Package\PackageInterface[]
      Open

          public function process(array $patches, array $packagesByName)

      Call to method __construct from undeclared class \Composer\Package\Package
      Open

              $package = new \Composer\Package\Package($name, $version, $version);

      Parameter $ownerPackage has undeclared type \Composer\Package\PackageInterface
      Open

          public function __construct(

      Call to method setDistSha1Checksum from undeclared class \Composer\Package\Package
      Open

                  $package->setDistSha1Checksum($checksum);

      Property \Vaimo\ComposerPatches\Patch\DefinitionList\LoaderComponents\DownloaderComponent->fileDownloader has undeclared type \Composer\Downloader\FileDownloader
      Open

          private $fileDownloader;

      Call to method setDistType from undeclared class \Composer\Package\Package
      Open

              $package->setDistType('file');

      Call to method setTargetDir from undeclared class \Composer\Package\Package
      Open

              $package->setTargetDir($targetDir);

      Parameter $composer has undeclared type \Composer\Composer
      Open

          public function __construct(

      Parameter $downloadManager has undeclared type \Composer\Downloader\FileDownloader
      Open

          public function __construct(

      There are no issues that match your filters.

      Category
      Status