Passed
Push — master ( 8f9505...f00c46 )
by Michiel
07:03
created

SubPhingTest.php$0 ➔ baseDirs()   B

Complexity

Conditions 2

Size

Total Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 65
rs 8.7636
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A SubPhingTest.php$0 ➔ targetStarted() 0 13 4
A SubPhingTest.php$0 ➔ messageLogged() 0 2 1
A SubPhingTest.php$0 ➔ __construct() 0 3 1
A SubPhingTest.php$0 ➔ buildStarted() 0 2 1
A SubPhingTest.php$0 ➔ getError() 0 3 1
A SubPhingTest.php$0 ➔ targetFinished() 0 2 1
A SubPhingTest.php$0 ➔ taskStarted() 0 2 1
A SubPhingTest.php$0 ➔ buildFinished() 0 2 1
A SubPhingTest.php$0 ➔ taskFinished() 0 2 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Listener\BuildEvent;
21
use Phing\Listener\BuildListener;
22
23
/**
24
 * Tests the SubPhing Task
25
 *
26
 * @author  Siad Ardroumli <[email protected]>
27
 * @package phing.tasks.system
28
 */
29
class SubPhingTest extends BuildFileTest
30
{
31
    public function setUp(): void
32
    {
33
        $this->configureProject(
34
            PHING_TEST_BASE . '/etc/tasks/system/subphing.xml'
35
        );
36
    }
37
38
    public function testNoDirs(): void
39
    {
40
        $this->expectLog(__FUNCTION__, 'No sub-builds to iterate on');
41
    }
42
43
    public function testGenericPhingFile(): void
44
    {
45
        $dir1 = $this->getProject()->resolveFile('.');
46
        $dir2 = $this->getProject()->resolveFile('subphing/subphing-test1');
47
        $dir3 = $this->getProject()->resolveFile('subphing/subphing-test2');
48
49
        $this->baseDirs(
50
            __FUNCTION__,
51
            [
52
                $dir1->getAbsolutePath(),
53
                $dir2->getAbsolutePath(),
54
                $dir3->getAbsolutePath()
55
            ]
56
        );
57
    }
58
59
    public function testPhingFile(): void
60
    {
61
        $dir1 = $this->getProject()->resolveFile('.');
62
        // basedir of subphing/subphing-test1/subphing.xml is ..
63
        // therefore we expect here the subphing/subphing-test1 subdirectory
64
        $dir2 = $this->getProject()->resolveFile('subphing/subphing-test1');
65
        // basedir of subphing/subphing-test2/subphing.xml is ..
66
        // therefore we expect here the subphing subdirectory
67
        $dir3 = $this->getProject()->resolveFile('subphing');
68
69
        $this->baseDirs(
70
            __FUNCTION__,
71
            [
72
                $dir1->getAbsolutePath(),
73
                $dir2->getAbsolutePath(),
74
                $dir3->getAbsolutePath()
75
            ]
76
        );
77
    }
78
79
    public function testPhingVersion()
80
    {
81
        $this->markTestSkipped('Please review!');
82
        $this->executeTarget(__FUNCTION__);
83
        $this->assertPropertySet('version');
84
        $this->assertPropertySet('home');
85
        $this->assertPropertySet('classpath');
86
    }
87
88
    /**
89
     * @param string $target
90
     * @param array $dirs
91
     */
92
    private function baseDirs(string $target, array $dirs): void
93
    {
94
        $bc = new class ($dirs) implements BuildListener {
95
            private $expectedBasedirs;
96
            private $calls = 0;
97
            private $error;
98
99
            public function __construct(array $dirs)
100
            {
101
                $this->expectedBasedirs = $dirs;
102
            }
103
104
            public function buildStarted(BuildEvent $event)
105
            {
106
            }
107
108
            public function buildFinished(BuildEvent $event)
109
            {
110
            }
111
112
            public function targetFinished(BuildEvent $event)
113
            {
114
            }
115
116
            public function taskStarted(BuildEvent $event)
117
            {
118
            }
119
120
            public function taskFinished(BuildEvent $event)
121
            {
122
            }
123
124
            public function messageLogged(BuildEvent $event)
125
            {
126
            }
127
128
            public function targetStarted(BuildEvent $event)
129
            {
130
                if ($event->getTarget()->getName() === '') {
131
                    return;
132
                }
133
                if ($this->error === null) {
134
                    try {
135
                        BuildFileTest::assertEquals(
136
                            $this->expectedBasedirs[$this->calls++],
137
                            $event->getProject()->getBaseDir()->getAbsolutePath()
138
                        );
139
                    } catch (AssertionError $e) {
140
                        $this->error = $e;
141
                    }
142
                }
143
            }
144
145
            public function getError()
146
            {
147
                return $this->error;
148
            }
149
        };
150
        $this->getProject()->addBuildListener($bc);
151
        $this->executeTarget($target);
152
        $ae = $bc->getError();
153
        if ($ae !== null) {
154
            throw $ae;
155
        }
156
        $this->getProject()->removeBuildListener($bc);
157
    }
158
}
159