Completed
Push — master ( bc8fac...f29534 )
by WEBEWEB
01:55
created

SkiDataStartRecordFormatParser::parseLine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
rs 9.6666
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\SkiData\Parser;
13
14
use WBW\Library\Core\Argument\IntegerHelper;
15
use WBW\Library\Core\SkiData\Entity\SkiDataStartRecordFormat;
16
17
/**
18
 * SkiData start record format parser.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Library\Core\SkiData\Parser
22
 */
23
class SkiDataStartRecordFormatParser extends AbstractSkiDataParser {
24
25
    /**
26
     * Constructor.
27
     */
28
    public function __construct() {
29
        parent::__construct();
30
    }
31
32
    /**
33
     * Parse a start record format entity.
34
     *
35
     * @param SkiDataStartRecordFormat $entity The start record format entity.
36
     * @return string Returns the parsed start record format entity.
37
     */
38
    public function parseEntity(SkiDataStartRecordFormat $entity) {
39
40
        // Initialise the output.
41
        $output = [];
42
43
        $output[] = $this->encodeInteger($entity->getVersionRecordStructure(), 6);
44
        $output[] = $this->encodeInteger($entity->getFacilityNumber(), 7);
45
        $output[] = $this->encodeDate($entity->getDateFile());
46
        $output[] = $this->encodeInteger($entity->getNumberRecords(), 5);
47
        $output[] = $this->encodeString($entity->getCurrency(), 6);
48
49
        // Return the output.
50
        return implode(";", $output);
51
    }
52
53
    /**
54
     * Parse a line.
55
     *
56
     * @param string $line The line.
57
     * @return SkiDataStartRecordFormat Returns a start record format entity.
58
     */
59
    public function parseLine($line) {
60
61
        // Split the line.
62
        $data = explode(";", $line);
63
        $i    = 0;
64
65
        // Initialize the entity.
66
        $entity = new SkiDataStartRecordFormat();
67
68
        $entity->setVersionRecordStructure(IntegerHelper::parseString($data[$i++]));
69
        $entity->setFacilityNumber(IntegerHelper::parseString($data[$i++]));
70
        $entity->setDateFile($this->decodeDate($data[$i++]));
71
        $entity->setNumberRecords(IntegerHelper::parseString($data[$i++]));
72
        $entity->setCurrency($this->decodeString($data[$i++]));
73
74
        // Return the entity.
75
        return $entity;
76
    }
77
78
}
79