esteit/shipping-calculator

View on GitHub
src/Handler/AramexHandler.php

Summary

Maintainability
F
5 days
Test Coverage

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

class AramexHandler implements HandlerInterface, ValidationHandlerInterface
{
    /**
     * @var array
     */
Severity: Minor
Found in src/Handler/AramexHandler.php by phpmd

File AramexHandler.php has 300 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace EsteIt\ShippingCalculator\Handler;

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

    AramexHandler has 22 functions (exceeds 20 allowed). Consider refactoring.
    Open

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

      Method __construct has 49 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/AramexHandler.php - About 1 hr to fix

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

            public function getPrice(Package $package)
            {
                $weight = $package->getWeight();
                $volumetricWeight = $this->getVolumetricWeightCalculator()->calculate($package->getDimensions());
        
        
        Severity: Minor
        Found in src/Handler/AramexHandler.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 AramexHandler has a coupling between objects value of 20. Consider to reduce the number of dependencies under 13.
        Open

        class AramexHandler implements HandlerInterface, ValidationHandlerInterface
        {
            /**
             * @var array
             */
        Severity: Minor
        Found in src/Handler/AramexHandler.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/AramexHandler.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, $weightPrices) {
        Severity: Minor
        Found in src/Handler/AramexHandler.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, $zones) use($resolver) {
        Severity: Minor
        Found in src/Handler/AramexHandler.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 __construct(array $options)
            {
                $math = new NativeMath();
                $resolver = new OptionsResolver();
                $weightConverter = new WeightConverter($math);
        Severity: Major
        Found in src/Handler/AramexHandler.php and 1 other location - About 1 day to fix
        src/Handler/IParcelHandler.php on lines 32..87

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

        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

            public function getPrice(Package $package)
            {
                $weight = $package->getWeight();
                $volumetricWeight = $this->getVolumetricWeightCalculator()->calculate($package->getDimensions());
        
        
        Severity: Major
        Found in src/Handler/AramexHandler.php and 1 other location - About 1 day to fix
        src/Handler/IParcelHandler.php on lines 195..226

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

        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

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

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

        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

            public function validateWeight(Package $package)
            {
                $importCountry = $this->detectImportCountry($package->getRecipientAddress());
        
                $weight = $package->getWeight();
        Severity: Major
        Found in src/Handler/AramexHandler.php and 1 other location - About 2 hrs to fix
        src/Handler/IParcelHandler.php on lines 179..193

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

        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/AramexHandler.php and 2 other locations - About 2 hrs to fix
        src/Handler/AsendiaHandler.php on lines 302..318
        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 2 locations. Consider refactoring.
        Open

            public function validateMaximumPerimeter(Package $package)
            {
                $dimensions = $package->getDimensions();
                $perimeter = $this->getPerimeterCalculator()->calculate($dimensions);
                $maxPerimeter = $this->getLengthConverter()->convert($this->get('maximum_perimeter'), $this->get('dimensions_unit'), $dimensions->getUnit());
        Severity: Major
        Found in src/Handler/AramexHandler.php and 1 other location - About 1 hr to fix
        src/Handler/IParcelHandler.php on lines 169..177

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

        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

            public function validateMaximumDimension(Package $package)
            {
                $dimensions = $this->getDimensionsNormalizer()->normalize($package->getDimensions());
                $maximumDimension = $this->getLengthConverter()->convert($this->get('maximum_dimension'), $this->get('dimensions_unit'), $dimensions->getUnit());
                if ($this->getMath()->greaterThan($dimensions->getLength(), $maximumDimension)) {
        Severity: Minor
        Found in src/Handler/AramexHandler.php and 1 other location - About 50 mins to fix
        src/Handler/IParcelHandler.php on lines 160..167

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

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

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

            public function calculate(Result $result, Package $package)
            {
                $this->validate($result, $package);
                if (!$result->hasViolations()) {
                    try {
        Severity: Minor
        Found in src/Handler/AramexHandler.php and 1 other location - About 40 mins to fix
        src/Handler/IParcelHandler.php on lines 127..138

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

        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

        Expected 1 space after USE keyword; found 0
        Open

                return function (Options $options, $zones) use($resolver) {

        Line exceeds 120 characters; contains 149 characters
        Open

                $maxPerimeter = $this->getLengthConverter()->convert($this->get('maximum_perimeter'), $this->get('dimensions_unit'), $dimensions->getUnit());

        Line exceeds 120 characters; contains 151 characters
        Open

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

        Line exceeds 120 characters; contains 153 characters
        Open

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

        Line exceeds 120 characters; contains 146 characters
        Open

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

        Line exceeds 120 characters; contains 121 characters
        Open

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

        Line exceeds 120 characters; contains 130 characters
        Open

                        'volumetric_weight_calculator' => new AramexVolumetricWeightCalculator($math, $weightConverter, $lengthConverter),

        There are no issues that match your filters.

        Category
        Status