esteit/shipping-calculator

View on GitHub
src/Handler/AsendiaHandler.php

Summary

Maintainability
C
1 day
Test Coverage

File AsendiaHandler.php has 261 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace EsteIt\ShippingCalculator\Handler;

use EsteIt\ShippingCalculator\Address;
Severity: Minor
Found in src/Handler/AsendiaHandler.php - About 2 hrs to fix

    Method __construct has 45 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function __construct(array $options)
        {
            $math = new NativeMath();
            $resolver = new OptionsResolver();
            $dimensionsNormalizer = new DimensionsNormalizer($math);
    Severity: Minor
    Found in src/Handler/AsendiaHandler.php - About 1 hr to fix

      The class AsendiaHandler has a coupling between objects value of 22. Consider to reduce the number of dependencies under 13.
      Open

      class AsendiaHandler implements HandlerInterface, ValidationHandlerInterface
      {
          /**
           * @var array
           */
      Severity: Minor
      Found in src/Handler/AsendiaHandler.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

      Avoid unused parameters such as '$options'.
      Open

              return function (Options $options, $value) {
      Severity: Minor
      Found in src/Handler/AsendiaHandler.php by phpmd

      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

      Avoid unused parameters such as '$options'.
      Open

              return function (Options $options, $value) {
      Severity: Minor
      Found in src/Handler/AsendiaHandler.php by phpmd

      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

      Avoid unused parameters such as '$options'.
      Open

              return function (Options $options, $calculators) {
      Severity: Minor
      Found in src/Handler/AsendiaHandler.php by phpmd

      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

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

          public function validate(Result $result, Package $package)
          {
              try {
                  $this->validateSenderAddress($package->getSenderAddress());
              } catch (ViolationException $e) {
      Severity: Major
      Found in src/Handler/AsendiaHandler.php and 1 other location - About 4 hrs to fix
      src/Handler/DhlHandler.php on lines 90..115

      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 176.

      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

          protected function createImportCountriesNormalizer()
          {
              return function (Options $options, $value) {
                  $normalized = [];
                  foreach ($value as $country) {
      Severity: Major
      Found in src/Handler/AsendiaHandler.php and 2 other locations - About 2 hrs to fix
      src/Handler/AramexHandler.php on lines 305..321
      src/Handler/IParcelHandler.php on lines 301..317

      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 122.

      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 4 locations. Consider refactoring.
      Open

          protected function createExportCountriesNormalizer()
          {
              return function (Options $options, $value) {
                  $normalized = [];
                  foreach ($value as $country) {
      Severity: Major
      Found in src/Handler/AsendiaHandler.php and 3 other locations - About 45 mins to fix
      src/Handler/AramexHandler.php on lines 326..340
      src/Handler/DhlHandler.php on lines 340..354
      src/Handler/IParcelHandler.php on lines 322..336

      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 96.

      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

      Line exceeds 120 characters; contains 129 characters
      Open

                      $weight = $this->getWeightConverter()->convert($weight->getValue(), $weight->getUnit(), $this->get('mass_unit'));

      Line exceeds 120 characters; contains 136 characters
      Open

              $maximumDimension = $converter->convert($this->get('maximum_dimension'), $this->get('dimensions_unit'), $dimensions->getUnit());

      Line exceeds 120 characters; contains 124 characters
      Open

              $maxGirth = $converter->convert($this->get('maximum_girth'), $this->get('dimensions_unit'), $dimensions->getUnit());

      Line exceeds 120 characters; contains 137 characters
      Open

              $countryMaxWeight = $converter->convert($country->getMaximumWeight(), $this->get('mass_unit'), $package->getWeight()->getUnit());

      There are no issues that match your filters.

      Category
      Status