RecordSet::count()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace BasePatterns\RecordSet;
6
7
use Countable;
8
use Traversable;
9
10
class RecordSet implements Countable
11
{
12
    private array $tables = [];
13
14
    private int $count = 0;
15
16 4
    public function getTable(string $tableName): Table
17
    {
18 4
        if (\array_key_exists($tableName, $this->tables) === false) {
19
            throw new NoTableFoundException($tableName);
20
        }
21
22 4
        return $this->tables[$tableName];
23
    }
24
25 4
    public function load(Traversable $traversable, string $tableName): void
26
    {
27 4
        $this->tables[$tableName] = new Table($tableName);
28 4
        $rows = [];
29 4
        foreach ($traversable as $row) {
30 4
            $rows[] = new Row($row);
31
        }
32 4
        $this->tables[$tableName]->load($rows);
33 4
        $this->count += \count($rows);
34 4
    }
35
36 3
    public function count(): int
37
    {
38 3
        return $this->count;
39
    }
40
}
41