CheckOutData::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace SGP\IronBox;
4
5
use SGP\IronBox\Contracts\Validatable;
6
use SGP\IronBox\Exceptions\IronBoxException;
7
8
class CheckOutData implements Validatable
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $sharedAccessSignature;
14
15
    /**
16
     * @var string
17
     */
18
    protected $sharedAccessSignatureUri;
19
20
    /**
21
     * @var string
22
     */
23
    protected $checkInToken;
24
25
    /**
26
     * @var string
27
     */
28
    protected $storageUri;
29
30
    /**
31
     * @var int
32
     */
33
    protected $storageType;
34
35
    /**
36
     * @var string
37
     */
38
    protected $containerStorageName;
39
40
    /**
41
     * CheckOutData constructor.
42
     *
43
     * @param array $data
44
     */
45
    public function __construct(array $data = [])
46
    {
47
        foreach ($data as $key => $value) {
48
            $key = lcfirst($key);
49
50
            $this->{$key} = $value;
51
        }
52
    }
53
54
    /**
55
     * Validates that all required fields are present
56
     *
57
     * @return bool
58
     * @throws \SGP\IronBox\Exceptions\IronBoxException
59
     */
60
    public function validate()
61
    {
62
        $requiredFields = [
63
            'sharedAccessSignature', 'sharedAccessSignatureUri', 'checkInToken',
64
            'storageUri', 'storageType', 'containerStorageName',
65
        ];
66
67
        foreach ($requiredFields as $requiredField) {
68
            if (is_null($this->{$requiredField})) {
69
                throw new IronBoxException("Field `{$requiredField}` is required");
70
            }
71
        }
72
73
        return true;
74
    }
75
76
    public function __get($key)
77
    {
78
        if (! isset($this->{$key})) {
79
            throw new IronBoxException("Property `{$key}` doesn't exist");
80
        }
81
82
        return $this->{$key};
83
    }
84
85
    public static function create(array $data = [])
86
    {
87
        return new static($data);
88
    }
89
}
90