BuildAddonsTask   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 60
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 20 4
A log() 0 4 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
46
        foreach ($addons as $addon) {
47
            /** @var Addon $addon */
48
            $this->log(sprintf('Building "%s"', $addon->Name));
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...
49
            try {
50
                $this->builder->build($addon);
51
            } catch (RuntimeException $e) {
52
                $this->log('Error: ' . $e->getMessage());
53
            }
54
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
     * @param string $msg
62
     */
63
    protected function log($msg)
64
    {
65
        echo $msg . PHP_EOL;
66
    }
67
}
68