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

LazyArray   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 18
ccs 5
cts 5
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 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