BuildAddonsTask::run()   A
last analyzed

Complexity

Conditions 5
Paths 10

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.2728
c 0
b 0
f 0
cc 5
nc 10
nop 1
1
<?php
2
/**
3
 * Updates addons. Should usually be handled by a redis queue which interacts directly with
4
 * {@link BuildAddonJob}, but this task can help with debugging.
5
 *
6
 * @package mysite
7
 */
8
class BuildAddonsTask extends BuildTask
9
{
10
    /**
11
     * {@inheritDoc}
12
     * @var string
13
     */
14
    protected $title = 'Build Add-ons';
15
16
    /**
17
     * {@inheritDoc}
18
     * @var string
19
     */
20
    protected $description = 'Downloads README and screenshots';
21
22
    /**
23
     * @var AddonBuilder
24
     */
25
    protected $builder;
26
27
    /**
28
     * @param AddonBuilder $builder
29
     */
30
    public function __construct(AddonBuilder $builder)
31
    {
32
        $this->builder = $builder;
33
    }
34
35
    /**
36
     * {@inheritDoc}
37
     * @param SS_HTTPRequest $request
38
     */
39
    public function run($request)
40
    {
41
        $addons = Addon::get();
42
        if ($request->getVar('addons')) {
43
            $addons = $addons->filter('Name', explode(',', $request->getVar('addons')));
44
        }
45
        foreach ($addons as $addon) {
46
            /** @var Addon $addon */
47
            $this->log(sprintf('Building "%s" (#%d)', $addon->Name, $addon->ID));
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<Addon>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
48
            try {
49
                $this->builder->build($addon);
50
            } catch (RuntimeException $e) {
51
                $this->log('Error: ' . $e->getMessage());
52
            }
53
54
            if ($addon->ID) {
55
                $addon->BuildQueued = false;
0 ignored issues
show
Documentation introduced by
The property BuildQueued does not exist on object<Addon>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
56
                $addon->write();
57
            }
58
        }
59
    }
60
61
    /**
62
     * @param string $msg
63
     */
64
    protected function log($msg)
65
    {
66
        echo $msg . PHP_EOL;
67
    }
68
}
69