Completed
Pull Request — master (#1)
by Spencer
02:07
created

ScaleEngineTicketFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A parseData() 0 16 3
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
    /** @type array A map of keys from ScaleEngine's API to exposed model. **/
10
    const KEY_MAP = [
11
        'active' => 'active',
12
        'app' => 'app',
13
        'created_date' => 'createdDate',
14
        'ip' => 'ip',
15
        'key' => 'key',
16
        'pass' => 'pass',
17
        'used_date' => 'usedDate',
18
        'uses' => 'uses',
19
        'video' => 'video',
20
    ];
21
22
    /**
23
     * Create the model factory for ScaleEngine tickets.
24
     */
25
    public function __construct()
26
    {
27
        parent::__construct(
28
            '\FloSports\ScaleEngine\Model\ScaleEngineTicket',
29
            self::KEY_MAP
30
        );
31
    }
32
33
    /**
34
     * Parse the data given into correct types and changes keys based on the
35
     * `KEY_MAP`.
36
     *
37
     * @param array $data The ticket data to parse.
38
     * @return array The data after being converted to the parsed form.
39
     */
40
    public function parseData(array $data)
41
    {
42
        $parsedData = [];
43
        foreach (self::KEY_MAP as $from => $to) {
44
            if (array_key_exists($from, $data)) {
45
                $parsedData[$to] = $data[$from];
46
            }
47
        }
48
49
        $parsedData['active'] = (bool)$parsedData['active'];
50
        $parsedData['createdDate'] = $this->convertDate($parsedData['createdDate']);
51
        $parsedData['usedDate'] = $this->convertDate($parsedData['usedDate']);
52
        $parsedData['uses'] = (int)$parsedData['uses'];
53
54
        return $parsedData;
55
    }
56
}
57