TaskAccessor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getBuiltTask() 0 6 2
A task() 0 8 1
1
<?php
2
3
namespace Robo;
4
5
use Robo\Common\BuilderAwareTrait;
6
7
trait TaskAccessor
8
{
9
    use BuilderAwareTrait;
10
11
    /**
12
     * Provides the collection builder with access to all of the
13
     * protected 'task' methods available on this object.
14
     *
15
     * @param string $fn
16
     * @param array $args
17
     *
18
     * @return null|\Robo\Collection\CollectionBuilder
19
     */
20
    public function getBuiltTask($fn, $args)
21
    {
22
        if (preg_match('#^task[A-Z]#', $fn)) {
23
            return call_user_func_array([$this, $fn], $args);
24
        }
25
    }
26
27
    /**
28
     * Alternative access to instantiate. Use:
29
     *
30
     *   $this->task(Foo::class, $a, $b);
31
     *
32
     * instead of:
33
     *
34
     *   $this->taskFoo($a, $b);
35
     *
36
     * The later form is preferred.
37
     *
38
     * @return \Robo\Collection\CollectionBuilder
39
     */
40
    protected function task()
41
    {
42
        $args = func_get_args();
43
        $name = array_shift($args);
44
45
        $collectionBuilder = $this->collectionBuilder();
46
        return $collectionBuilder->build($name, $args);
47
    }
48
}
49