Passed
Push — master ( 8f83e8...e4d779 )
by Chema
02:15
created

EdifactParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 22
rs 10
c 0
b 0
f 0
ccs 10
cts 10
cp 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A parse() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EdifactParser;
6
7
use EDI\Parser;
8
use EdifactParser\Exception\InvalidFile;
9
use EdifactParser\Segments\CustomSegmentFactoryInterface;
10
11
final class EdifactParser
12
{
13
    /** @var CustomSegmentFactoryInterface|null */
14
    private $customSegmentsFactory;
15
16 4
    public function __construct(?CustomSegmentFactoryInterface $customSegmentsFactory = null)
17
    {
18 4
        $this->customSegmentsFactory = $customSegmentsFactory;
19 4
    }
20
21 4
    public function parse(string $fileContent): TransactionResult
22
    {
23 4
        $parser = new Parser($fileContent);
24 4
        $errors = $parser->errors();
25
26 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...
27 1
            throw InvalidFile::withErrors($errors);
28
        }
29
30 3
        $segmentedValues = SegmentedValues::fromRaw($parser->get(), $this->customSegmentsFactory);
31
32 3
        return TransactionResult::fromSegmentedValues($segmentedValues);
33
    }
34
}
35