Passed
Branch master (608a5d)
by Simon
01:54
created

DataObjectAnnotatorTask::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverLeague\IDEAnnotator;
4
5
use Psr\Container\NotFoundExceptionInterface;
6
use ReflectionException;
7
use SilverStripe\Control\HTTPRequest;
8
use SilverStripe\Core\Injector\Injector;
9
use SilverStripe\Dev\BuildTask;
10
11
/**
12
 * Class DataObjectAnnotatorTask
13
 *
14
 * Task to add or remove annotations from a module or dataobject.
15
 *
16
 * @package IDEAnnotator/Tasks
17
 */
18
class DataObjectAnnotatorTask extends BuildTask
19
{
20
21
    /**
22
     * DataObjectAnnotatorTask constructor.
23
     * Setup default values. In this case title and description.
24
     */
25
    public function __construct()
26
    {
27
        parent::__construct();
28
        $this->title = 'DataObject annotations for specific DataObjects, Extensions or Controllers';
29
        $this->description = "DataObject Annotator annotates your DO's if possible, helping you write better code.<br />"
30
            . 'Usage: add the module or DataObject as parameter to the URL, e.g. ?module=mysite .';
31
    }
32
33
    /**
34
     * @param HTTPRequest $request
35
     * @return bool
36
     * @throws ReflectionException
37
     * @throws NotFoundExceptionInterface
38
     */
39
    public function run($request)
40
    {
41
        /* @var $permissionChecker AnnotatePermissionChecker */
42
        $permissionChecker = Injector::inst()->get(AnnotatePermissionChecker::class);
43
44
        if (!$permissionChecker->environmentIsAllowed()) {
45
            return false;
46
        }
47
48
        /* @var $annotator DataObjectAnnotator */
49
        $annotator = DataObjectAnnotator::create();
50
51
        $annotator->annotateObject($request->getVar('object'));
52
53
        $annotator->annotateModule($request->getVar('module'));
54
55
        return true;
56
    }
57
}
58