Completed
Pull Request — master (#2)
by Spencer
03:30
created

ScaleEngineTicketFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 57
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A parseData() 0 16 3
A _keyMap() 0 14 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