Parser::loadFromString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Beccha\OfxParser;
6
7
use Beccha\OfxParser\Service\SgmlToXml;
8
use Exception;
9
use InvalidArgumentException;
10
11
class Parser
12
{
13
    /**
14
     * Load an OFX file into this parser by way of a filename
15
     * @throws InvalidArgumentException
16
     * @throws Exception
17
     */
18
    public function loadFromFile(string $ofxFile): Ofx
19
    {
20
        if (false === file_exists($ofxFile)) {
21
            throw new InvalidArgumentException("File '$ofxFile' could not be found");
22
        }
23
24
        return $this->loadFromString($ofxFile);
25
    }
26
27
    /**
28
     * Load an OFX by directly using the text content
29
     * @throws Exception
30
     */
31
    public function loadFromString(string $filePath): Ofx
32
    {
33
        $xmlFromSgml = new SgmlToXml();
34
        $xml = $xmlFromSgml->parse($filePath);
35
36
        return new Ofx($xml);
37
    }
38
}
39