Test Failed
Push — master ( e081e8...a6938b )
by Kirill
02:31
created

Collection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 12 1
A getIterator() 0 4 1
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Frontend\IR;
11
12
use Railt\Io\Readable;
13
use Railt\SDL\Frontend\Context;
14
15
/**
16
 * Class Collection
17
 */
18
class Collection implements \IteratorAggregate
19
{
20
    /**
21
     * @var int
22
     */
23
    private static $lastId = 0;
24
25
    /**
26
     * @var array|OpcodeInterface[]
27
     */
28
    private $opcodes = [];
29
30
    /**
31
     * @var Context
32
     */
33
    private $ctx;
34
35
    /**
36
     * Heap constructor.
37
     * @param Context $ctx
38
     */
39
    public function __construct(Context $ctx)
40
    {
41
        $this->ctx = $ctx;
42
    }
43
44
    /**
45
     * @param OpcodeInterface|Opcode $opcode
46
     * @param Readable $readable
47
     * @param int $offset
48
     * @return Opcode|OpcodeInterface
49
     */
50
    public function add(OpcodeInterface $opcode, Readable $readable, int $offset = 0): OpcodeInterface
51
    {
52
        $id = self::$lastId++;
53
54
        $joinable = $opcode->mount($id, $readable, $offset);
55
56
        $this->opcodes[$id] = $joinable;
57
58
        $this->ctx->match($joinable);
59
60
        return $joinable;
61
    }
62
63
    /**
64
     * @return \SplDoublyLinkedList|Opcode[]|OpcodeInterface[]
65
     */
66
    public function getIterator(): iterable
67
    {
68
        yield from $this->opcodes;
69
    }
70
}
71