ScaleEngineTicketFactory::parseData()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 3
eloc 10
nc 3
nop 1
1
<?php
2
namespace FloSports\ScaleEngine\Model\Factory;
3
4
/**
5
 * A factory used to construct ScaleEngine ticket models.
6
 */
7
class ScaleEngineTicketFactory extends AbstractScaleEngineModelFactory
8
{
9
    /**
10
     * Create the model factory for ScaleEngine tickets.
11
     */
12
    public function __construct()
13
    {
14
        parent::__construct(
15
            '\FloSports\ScaleEngine\Model\ScaleEngineTicket',
16
            $this->_keyMap()
17
        );
18
    }
19
20
    /**
21
     * Parse the data given into correct types and changes keys based on the
22
     * key map.
23
     *
24
     * @param array $data The ticket data to parse.
25
     * @return array The data after being converted to the parsed form.
26
     */
27
    public function parseData(array $data)
28
    {
29
        $parsedData = [];
30
        foreach ($this->_keyMap() as $from => $to) {
31
            if (array_key_exists($from, $data)) {
32
                $parsedData[$to] = $data[$from];
33
            }
34
        }
35
36
        $parsedData['active'] = (bool)$parsedData['active'];
37
        $parsedData['createdDate'] = $this->convertDate($parsedData['createdDate']);
38
        $parsedData['usedDate'] = $this->convertDate($parsedData['usedDate']);
39
        $parsedData['uses'] = (int)$parsedData['uses'];
40
41
        return $parsedData;
42
    }
43
44
    /**
45
     * Gets the key map for API results to the ScaleEngineTicket model.
46
     *
47
     * @return array A map of keys from ScaleEngine's API to exposed model.
48
     */
49
    private function _keyMap()
50
    {
51
        return [
52
            'active' => 'active',
53
            'app' => 'app',
54
            'created_date' => 'createdDate',
55
            'ip' => 'ip',
56
            'key' => 'key',
57
            'pass' => 'pass',
58
            'used_date' => 'usedDate',
59
            'uses' => 'uses',
60
            'video' => 'video',
61
        ];
62
    }
63
}
64