esteit/shipping-calculator

View on GitHub
src/Handler/DhlHandler.php

Summary

Maintainability
C
1 day
Test Coverage

File DhlHandler.php has 279 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace EsteIt\ShippingCalculator\Handler;

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

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

    class DhlHandler implements HandlerInterface, ValidationHandlerInterface
    {
        /**
         * @var array
         */
    Severity: Minor
    Found in src/Handler/DhlHandler.php - About 2 hrs to fix

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

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

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

        class DhlHandler implements HandlerInterface, ValidationHandlerInterface
        {
            /**
             * @var array
             */
        Severity: Minor
        Found in src/Handler/DhlHandler.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/DhlHandler.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/DhlHandler.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/DhlHandler.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/DhlHandler.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/DhlHandler.php and 1 other location - About 4 hrs to fix
        src/Handler/AsendiaHandler.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

        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/DhlHandler.php and 3 other locations - About 45 mins to fix
        src/Handler/AramexHandler.php on lines 326..340
        src/Handler/AsendiaHandler.php on lines 323..337
        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 125 characters
        Open

                $maxLength = $converter->convert($maxDimensions->getLength(), $this->get('dimensions_unit'), $dimensions->getUnit());
        Severity: Minor
        Found in src/Handler/DhlHandler.php by phpcodesniffer

        Line exceeds 120 characters; contains 130 characters
        Open

                $maxWeight = $converter->convert($this->get('maximum_weight'), $this->get('mass_unit'), $package->getWeight()->getUnit());
        Severity: Minor
        Found in src/Handler/DhlHandler.php by phpcodesniffer

        Line exceeds 120 characters; contains 123 characters
        Open

                $maxWidth = $converter->convert($maxDimensions->getWidth(), $this->get('dimensions_unit'), $dimensions->getUnit());
        Severity: Minor
        Found in src/Handler/DhlHandler.php by phpcodesniffer

        Line exceeds 120 characters; contains 125 characters
        Open

                $maxHeight = $converter->convert($maxDimensions->getHeight(), $this->get('dimensions_unit'), $dimensions->getUnit());
        Severity: Minor
        Found in src/Handler/DhlHandler.php by phpcodesniffer

        Line exceeds 120 characters; contains 127 characters
        Open

                        'volumetric_weight_calculator' => new DhlVolumetricWeightCalculator($math, $weightConverter, $lengthConverter),
        Severity: Minor
        Found in src/Handler/DhlHandler.php by phpcodesniffer

        Line exceeds 120 characters; contains 151 characters
        Open

                $volumetricWeight = $this->getWeightConverter()->convert($volumetricWeight->getValue(), $volumetricWeight->getUnit(), $this->get('mass_unit'));
        Severity: Minor
        Found in src/Handler/DhlHandler.php by phpcodesniffer

        Line exceeds 120 characters; contains 121 characters
        Open

                $weight = $this->getWeightConverter()->convert($weight->getValue(), $weight->getUnit(), $this->get('mass_unit'));
        Severity: Minor
        Found in src/Handler/DhlHandler.php by phpcodesniffer

        There are no issues that match your filters.

        Category
        Status