DataObjectAnnotatorTask::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
51
        }
52
53
        /* @var $annotator DataObjectAnnotator */
54
        $annotator = DataObjectAnnotator::create();
55
56
        $annotator->annotateObject($request->getVar('object'));
57
58
        $annotator->annotateModule($request->getVar('module'));
59
60
        return true;
0 ignored issues
show
Bug Best Practice introduced by
The expression return true returns the type true which is incompatible with the return type mandated by SilverStripe\Dev\BuildTask::run() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
61
    }
62
}
63