Test Failed
Push — master ( 2d53c5...8b1ae1 )
by Kirill
02:39
created

OpcodeHeap::getIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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 Heap
17
 */
18
class OpcodeHeap implements \IteratorAggregate
19
{
20
    /**
21
     * @var \SplDoublyLinkedList
22
     */
23
    private $opcodes;
24
25
    /**
26
     * @var Context
27
     */
28
    private $ctx;
29
30
    /**
31
     * Heap constructor.
32
     * @param Context $ctx
33
     */
34
    public function __construct(Context $ctx)
35
    {
36
        $this->opcodes = new \SplDoublyLinkedList();
37
        $this->opcodes->setIteratorMode(\SplDoublyLinkedList::IT_MODE_FIFO);
38
        $this->ctx = $ctx;
39
    }
40
41
    /**
42
     * @param Opcode $opcode
43
     * @param Readable $readable
44
     * @param int $offset
45
     * @return JoinableOpcode
46
     */
47
    public function add(Opcode $opcode, Readable $readable, int $offset = 0): JoinableOpcode
48
    {
49
        $id = $this->opcodes->count();
50
51
        $joinable = $opcode->join($id, $readable, $offset);
52
53
        $this->opcodes->push($joinable);
54
55
        $this->ctx->match($joinable);
56
57
        return $joinable;
58
    }
59
60
    /**
61
     * @return \SplDoublyLinkedList|JoinableOpcode[]|OpcodeInterface[]
62
     */
63
    public function getIterator(): \SplDoublyLinkedList
64
    {
65
        return $this->opcodes;
66
    }
67
}
68