integer-net/magento2-shippingpreselection

View on GitHub

Showing 24 of 24 total issues

Method getCartGraphQlQuery has 197 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getCartGraphQlQuery()
    {
        return '
              total_quantity
              is_virtual
Severity: Major
Found in src/ViewModel/Cart/GraphQlQueries.php - About 7 hrs to fix

    Avoid excessively long variable names like $customerAttributesToCheckForMockData. Keep variable name length under 20.
    Open

        public $customerAttributesToCheckForMockData = [
            AddressInterface::FIRSTNAME,
            AddressInterface::LASTNAME,
            AddressInterface::STREET,
            AddressInterface::CITY,
    Severity: Minor
    Found in src/Service/AddressUnsetMockdata.php by phpmd

    LongVariable

    Since: 0.2

    Detects when a field, formal or local variable is declared with a long name.

    Example

    class Something {
        protected $reallyLongIntName = -3; // VIOLATION - Field
        public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
            $otherReallyLongName = -5; // VIOLATION - Local
            for ($interestingIntIndex = 0; // VIOLATION - For
                 $interestingIntIndex < 10;
                 $interestingIntIndex++ ) {
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#longvariable

    Avoid excessively long variable names like $customerAttributesToCheckForNullData. Keep variable name length under 20.
    Open

        public $customerAttributesToCheckForNullData = [
            AddressInterface::REGION_ID,
            AddressInterface::REGION,
        ];
    Severity: Minor
    Found in src/Service/AddressUnsetMockdata.php by phpmd

    LongVariable

    Since: 0.2

    Detects when a field, formal or local variable is declared with a long name.

    Example

    class Something {
        protected $reallyLongIntName = -3; // VIOLATION - Field
        public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
            $otherReallyLongName = -5; // VIOLATION - Local
            for ($interestingIntIndex = 0; // VIOLATION - For
                 $interestingIntIndex < 10;
                 $interestingIntIndex++ ) {
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#longvariable

    Avoid excessively long variable names like $addressResetConditions. Keep variable name length under 20.
    Open

            AddressResetConditions $addressResetConditions,

    LongVariable

    Since: 0.2

    Detects when a field, formal or local variable is declared with a long name.

    Example

    class Something {
        protected $reallyLongIntName = -3; // VIOLATION - Field
        public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
            $otherReallyLongName = -5; // VIOLATION - Local
            for ($interestingIntIndex = 0; // VIOLATION - For
                 $interestingIntIndex < 10;
                 $interestingIntIndex++ ) {
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#longvariable

    Avoid excessively long variable names like $shippingMethodManagement. Keep variable name length under 20.
    Open

        private ShippingMethodManagement $shippingMethodManagement;

    LongVariable

    Since: 0.2

    Detects when a field, formal or local variable is declared with a long name.

    Example

    class Something {
        protected $reallyLongIntName = -3; // VIOLATION - Field
        public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
            $otherReallyLongName = -5; // VIOLATION - Local
            for ($interestingIntIndex = 0; // VIOLATION - For
                 $interestingIntIndex < 10;
                 $interestingIntIndex++ ) {
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#longvariable

    Avoid excessively long variable names like $addressResetConditions. Keep variable name length under 20.
    Open

        private AddressResetConditions   $addressResetConditions;

    LongVariable

    Since: 0.2

    Detects when a field, formal or local variable is declared with a long name.

    Example

    class Something {
        protected $reallyLongIntName = -3; // VIOLATION - Field
        public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
            $otherReallyLongName = -5; // VIOLATION - Local
            for ($interestingIntIndex = 0; // VIOLATION - For
                 $interestingIntIndex < 10;
                 $interestingIntIndex++ ) {
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#longvariable

    Avoid excessively long variable names like $addressResetConditions. Keep variable name length under 20.
    Open

        private AddressResetConditions $addressResetConditions;
    Severity: Minor
    Found in src/Plugin/ResetShippingAddress.php by phpmd

    LongVariable

    Since: 0.2

    Detects when a field, formal or local variable is declared with a long name.

    Example

    class Something {
        protected $reallyLongIntName = -3; // VIOLATION - Field
        public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
            $otherReallyLongName = -5; // VIOLATION - Local
            for ($interestingIntIndex = 0; // VIOLATION - For
                 $interestingIntIndex < 10;
                 $interestingIntIndex++ ) {
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#longvariable

    Avoid excessively long variable names like $shippingMethodManagement. Keep variable name length under 20.
    Open

            ShippingMethodManagement $shippingMethodManagement,

    LongVariable

    Since: 0.2

    Detects when a field, formal or local variable is declared with a long name.

    Example

    class Something {
        protected $reallyLongIntName = -3; // VIOLATION - Field
        public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
            $otherReallyLongName = -5; // VIOLATION - Local
            for ($interestingIntIndex = 0; // VIOLATION - For
                 $interestingIntIndex < 10;
                 $interestingIntIndex++ ) {
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#longvariable

    Avoid excessively long variable names like $addressResetConditions. Keep variable name length under 20.
    Open

            AddressResetConditions $addressResetConditions)
    Severity: Minor
    Found in src/Plugin/ResetShippingAddress.php by phpmd

    LongVariable

    Since: 0.2

    Detects when a field, formal or local variable is declared with a long name.

    Example

    class Something {
        protected $reallyLongIntName = -3; // VIOLATION - Field
        public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
            $otherReallyLongName = -5; // VIOLATION - Local
            for ($interestingIntIndex = 0; // VIOLATION - For
                 $interestingIntIndex < 10;
                 $interestingIntIndex++ ) {
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#longvariable

    Function afterGetQuote has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        public function afterGetQuote(Session $subject, Quote $result): Quote
        {
            if (!$this->addressResetConditions->isAddressResetRequest() && !$this->addressResetConditions->isAddressIgnoreRequest()) {
                if (!$result->getIsVirtual() && $result->getItemsCount()) {
                    $shippingAddress = $result->getShippingAddress();
    Severity: Minor
    Found in src/Plugin/PreselectShippingMethod.php - About 55 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 variables with short names like $b. Configured minimum length is 3.
    Open

        private function sortArray($a, $b): int
    Severity: Minor
    Found in src/ViewModel/AllowedCountries.php by phpmd

    ShortVariable

    Since: 0.2

    Detects when a field, local, or parameter has a very short name.

    Example

    class Something {
        private $q = 15; // VIOLATION - Field
        public static function main( array $as ) { // VIOLATION - Formal
            $r = 20 + $this->q; // VIOLATION - Local
            for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                $r += $this->q;
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#shortvariable

    Avoid variables with short names like $a. Configured minimum length is 3.
    Open

        private function sortArray($a, $b): int
    Severity: Minor
    Found in src/ViewModel/AllowedCountries.php by phpmd

    ShortVariable

    Since: 0.2

    Detects when a field, local, or parameter has a very short name.

    Example

    class Something {
        private $q = 15; // VIOLATION - Field
        public static function main( array $as ) { // VIOLATION - Formal
            $r = 20 + $this->q; // VIOLATION - Local
            for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                $r += $this->q;
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#shortvariable

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

        public function afterGetQuote(Session $subject, Quote $result): Quote
        {
            if ($this->addressResetConditions->isAddressResetRequest()) {
                if (!$result->getIsVirtual() && $result->getItemsCount()) {
                    $shippingAddress = $result->getShippingAddress();
    Severity: Minor
    Found in src/Plugin/ResetShippingAddress.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

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

        private function prepareShippingRates(Quote $quote): void
        {
            $quote->getShippingAddress()->requestShippingRates();
            $rates = $quote->getShippingAddress()->getShippingRatesCollection();
    
    
    Severity: Minor
    Found in src/Plugin/PreselectShippingMethod.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 isMockedAddress has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public function isMockedAddress(Address $address): bool
        {
            $prefill = $this->storeConfig->getValue(AddressSetMockdata::CONFIG_PATH_MOCK_DATASET, 'store');
    
            $matchesNeeded = count($this->customerAttributesToCheckForMockData);
    Severity: Minor
    Found in src/Service/AddressUnsetMockdata.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

    The method isMockedAddress uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                } else {
                    $matches = $matches + (int)($address->getData($attributeCode) === $prefill);
                }
    Severity: Minor
    Found in src/Service/AddressUnsetMockdata.php by phpmd

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

    The method afterGetQuote uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                    } else {
                        $this->addressUnsetMockdata->checkForEmptyAddressFields($shippingAddress);
                    }
    Severity: Minor
    Found in src/Plugin/ResetShippingAddress.php by phpmd

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

    syntax error, unexpected 'ScopeConfigInterface' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
    Open

        private ScopeConfigInterface $storeConfig;
    Severity: Critical
    Found in src/Service/AddressSetMockdata.php by phan

    syntax error, unexpected 'DirectoryAllowedCountries' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
    Open

        private DirectoryAllowedCountries $allowedCountries;
    Severity: Critical
    Found in src/ViewModel/AllowedCountries.php by phan

    syntax error, unexpected 'AddressUnsetMockdata' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
    Open

        private AddressUnsetMockdata   $addressUnsetMockdata;
    Severity: Critical
    Found in src/Plugin/ResetShippingAddress.php by phan
    Severity
    Category
    Status
    Source
    Language