Passed
Push — master ( ec5d4d...d68b8d )
by Siad
11:29
created

ClassConstants   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 49
ccs 14
cts 15
cp 0.9333
rs 10
c 1
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 21 4
A chain() 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
/**
21
 * Assembles the constants declared in a PHP class in
22
 * <code>key1=value1(PHP_EOL)key2=value2</code>
23
 * format.
24
 *
25
 * @author Siad Ardroumli <[email protected]>
26
 * @package phing.filters
27
 */
28
class ClassConstants extends BaseFilterReader implements ChainableReader
29
{
30
    private $test = '';
0 ignored issues
show
introduced by
The private property $test is not used, and could be removed.
Loading history...
31
32
    /**
33
     * Returns the filtered stream.
34
     *
35
     * @param int $len
36
     * @return mixed the filtered stream, or -1 if the end of the resulting stream has been reached.
37
     *
38
     * @throws IOException if the underlying stream throws an IOException
39
     * during reading
40
     */
41 1
    public function read($len = null)
42
    {
43 1
        $buffer = $this->in->read();
44
45 1
        if ($buffer === -1) {
46
            return -1;
47
        }
48
49 1
        $classes = get_declared_classes();
50 1
        eval($buffer);
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
51 1
        $newClasses = array_diff(get_declared_classes(), $classes);
52
53 1
        $sb = '';
54 1
        foreach ($newClasses as $name) {
55 1
            $clazz = new ReflectionClass($name);
56 1
            foreach ($clazz->getConstants() as $key => $value) {
57 1
                $sb .= $key . '=' . $value . PHP_EOL;
58
            }
59
        }
60
61 1
        return $sb;
62
    }
63
64
    /**
65
     * Creates a new ExpandProperties filter using the passed in
66
     * Reader for instantiation.
67
     *
68
     * @param Reader $reader A Reader object providing the underlying stream.
69
     *               Must not be <code>null</code>.
70
     *
71
     * @return ExpandProperties A new filter based on this configuration, but filtering
72
     *                the specified reader
73
     */
74 1
    public function chain(Reader $reader): Reader
75
    {
76 1
        return new self($reader);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new self($reader) returns the type ClassConstants which is incompatible with the documented return type ExpandProperties.
Loading history...
77
    }
78
}
79