Passed
Pull Request — master (#98)
by Robbie
01:42
created

DataObjectAnnotatorTask   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 38
rs 10
c 1
b 1
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 17 2
A __construct() 0 6 1
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