SkiDataStartRecordFormatParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

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