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

OpcodeHeap   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

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