Passed
Push — PSR-11-2 ( e86d47...dfb1a3 )
by Nikolaos
05:09
created

LazyArray::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 10
cc 3
nc 3
nop 0
crap 3
1
<?php
2
3
/**
4
 * This file is part of the Phalcon Framework.
5
 *
6
 * (c) Phalcon Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 *
11
 * Implementation of this file has been influenced by AuraPHP
12
 *
13
 * @link    https://github.com/auraphp/Aura.Di
14
 * @license https://github.com/auraphp/Aura.Di/blob/4.x/LICENSE
15
 */
16
17
declare(strict_types=1);
18
19
namespace Phalcon\Container\Injection;
20
21
use ArrayObject;
22
23
/**
24
 * Returns the value of a callable when invoked (thereby invoking the callable).
25
 */
26
class LazyArray extends ArrayObject implements LazyInterface
27
{
28
    /**
29
     * Invoke any LazyInterface in the array.
30
     *
31
     * @return array The array of potentially invoked items.
32
     */
33 4
    public function __invoke()
34
    {
35
        // convert Lazy objects in the callables
36 4
        foreach ($this as $key => $val) {
37 3
            if ($val instanceof LazyInterface) {
38 3
                $this[$key] = $val();
39
            }
40
        }
41
42
        // return array
43 4
        return $this->getArrayCopy();
44
    }
45
}
46