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

SkiDataCardParser::parseEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
c 0
b 0
f 0
rs 9.312
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\BooleanHelper;
15
use WBW\Library\Core\Argument\IntegerHelper;
16
use WBW\Library\Core\SkiData\Entity\SkiDataCard;
17
18
/**
19
 * SkiData card parser.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Library\Core\SkiData\Parser
23
 */
24
class SkiDataCardParser extends AbstractSkiDataParser {
25
26
    /**
27
     * Constructor.
28
     */
29
    public function __construct() {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Parse a card entity.
35
     *
36
     * @param SkiDataCard $entity The card entity.
37
     * @return string Returns the parsed card entity.
38
     */
39
    public function parseEntity(SkiDataCard $entity) {
40
41
        // Initialise the output.
42
        $output = [];
43
44
        $output[] = $this->encodeString($entity->getTicketNumber(), 23);
45
        $output[] = $this->encodeInteger($entity->getUserNumber(), 9);
46
        $output[] = $this->encodeInteger($entity->getArticleNumber(), 3);
47
        $output[] = $this->encodeDate($entity->getValidFrom());
48
        $output[] = $this->encodeDate($entity->getExpires());
49
        $output[] = $this->encodeBoolean($entity->getBlocked());
50
        $output[] = $this->encodeDate($entity->getBlockedDate());
51
        $output[] = $this->encodeInteger($entity->getProductionState(), 1);
52
        $output[] = $this->encodeInteger($entity->getReasonProduction(), 1);
53
        $output[] = $this->encodeInteger($entity->getProductionCounter(), 4);
54
        $output[] = $this->encodeBoolean($entity->getNeutral());
55
        $output[] = $this->encodeBoolean($entity->getRetainTicketEntry());
56
        $output[] = $this->encodeBoolean($entity->getEntryBarrierClosed());
57
        $output[] = $this->encodeBoolean($entity->getExitBarrierClosed());
58
        $output[] = $this->encodeBoolean($entity->getRetainTicketExit());
59
        $output[] = $this->encodeBoolean($entity->getDisplayText());
60
        $output[] = $this->encodeString($entity->getDisplayText1(), 16);
61
        $output[] = $this->encodeString($entity->getDisplayText2(), 16);
62
        $output[] = $this->encodeInteger($entity->getPersonnalNo(), 4);
63
        $output[] = $this->encodeInteger($entity->getResidualValue(), 12);
64
        $output[] = $this->encodeString($entity->getSerialNumberKeyCardSwatch(), 20);
65
        $output[] = $this->encodeString($entity->getCurrencyResidualValue(), 3);
66
        $output[] = $this->encodeInteger($entity->getTicketType(), 1);
67
        $output[] = $this->encodeString($entity->getTicketSubType(), 5);
68
        $output[] = $this->encodeString($entity->getSerialNo(), 30);
69
        $output[] = $this->encodeDate($entity->getSuspendPeriodFrom());
70
        $output[] = $this->encodeDate($entity->getSuspendPeriodUntil());
71
        $output[] = $this->encodeBoolean($entity->getUseValidCarParks());
72
        $output[] = $this->encodeInteger($entity->getProductionFacilityNumber(), 7);
73
74
        // Return the output.
75
        return implode(";", $output);
76
    }
77
78
    /**
79
     * Parse a line.
80
     *
81
     * @param string $line The line.
82
     * @return SkiDataCard Returns a card entity.
83
     */
84
    public function parseLine($line) {
85
86
        // Split the line.
87
        $data = explode(";", $line);
88
        $i    = 0;
89
90
        // Initialize the entity.
91
        $entity = new SkiDataCard();
92
93
        $entity->setTicketNumber($this->decodeString($data[$i++]));
94
        $entity->setUserNumber(IntegerHelper::parseString($data[$i++]));
95
        $entity->setArticleNumber(IntegerHelper::parseString($data[$i++]));
96
        $entity->setValidFrom($this->decodeDate($data[$i++]));
97
        $entity->setExpires($this->decodeDate($data[$i++]));
98
        $entity->setBlocked(BooleanHelper::parseString($data[$i++]));
99
        $entity->setBlockedDate($this->decodeDate($data[$i++]));
100
        $entity->setProductionState(IntegerHelper::parseString($data[$i++]));
101
        $entity->setReasonProduction(IntegerHelper::parseString($data[$i++]));
102
        $entity->setProductionCounter(IntegerHelper::parseString($data[$i++]));
103
        $entity->setNeutral(BooleanHelper::parseString($data[$i++]));
104
        $entity->setRetainTicketEntry(BooleanHelper::parseString($data[$i++]));
105
        $entity->setEntryBarrierClosed(BooleanHelper::parseString($data[$i++]));
106
        $entity->setExitBarrierClosed(BooleanHelper::parseString($data[$i++]));
107
        $entity->setRetainTicketExit(BooleanHelper::parseString($data[$i++]));
108
        $entity->setDisplayText(BooleanHelper::parseString($data[$i++]));
109
        $entity->setDisplayText1($this->decodeString($data[$i++]));
110
        $entity->setDisplayText2($this->decodeString($data[$i++]));
111
        $entity->setPersonnalNo(IntegerHelper::parseString($data[$i++]));
112
        $entity->setResidualValue(IntegerHelper::parseString($data[$i++]));
113
        $entity->setSerialNumberKeyCardSwatch($this->decodeString($data[$i++]));
114
        $entity->setCurrencyResidualValue($this->decodeString($data[$i++]));
115
        $entity->setTicketType(IntegerHelper::parseString($data[$i++]));
116
        $entity->setTicketSubType($this->decodeString($data[$i++]));
117
        $entity->setSerialNo($this->decodeString($data[$i++]));
118
        $entity->setSuspendPeriodFrom($this->decodeDate($data[$i++]));
119
        $entity->setSuspendPeriodUntil($this->decodeDate($data[$i++]));
120
        $entity->setUseValidCarParks(BooleanHelper::parseString($data[$i++]));
121
        $entity->setProductionFacilityNumber(IntegerHelper::parseString($data[$i++]));
122
123
        // Return the entity.
124
        return $entity;
125
    }
126
127
}
128