SolrIndexCheck   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 28 5
1
<?php
2
3
namespace SilverStripe\EnvironmentCheck\Checks;
4
5
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
6
use SilverStripe\FullTextSearch\Solr\Solr;
0 ignored issues
show
Bug introduced by
The type SilverStripe\FullTextSearch\Solr\Solr 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...
7
use SilverStripe\FullTextSearch\Solr\SolrIndex;
0 ignored issues
show
Bug introduced by
The type SilverStripe\FullTextSearch\Solr\SolrIndex 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
 * Check the availability of all Solr indexes
11
 *
12
 * If there are no indexes of given class found, the returned status will still be "OK".
13
 *
14
 * @package environmentcheck
15
 */
16
class SolrIndexCheck implements EnvironmentCheck
17
{
18
    /**
19
     * {@inheritDoc}
20
     *
21
     * @return array
22
     */
23
    public function check()
24
    {
25
        $brokenCores = [];
26
27
        if (!class_exists(Solr::class)) {
28
            return [
29
                EnvironmentCheck::ERROR,
30
                'Class `' . Solr::class . '` not found. Is the fulltextsearch module installed?'
31
            ];
32
        }
33
34
        $service = Solr::service();
35
        foreach (Solr::get_indexes() as $index) {
36
            /** @var SolrIndex $core */
37
            $core = $index->getIndexName();
38
            if (!$service->coreIsActive($core)) {
39
                $brokenCores[] = $core;
40
            }
41
        }
42
43
        if (!empty($brokenCores)) {
44
            return [
45
                EnvironmentCheck::ERROR,
46
                'The following indexes are unavailable: ' . implode($brokenCores, ', ')
0 ignored issues
show
Unused Code introduced by
The call to implode() has too many arguments starting with ', '. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
                'The following indexes are unavailable: ' . /** @scrutinizer ignore-call */ implode($brokenCores, ', ')

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
47
            ];
48
        }
49
50
        return [EnvironmentCheck::OK, 'Expected indexes are available.'];
51
    }
52
}
53