InvalidBarcodeException::becauseBarcodeIsEmpty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\GS1Parser\Exception;
6
7
use InvalidArgumentException;
8
9
final class InvalidBarcodeException extends InvalidArgumentException implements GS1ParserExceptionInterface
10
{
11
    public static function becauseBarcodeIsEmpty(): self
12
    {
13
        return new static('Barcode is empty');
14
    }
15
16
    public static function becauseFNC1SequenceIsNotFound(): self
17
    {
18
        return new static('FNC1 sequence is not found at the start of barcode');
19
    }
20
21
    public static function becauseNoDataPresent(): self
22
    {
23
        return new static('Barcode does not contain data');
24
    }
25
26
    public static function becauseNotEnoughDataFoAI(string $ai, int $expectedLength, int $actualLength): self
27
    {
28
        return new static(sprintf(
29
            'Not enough data for AI "%s": %d expected but %d exists',
30
            $ai,
31
            $expectedLength,
32
            $actualLength
33
        ));
34
    }
35
36
    public static function becauseGroupSeparatorWasNotExpected(string $value): self
37
    {
38
        return new static(sprintf('Group separator was not expected in AI "%s"', $value));
39
    }
40
41
    public static function becauseValueContainsInvalidCharacters(string ...$invalidCharacters): self
42
    {
43
        return new static(sprintf(
44
            'Value contains invalid characters: %s',
45
            implode(', ', array_map(static function (string $character) {
46
                return "\"$character\"";
47
            }, $invalidCharacters))
48
        ));
49
    }
50
}
51