FulltextIndex::ensureTablesAreCreated()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 6
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace TddWizard\Fixtures\Catalog;
5
6
use Magento\Indexer\Model\IndexerFactory;
7
use Magento\TestFramework\Helper\Bootstrap;
0 ignored issues
show
Bug introduced by
The type Magento\TestFramework\Helper\Bootstrap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
/**
10
 * Can run the fulltext catalog index once from tests to ensure that tables for all stores are created
11
 */
12
class FulltextIndex
13
{
14
    /**
15
     * @var bool
16
     */
17
    private static $created = false;
18
19
    /**
20
     * @var IndexerFactory
21
     */
22
    private $indexerFactory;
23
24
    public function __construct(IndexerFactory $indexerFactory)
25
    {
26
        $this->indexerFactory = $indexerFactory;
27
    }
28
29
    /**
30
     * @throws \Throwable
31
     */
32
    public static function ensureTablesAreCreated(): void
33
    {
34
        if (!self::$created) {
35
            (new self(Bootstrap::getObjectManager()->create(IndexerFactory::class)))->reindex();
36
        }
37
    }
38
39
    /**
40
     * @throws \Throwable
41
     */
42
    public function reindex(): void
43
    {
44
        $indexer = $this->indexerFactory->create();
45
        $indexer->load('catalogsearch_fulltext');
46
        $indexer->reindexAll();
47
    }
48
}
49