Smile-SA/elasticsuite

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

Summary

Maintainability
C
1 day
Test Coverage

Rule has 16 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

    File Rule.php has 263 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 2 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 15 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 1 hr to fix

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

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

            private function getVirtualRootCategory(CategoryInterface $category): ?CategoryInterface
            {
                $storeId      = $this->getStoreId();
                $rootCategory = $this->categoryFactory->create()->setStoreId($storeId);
        
        
        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 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

        TODO found
        Open

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

        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

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

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

        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);

        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));

        There are no issues that match your filters.

        Category
        Status