Passed
Pull Request — master (#5)
by Gordon
01:54
created

CreateIndexTask   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 2
b 0
f 0
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 15 4
1
<?php declare(strict_types = 1);
2
3
/**
4
 * Created by PhpStorm.
5
 * User: gordon
6
 * Date: 25/3/2561
7
 * Time: 17:01 น.
8
 */
9
10
namespace Suilven\FreeTextSearch\Task;
11
12
use SilverStripe\Control\Director;
13
use SilverStripe\Dev\BuildTask;
14
use Suilven\FreeTextSearch\Factory\IndexCreatorFactory;
15
16
class CreateIndexTask extends BuildTask
17
{
18
19
    protected $title = 'Create Index';
20
21
    protected $description = 'Create an index of a given name';
22
23
    protected $enabled = true;
24
25
    private static $segment = 'create-index';
0 ignored issues
show
introduced by
The private property $segment is not used, and could be removed.
Loading history...
26
27
    public function run(\SilverStripe\Control\HTTPRequest $request)
28
    {
29
        // check this script is being run by admin
30
        $canAccess = (Director::isDev() || Director::is_cli() || Permission::check("ADMIN"));
0 ignored issues
show
Bug introduced by
The type Suilven\FreeTextSearch\Task\Permission 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...
31
        if (!$canAccess) {
32
            return Security::permissionFailure($this);
0 ignored issues
show
Bug introduced by
The type Suilven\FreeTextSearch\Task\Security was not found. Did you mean Security? If so, make sure to prefix the type with \.
Loading history...
33
        }
34
35
        $name = $request->param('index');
36
37
        $factory = new IndexCreatorFactory();
38
        $indexCreator = $factory->getIndexCreator();
39
40
        // @todo Does the index need dropped prior to re-creation?
41
        $indexCreator->createIndex($name);
42
    }
43
}
44