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

ClassConstants::read()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4.0072

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
nc 4
nop 1
dl 0
loc 21
ccs 12
cts 13
cp 0.9231
crap 4.0072
rs 9.8666
c 1
b 0
f 0
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