Passed
Push — main ( 95b369...5c384e )
by Michiel
17:35 queued 12s
created

SvnLogTask   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
eloc 24
dl 0
loc 66
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setLimit() 0 3 1
A getPropertyName() 0 3 1
B main() 0 28 8
A setPropertyName() 0 3 1
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\Tasks\Ext;
22
23
use Phing\Exception\BuildException;
24
25
/**
26
 * Stores the output of a log command on a workingcopy or repositoryurl in a property.
27
 * This stems from the SvnLastRevisionTask.
28
 *
29
 * @author  Anton Stöckl <[email protected]>
30
 * @author  Michiel Rook <[email protected]> (SvnLastRevisionTask)
31
 * @package phing.tasks.ext.svn
32
 * @see     VersionControl_SVN
33
 * @since   2.1.0
34
 */
35
class SvnLogTask extends SvnBaseTask
36
{
37
    private $propertyName = "svn.log";
38
    private $limit = null;
39
40
    /**
41
     * Sets the name of the property to use
42
     *
43
     * @param $propertyName
44
     */
45
    public function setPropertyName($propertyName)
46
    {
47
        $this->propertyName = $propertyName;
48
    }
49
50
    /**
51
     * Returns the name of the property to use
52
     */
53
    public function getPropertyName()
54
    {
55
        return $this->propertyName;
56
    }
57
58
    /**
59
     * Sets the max num of log entries to get from svn
60
     *
61
     * @param $limit
62
     */
63
    public function setLimit($limit)
64
    {
65
        $this->limit = (int) $limit;
66
    }
67
68
    /**
69
     * The main entry point
70
     *
71
     * @throws BuildException
72
     */
73
    public function main()
74
    {
75
        $this->setup('log');
76
77
        $switches = [];
78
        if ($this->limit > 0) {
79
            $switches['limit'] = $this->limit;
80
        }
81
82
        $output = $this->run([], $switches);
83
        $result = null;
84
85
        if ($this->oldVersion) {
86
            foreach ($output as $line) {
87
                $result .= (!empty($result)) ? "\n" : '';
88
                $result .= "{$line['REVISION']} | {$line['AUTHOR']}  | {$line['DATE']}  | {$line['MSG']}";
89
            }
90
        } else {
91
            foreach ($output['logentry'] as $line) {
92
                $result .= (!empty($result)) ? "\n" : '';
93
                $result .= "{$line['revision']} | {$line['author']}  | {$line['date']}  | {$line['msg']}";
94
            }
95
        }
96
97
        if (!empty($result)) {
98
            $this->project->setProperty($this->getPropertyName(), $result);
99
        } else {
100
            throw new BuildException("Failed to parse the output of 'svn log'.");
101
        }
102
    }
103
}
104