AbstractTask::setOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Vectorface\SnappyRouter\Task;
4
5
use Vectorface\SnappyRouter\Di\Di;
6
use Vectorface\SnappyRouter\Di\DiProviderInterface;
7
8
/**
9
 * An abstract base task class to be extended when writing custom cli tasks.
10
 * @copyright Copyright (c) 2014, VectorFace, Inc.
11
 * @author Dan Bruce <[email protected]>
12
 */
13
class AbstractTask implements DiProviderInterface, TaskInterface
14
{
15
    // an array of cli handler options
16
    private $options;
17
18
    /**
19
     * Initializes the cli task from the given configuration.
20
     * @param array $options The task options.
21
     */
22 2
    public function init($options)
23
    {
24 2
        $this->setOptions($options);
25 2
    }
26
27
    /**
28
     * Returns the current set of options.
29
     * @return array The current set of options.
30
     */
31 1
    public function getOptions()
32
    {
33 1
        return $this->options;
34
    }
35
36
    /**
37
     * Sets the current set of options.
38
     * @param array $options The set of options.
39
     * @return AbstractTask Returns $this.
40
     */
41 2
    public function setOptions($options)
42
    {
43 2
        $this->options = $options;
44 2
        return $this;
45
    }
46
47
    /**
48
     * Retrieve an element from the DI container.
49
     * @param string $key The DI key.
50
     * @param boolean $useCache (optional) An optional indicating whether we
51
     *        should use the cached version of the element (true by default).
52
     * @return mixed Returns the DI element mapped to that key.
53
     */
54 1
    public function get($key, $useCache = true)
55
    {
56 1
        return Di::getDefault()->get($key, $useCache);
57
    }
58
59
    /**
60
     * Sets an element in the DI container for the specified key.
61
     * @param string $key The DI key.
62
     * @param mixed  $element The DI element to store.
63
     * @return Di Returns the Di instance.
64
     */
65 1
    public function set($key, $element)
66
    {
67 1
        return Di::getDefault()->set($key, $element);
68
    }
69
}
70