Completed
Pull Request — master (#5)
by Valentin
03:04
created

StatementsInjector::injectionID()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Spiral Framework. Cycle ProxyFactory
5
 *
6
 * @license MIT
7
 * @author  Valentin V (vvval)
8
 */
9
declare(strict_types=1);
10
11
namespace Cycle\ORM\Promise;
12
13
use PhpParser\Node;
14
15
class StatementsInjector
16
{
17
    /**
18
     * @param Node\Stmt[] $stmts $stmts
19
     * @param string      $target
20
     * @param Node\Stmt[] $injection
21
     * @return Node\Stmt[]
22
     */
23
    public function inject(array $stmts, string $target, array $injection): array
24
    {
25
        return injectValues($stmts, $this->injectionID($stmts, $target), $injection);
26
    }
27
28
    /**
29
     * @param Node\Stmt[] $stmts
30
     * @param string      $target
31
     * @return int
32
     */
33
    private function injectionID(array $stmts, string $target): int
34
    {
35
        foreach ($stmts as $index => $child) {
36
            if ($child instanceof $target) {
37
                return $index;
38
            }
39
        }
40
41
        return 0;
42
    }
43
}
44