Passed
Push — master ( b5ca42...8fe651 )
by Siad
05:05
created

AutoloaderTask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 44
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setAutoloaderPath() 0 3 1
A main() 0 12 3
A getAutoloaderPath() 0 3 1
1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19
20
use Phing\Exception\BuildException;
21
use Phing\Task;
22
23
/**
24
 * @author Max Romanovsky <[email protected]>
25
 * @package phing.tasks.ext
26
 */
27
class AutoloaderTask extends Task
28
{
29
    public const DEFAULT_AUTOLOAD_PATH = 'vendor/autoload.php';
30
31
    private $autoloaderPath = self::DEFAULT_AUTOLOAD_PATH;
32
33
    /**
34
     * @return string
35
     */
36
    public function getAutoloaderPath()
37
    {
38
        return $this->autoloaderPath;
39
    }
40
41
    /**
42
     * @param string $autoloaderPath
43
     */
44 1
    public function setAutoloaderPath($autoloaderPath)
45
    {
46 1
        $this->autoloaderPath = $autoloaderPath;
47 1
    }
48
49
    /**
50
     *  Called by the project to let the task do it's work. This method may be
51
     *  called more than once, if the task is invoked more than once. For
52
     *  example, if target1 and target2 both depend on target3, then running
53
     *  <em>phing target1 target2</em> will run all tasks in target3 twice.
54
     *
55
     *  Should throw a BuildException if someting goes wrong with the build
56
     *
57
     *  This is here. Must be overloaded by real tasks.
58
     */
59 2
    public function main()
60
    {
61 2
        if (is_dir($this->autoloaderPath) || !is_readable($this->autoloaderPath)) {
62 1
            throw new BuildException(
63 1
                sprintf(
64 1
                    'Provided autoloader file "%s" is not a readable file',
65 1
                    $this->autoloaderPath
66
                )
67
            );
68
        }
69 1
        $this->log('Loading autoloader from ' . $this->autoloaderPath);
70 1
        include_once $this->autoloaderPath;
71 1
    }
72
}
73