Passed
Push — main ( 28d658...6dddcc )
by Michiel
06:12
created

TaskAdapter   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 52.17%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 27
c 1
b 0
f 0
dl 0
loc 68
ccs 12
cts 23
cp 0.5217
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setProxy() 0 3 1
A getProxy() 0 3 1
B main() 0 34 7
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing;
22
23
use Exception;
24
use Phing\Dispatch\DispatchUtils;
25
use Phing\Exception\BuildException;
26
27
/**
28
 * Use introspection to "adapt" an arbitrary ( not extending Task, but with
29
 * similar patterns).
30
 *
31
 * @author    Andreas Aderhold <[email protected]>
32
 * @copyright 2001,2002 THYRELL. All rights reserved
33
 */
34
class TaskAdapter extends Task implements TypeAdapter
35
{
36
    /**
37
     * target object.
38
     */
39
    private $proxy;
40
41
    /**
42
     * Main entry point.
43
     *
44
     * @throws Exception
45
     * @throws BuildException
46
     */
47 230
    public function main()
48
    {
49 230
        if (method_exists($this->proxy, 'setLocation')) {
50
            try { // try to set location
51 230
                $this->proxy->setLocation($this->getLocation());
52
            } catch (Exception $ex) {
53
                $this->log('Error setting location in ' . get_class($this->proxy) . Project::MSG_ERR);
54
55
                throw new BuildException($ex);
56
            }
57
        } else {
58
            throw new Exception('Error setting location in class ' . get_class($this->proxy));
59
        }
60
61 230
        if (method_exists($this->proxy, 'setProject')) {
62
            try { // try to set project
63 230
                $this->proxy->setProject($this->project);
64
            } catch (Exception $ex) {
65
                $this->log('Error setting project in ' . get_class($this->proxy) . Project::MSG_ERR);
66
67
                throw new BuildException($ex);
68
            }
69
        } else {
70
            throw new Exception('Error setting project in class ' . get_class($this->proxy));
71
        }
72
73
        try { //try to call main
74 230
            DispatchUtils::main($this->proxy);
75 9
        } catch (BuildException $be) {
76 9
            throw $be;
77
        } catch (Exception $ex) {
78
            $this->log('Error in ' . get_class($this->proxy), Project::MSG_ERR);
79
80
            throw new BuildException('Error in ' . get_class($this->proxy), $ex);
81
        }
82
    }
83
84
    /**
85
     * Set the target object.
86
     *
87
     * @param object $o
88
     */
89 232
    public function setProxy($o)
90
    {
91 232
        $this->proxy = $o;
92
    }
93
94
    /**
95
     * Gets the target object.
96
     *
97
     * @return object
98
     */
99 232
    public function getProxy()
100
    {
101 232
        return $this->proxy;
102
    }
103
}
104