Completed
Push — master ( eed8c4...bd454a )
by WEBEWEB
02:23
created

StartRecordFormatParser::parseLine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
rs 9.7998
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Core\ThirdParty\SkiData\Parser;
13
14
use WBW\Library\Core\Argument\IntegerHelper;
15
use WBW\Library\Core\Exception\Argument\IntegerArgumentException;
16
use WBW\Library\Core\ThirdParty\SkiData\Exception\TooLongDataException;
17
use WBW\Library\Core\ThirdParty\SkiData\Model\StartRecordFormat;
18
19
/**
20
 * Start record format parser.
21
 *
22
 * @author webeweb <https://github.com/webeweb/>
23
 * @package WBW\Library\Core\ThirdParty\SkiData\Parser
24
 */
25
class StartRecordFormatParser extends AbstractParser {
26
27
    /**
28
     * Constructor.
29
     */
30
    public function __construct() {
31
        parent::__construct();
32
    }
33
34
    /**
35
     * Parse a start record format entity.
36
     *
37
     * @param StartRecordFormat $entity The start record format.
38
     * @return string Returns the parsed start record format.
39
     * @throws TooLongDataException Throws a too long data exception if a data is too long.
40
     */
41
    public function parseEntity(StartRecordFormat $entity) {
42
43
        $output = [
44
            $this->encodeInteger($entity->getVersionRecordStructure(), 6),
45
            $this->encodeInteger($entity->getFacilityNumber(), 7),
46
            $this->encodeDate($entity->getDateFile()),
47
            $this->encodeInteger($entity->getNumberRecords(), 5),
48
            $this->encodeString($entity->getCurrency(), 6),
49
        ];
50
51
        return implode(";", $output);
52
    }
53
54
    /**
55
     * Parse a line.
56
     *
57
     * @param string $line The line.
58
     * @return StartRecordFormat Returns a start record format entity.
59
     * @throws IntegerArgumentException Throws an integer argument exception.
60
     */
61
    public function parseLine($line) {
62
63
        $data = explode(";", $line);
64
        $i    = -1;
65
66
        $model = new StartRecordFormat();
67
        $model->setVersionRecordStructure(IntegerHelper::parseString($data[++$i]));
68
        $model->setFacilityNumber(IntegerHelper::parseString($data[++$i]));
69
        $model->setDateFile($this->decodeDate($data[++$i]));
70
        $model->setNumberRecords(IntegerHelper::parseString($data[++$i]));
71
        $model->setCurrency($this->decodeString($data[++$i]));
72
73
        return $model;
74
    }
75
}
76