AbstractRoboFile::getSrcDir()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * AppserverIo\RoboTasks\AbstractRoboFile
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/robo-tasks
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\RoboTasks;
22
23
use Robo\Robo;
24
use Robo\Tasks;
25
26
/**
27
 * Abstract implementation of a Robo configuration class.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2015 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/appserver-io/robo-tasks
33
 * @link      http://www.appserver.io
34
 */
35
abstract class AbstractRoboFile extends Tasks
36
{
37
38
    /**
39
     * Load the appserver.io base tasks.
40
     *
41
     * @var \AppserverIo\RoboTasks\Base\loadTasks
42
     */
43
    use Base\loadTasks;
44
45
    /**
46
     * Initializes the default configuration.
47
     */
48
    public function __construct()
49
    {
50
51
        // initialize the default configuration
52
        Robo::config()->setDefault(sprintf('%s.%s', ConfigurationKeys::DIRS, ConfigurationKeys::SRC), sprintf('%s/src', getcwd()));
53
        Robo::config()->setDefault(sprintf('%s.%s', ConfigurationKeys::DIRS, ConfigurationKeys::VENDOR), sprintf('%s/vendor', getcwd()));
54
        Robo::config()->setDefault(sprintf('%s.%s', ConfigurationKeys::DIRS, ConfigurationKeys::TARGET), $targetDir = sprintf('%s/target', getcwd()));
55
        Robo::config()->setDefault(sprintf('%s.%s', ConfigurationKeys::DIRS, ConfigurationKeys::REPORTS), sprintf('%s/reports', $targetDir));
56
    }
57
58
    /**
59
     * The sync command implementation.
60
     *
61
     * @param array $opts The command OptionsHookDispatcher
62
     *
63
     * @return void
64
     */
65
    public function sync(array $opts = [InputOptionKeys::SRC => null, InputOptionKeys::DEST => null])
66
    {
67
        // load the task
68
        $task = $this->taskSync();
69
70
        // set source directory
71
        if (isset($opts[InputOptionKeys::SRC])) {
72
            $task->src($opts[InputOptionKeys::SRC]);
73
        }
74
75
        // set target directory
76
        if (isset($opts[InputOptionKeys::DEST])) {
77
            $task->dest($opts[InputOptionKeys::DEST]);
78
        }
79
80
        // run the task
81
        $task->run();
82
    }
83
84
    /**
85
     * Returns the source directory.
86
     *
87
     * @return string The source directory
88
     */
89
    protected function getSrcDir()
90
    {
91
        return Robo::config()->get(sprintf('%s.%s', ConfigurationKeys::DIRS, ConfigurationKeys::SRC));
92
    }
93
94
    /**
95
     * Returns the vendor directory.
96
     *
97
     * @return string The vendor directory
98
     */
99
    protected function getVendorDir()
100
    {
101
        return Robo::config()->get(sprintf('%s.%s', ConfigurationKeys::DIRS, ConfigurationKeys::VENDOR));
102
    }
103
104
    /**
105
     * Returns the reports directory.
106
     *
107
     * @return string The reports directory
108
     */
109
    protected function getReportsDir()
110
    {
111
        return Robo::config()->get(sprintf('%s.%s', ConfigurationKeys::DIRS, ConfigurationKeys::REPORTS));
112
    }
113
114
    /**
115
     * Returns the target directory.
116
     *
117
     * @return string The target directory
118
     */
119
    protected function getTargetDir()
120
    {
121
        return Robo::config()->get(sprintf('%s.%s', ConfigurationKeys::DIRS, ConfigurationKeys::TARGET));
122
    }
123
}
124