Smile-SA/elasticsuite

View on GitHub
src/module-elasticsuite-virtual-category/Model/Rule.php

Summary

Maintainability
D
2 days
Test Coverage

File Rule.php has 334 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer
Severity: Minor
Found in src/module-elasticsuite-virtual-category/Model/Rule.php - About 4 hrs to fix

    Rule has 19 functions (exceeds 10 allowed). Consider refactoring.
    Open

    class Rule extends \Smile\ElasticsuiteCatalogRule\Model\Rule implements VirtualRuleInterface
    {
        /**
         * @var QueryFactory
         */
    Severity: Minor
    Found in src/module-elasticsuite-virtual-category/Model/Rule.php - About 3 hrs to fix

      Function addChildrenQueries has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          private function addChildrenQueries($query, CategoryInterface $category, $excludedCategories = []): QueryInterface
          {
              $childrenCategories    = $this->getChildrenCategories($category, $excludedCategories);
              $childrenCategoriesIds = [];
      
      
      Severity: Minor
      Found in src/module-elasticsuite-virtual-category/Model/Rule.php - About 2 hrs 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

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

              Context $context,
              Registry $registry,
              FormFactory             $formFactory,
              TimezoneInterface       $localeDate,
              CombineConditionFactory $combineConditionsFactory,
      Severity: Major
      Found in src/module-elasticsuite-virtual-category/Model/Rule.php - About 2 hrs to fix

        Method addChildrenQueries has 47 lines of code (exceeds 40 allowed). Consider refactoring.
        Open

            private function addChildrenQueries($query, CategoryInterface $category, $excludedCategories = []): QueryInterface
            {
                $childrenCategories    = $this->getChildrenCategories($category, $excludedCategories);
                $childrenCategoriesIds = [];
        
        
        Severity: Minor
        Found in src/module-elasticsuite-virtual-category/Model/Rule.php - About 1 hr to fix

          Function getCategorySearchQuery has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getCategorySearchQuery($category, $excludedCategories = []): ?QueryInterface
              {
                  \Magento\Framework\Profiler::start('ES:Virtual Rule ' . __FUNCTION__);
                  $categoryId = (int) (!is_object($category) ? $category : $category->getId());
                  $storeId = !is_object($category) ? $this->getStoreId() : $category->getStoreId();
          Severity: Minor
          Found in src/module-elasticsuite-virtual-category/Model/Rule.php - About 1 hr 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 buildCategorySearchQuery has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              private function buildCategorySearchQuery($category, $excludedCategories = []): ?QueryInterface
              {
                  $query = null;
          
                  if (!in_array($category->getId(), $excludedCategories)) {
          Severity: Minor
          Found in src/module-elasticsuite-virtual-category/Model/Rule.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

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

              public function getSearchQueriesByChildren(CategoryInterface $rootCategory): array
              {
                  $queries     = [];
                  $childrenIds = $rootCategory->getResource()->getChildren($rootCategory, false);
          
          
          Severity: Minor
          Found in src/module-elasticsuite-virtual-category/Model/Rule.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

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

              private function getVirtualRootCategory(CategoryInterface $category): ?CategoryInterface
              {
                  $storeId      = $this->getStoreId();
                  $rootCategory = null;
          
          
          Severity: Minor
          Found in src/module-elasticsuite-virtual-category/Model/Rule.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

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

              private function getVirtualCategoryQuery(
                  CategoryInterface $category,
                  $excludedCategories = []
              ): ?QueryInterface {
                  $rootCategory = $this->getVirtualRootCategory($category);
          Severity: Minor
          Found in src/module-elasticsuite-virtual-category/Model/Rule.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

          Argument 1 (condition) is \Magento\Framework\Api\ExtensibleDataInterface|\Smile\ElasticsuiteCatalogRule\Api\Data\ConditionInterface but \Smile\ElasticsuiteVirtualCategory\Model\Rule::dataModelToArray() takes \Smile\ElasticsuiteCatalogRule\Model\Data\Condition defined at /code/src/module-elasticsuite-catalog-rule/Model/Rule.php:181
          Open

                  $this->getConditions()->setConditions([])->loadArray($this->dataModelToArray($condition));

          Assigning array<int></int> to property but \Smile\ElasticsuiteVirtualCategory\Model\Rule->instances is \Magento\Catalog\Model\Category[]
          Open

                      $this->instances[$rootCategoryId][$cacheKey] = $rootCategory;

          Suspicious array access to \Magento\Catalog\Model\Category
          Open

                  return $this->instances[$rootCategoryId][$cacheKey];

          Doc-block of getVirtualCategoryQuery has declared return type \Smile\ElasticsuiteCore\Search\Request\QueryInterface which is not a permitted replacement of the nullable return type ?\Smile\ElasticsuiteCore\Search\Request\QueryInterface declared in the signature ('?T' should be documented as 'T|null' or '?T')
          Open

               * @return QueryInterface

          TODO found
          Open

               * @TODO: manage cache in this file for getSearchQueriesByChildren,

          Argument 2 (pieces) is array{0:'getCategorySearchQuery',1:mixed,2:int,3:mixed,4:bool} but \implode() takes string[]
          Open

                  $cacheKey = implode(

          Call with 2 arg(s) to \Smile\ElasticsuiteCatalogRule\Model\Rule\Condition\Product\QueryBuilder::getSearchQuery() which only takes 1 arg(s) defined at /code/src/module-elasticsuite-catalog-rule/Model/Rule/Condition/Product/QueryBuilder.php:78
          Open

                  return $this->queryBuilder->getSearchQuery($categoryCondition, $excludedCategories);

          There are no issues that match your filters.

          Category
          Status