Test Failed
Pull Request — master (#12)
by wujunze
03:09
created

RecordValidator::validate()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 28
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 8
eloc 14
c 1
b 0
f 1
nc 8
nop 2
dl 0
loc 28
rs 8.4444
1
<?php
2
declare(strict_types=1);
3
4
namespace Seasx\SeasLogger\Kafka;
5
6
use function is_string;
7
use function trim;
8
9
/**
10
 * @internal
11
 */
12
final class RecordValidator
13
{
14
    /**
15
     * @param string[] $record
16
     * @param mixed[][] $topicList
17
     * @throws InvalidRecordInSet
18
     */
19
    public function validate(array $record, array $topicList): void
20
    {
21
        if (!isset($record['topic'])) {
22
            throw InvalidRecordInSet::missingTopic();
23
        }
24
25
        if (!is_string($record['topic'])) {
0 ignored issues
show
introduced by
The condition is_string($record['topic']) is always true.
Loading history...
26
            throw InvalidRecordInSet::topicIsNotString();
27
        }
28
29
        if (trim($record['topic']) === '') {
30
            throw InvalidRecordInSet::missingTopic();
31
        }
32
33
        if (!isset($topicList[$record['topic']])) {
34
            throw InvalidRecordInSet::nonExististingTopic($record['topic']);
35
        }
36
37
        if (!isset($record['value'])) {
38
            throw InvalidRecordInSet::missingValue();
39
        }
40
41
        if (!is_string($record['value'])) {
0 ignored issues
show
introduced by
The condition is_string($record['value']) is always true.
Loading history...
42
            throw InvalidRecordInSet::valueIsNotString();
43
        }
44
45
        if (trim($record['value']) === '') {
46
            throw InvalidRecordInSet::missingValue();
47
        }
48
    }
49
}
50