autowp/autowp

View on GitHub
module/Application/src/Controller/Api/BrandsController.php

Summary

Maintainability
D
2 days
Test Coverage
F
22%

File BrandsController.php has 357 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Application\Controller\Api;

use Application\Model\Brand;
Severity: Minor
Found in module/Application/src/Controller/Api/BrandsController.php - About 4 hrs to fix

    Method otherGroups has 56 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function otherGroups(
            int $brandId,
            string $brandCatname,
            bool $conceptsSeparately
        ): array {
    Severity: Major
    Found in module/Application/src/Controller/Api/BrandsController.php - About 2 hrs to fix

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

          private function carSectionGroupsSelect(
              int $brandId,
              int $itemTypeId,
              int $carTypeId,
              ?bool $nullType,
      Severity: Major
      Found in module/Application/src/Controller/Api/BrandsController.php - About 2 hrs to fix

        Method carSections has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function carSections(
                string $language,
                int $brandId,
                string $brandCatname,
                bool $conceptsSeparatly
        Severity: Major
        Found in module/Application/src/Controller/Api/BrandsController.php - About 2 hrs to fix

          Method carSectionGroups has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function carSectionGroups(
                  string $language,
                  int $brandId,
                  string $brandCatname,
                  array $section,
          Severity: Minor
          Found in module/Application/src/Controller/Api/BrandsController.php - About 1 hr to fix

            Method newItemsAction has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function newItemsAction(): ViewModel
                {
                    $brand = $this->itemModel->getRow([
                        'item_type_id' => Item::BRAND,
                        'id'           => (int) $this->params()->fromRoute('id'),
            Severity: Minor
            Found in module/Application/src/Controller/Api/BrandsController.php - About 1 hr to fix

              Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                      StorageInterface $cache,
                      Brand $brand,
                      VehicleType $vehicleType,
                      Item $itemModel,
                      Picture $picture,
              Severity: Minor
              Found in module/Application/src/Controller/Api/BrandsController.php - About 45 mins to fix

                Method carSectionGroups has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                        string $language,
                        int $brandId,
                        string $brandCatname,
                        array $section,
                        bool $conceptsSeparatly
                Severity: Minor
                Found in module/Application/src/Controller/Api/BrandsController.php - About 35 mins to fix

                  Method carSectionGroupsSelect has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                          int $brandId,
                          int $itemTypeId,
                          int $carTypeId,
                          ?bool $nullType,
                          bool $conceptsSeparately
                  Severity: Minor
                  Found in module/Application/src/Controller/Api/BrandsController.php - About 35 mins to fix

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

                        private function carSectionGroups(
                            string $language,
                            int $brandId,
                            string $brandCatname,
                            array $section,
                    Severity: Minor
                    Found in module/Application/src/Controller/Api/BrandsController.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 otherGroups has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function otherGroups(
                            int $brandId,
                            string $brandCatname,
                            bool $conceptsSeparately
                        ): array {
                    Severity: Minor
                    Found in module/Application/src/Controller/Api/BrandsController.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

                    Avoid using undefined variables such as '$success' which will lead to PHP notices.
                    Open

                            if (! $success) {

                    UndefinedVariable

                    Since: 2.8.0

                    Detects when a variable is used that has not been defined before.

                    Example

                    class Foo
                    {
                        private function bar()
                        {
                            // $message is undefined
                            echo $message;
                        }
                    }

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

                    Avoid using undefined variables such as '$success' which will lead to PHP notices.
                    Open

                            $items = $this->cache->getItem($cacheKey, $success);

                    UndefinedVariable

                    Since: 2.8.0

                    Detects when a variable is used that has not been defined before.

                    Example

                    class Foo
                    {
                        private function bar()
                        {
                            // $message is undefined
                            echo $message;
                        }
                    }

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

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

                    class BrandsController extends AbstractActionController
                    {
                        private StorageInterface $cache;
                    
                        private Brand $brand;

                    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

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

                            } else {
                                $rows   = [];
                                $select = $this->carSectionGroupsSelect(
                                    $brandId,
                                    $section['item_type_id'],

                    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 'StorageInterface' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
                    Open

                        private StorageInterface $cache;

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

                        public function __construct(
                            StorageInterface $cache,
                            Brand $brand,
                            VehicleType $vehicleType,
                            Item $itemModel,
                    Severity: Minor
                    Found in module/Application/src/Controller/Api/BrandsController.php and 1 other location - About 1 hr to fix
                    module/Application/src/Service/Mosts.php on lines 337..351

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

                    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

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

                            $unsortedPicturesCount = $this->picture->getCount([

                    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

                    There are no issues that match your filters.

                    Category
                    Status