Passed
Push — master ( f27e95...6a73f4 )
by Chema
08:35 queued 11s
created

EdifactParser::__clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EdifactParser;
6
7
use EDI\Parser;
8
use EdifactParser\Exception\InvalidFile;
9
10
use EdifactParser\Segments\SegmentFactory;
11
use EdifactParser\Segments\SegmentFactoryInterface;
12
13
/** @psalm-immutable */
14
final class EdifactParser
15
{
16
    private SegmentFactoryInterface $segmentFactory;
17
18 4
    public static function create(?SegmentFactoryInterface $segmentFactory = null): self
19
    {
20 4
        return new self($segmentFactory ?? new SegmentFactory());
21
    }
22
23 4
    private function __construct(SegmentFactoryInterface $segmentFactory)
24
    {
25 4
        $this->segmentFactory = $segmentFactory;
26 4
    }
27
28
    /** @codeCoverageIgnore */
29
    private function __clone()
30
    {
31
    }
32
33
    /** @psalm-return list<TransactionMessage> */
34 4
    public function parse(string $fileContent): array
35
    {
36 4
        $parser = new Parser($fileContent);
37 4
        $errors = $parser->errors();
38
39 4
        if ($errors) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $errors of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
40 1
            throw InvalidFile::withErrors($errors);
41
        }
42
43 3
        $segments = SegmentList::factory($this->segmentFactory)->fromRaw($parser->get());
44
45 3
        return TransactionMessage::groupSegmentsByMessage(...$segments);
46
    }
47
}
48