Factory::buildCollection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Date: 20/08/15
4
 */
5
6
namespace Mailxpert\Model;
7
8
use Mailxpert\Exceptions\MailxpertSDKException;
9
10
/**
11
 * Class Factory
12
 * @package Mailxpert\Model
13
 */
14
abstract class Factory implements FactoryInterface
15
{
16
    /**
17
     * @param mixed $data
18
     *
19
     * @return mixed
20
     * @throws MailxpertSDKException
21
     */
22
    public static function parse($data)
23
    {
24
        if (!isset($data['data'])) {
25
            throw new MailxpertSDKException('The $data is invalid, it should at least contain a data field.');
26
        }
27
28
        if (isset($data['data']['id'])) {
29
            $element = static::buildElement($data['data']);
30
        } else {
31
            $element = static::buildCollection($data['data']);
32
        }
33
34
        return $element;
35
    }
36
37
38
    /**
39
     * Build collection of elements
40
     *
41
     * @param $data
42
     *
43
     * @return mixed
44
     * @throws MailxpertSDKException
45
     */
46
    protected static function buildCollection($data)
47
    {
48
        throw new MailxpertSDKException('Method not implemented');
49
    }
50
51
    /**
52
     * Build element
53
     *
54
     * @param $data
55
     *
56
     * @return mixed
57
     * @throws MailxpertSDKException
58
     */
59
    protected static function buildElement($data)
60
    {
61
        throw new MailxpertSDKException('Method not implemented');
62
    }
63
}
64