Issues (12)

src/ListParser.php (1 issue)

1
<?php
2
3
namespace petitparser;
4
5
/**
6
 * Abstract parser that parses a list of things in some way.
7
 *
8
 * @property-read Parser[] $children
9
 */
10
abstract class ListParser extends Parser
11
{
12
    /**
13
     * @var Parser[]
14
     */
15
    protected $_parsers;
16
17
    /**
18
     * @param Parser[] $parsers
19
     */
20 1
    public function __construct($parsers)
21
    {
22 1
        $this->_parsers = $parsers;
23 1
    }
24
25
    /**
26
     * @see $children
27
     */
28 1
    public function getChildren()
29
    {
30 1
        return $this->_parsers;
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36 1
    public function replace(Parser $source, Parser $target)
37
    {
38 1
        parent::replace($source, $target);
39
40 1
        for ($i=0; $i < count($this->_parsers); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
Consider avoiding function calls on each iteration of the for loop.

If you have a function call in the test part of a for loop, this function is executed on each iteration. Often such a function, can be moved to the initialization part and be cached.

// count() is called on each iteration
for ($i=0; $i < count($collection); $i++) { }

// count() is only called once
for ($i=0, $c=count($collection); $i<$c; $i++) { }
Loading history...
41 1
            if ($this->_parsers[$i] == $source) {
42 1
                $this->_parsers[$i] = $target;
43 1
            }
44 1
        }
45 1
    }
46
}
47