Passed
Push — main ( 221f6d...f8c128 )
by Siad
05:28
created

src/Phing/Filter/ClassConstants.php (3 issues)

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