Completed
Push — master ( 2e5467...f43997 )
by Julián
02:59
created

AbstractService::setSandbox()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * Push notification services abstraction (http://github.com/juliangut/tify)
4
 *
5
 * @link https://github.com/juliangut/tify for the canonical source repository
6
 *
7
 * @license https://github.com/juliangut/tify/blob/master/LICENSE
8
 */
9
10
namespace Jgut\Tify\Service;
11
12
use Jgut\Tify\ParametersTrait;
13
use Symfony\Component\OptionsResolver\OptionsResolver;
14
15
abstract class AbstractService
16
{
17
    use ParametersTrait;
18
19
    /**
20
     * List of defined parameters.
21
     *
22
     * @var array
23
     */
24
    protected $definedParameters = [];
25
26
    /**
27
     * List of default parameters.
28
     *
29
     * @var array
30
     */
31
    protected $defaultParameters = [];
32
33
    /**
34
     * List of required parameters.
35
     *
36
     * @var array
37
     */
38
    protected $requiredParameters = [];
39
40
    /**
41
     * Sandbox environment.
42
     *
43
     * @var bool
44
     */
45
    protected $sandbox;
46
47
    /**
48
     * Constructor.
49
     *
50
     * @param array $parameters
51
     * @param bool  $sandbox
52
     */
53
    public function __construct(array $parameters = [], $sandbox = false)
54
    {
55
        $resolver = new OptionsResolver();
56
        $resolver->setDefined($this->definedParameters);
57
        $resolver->setDefaults($this->defaultParameters);
58
        $resolver->setRequired($this->requiredParameters);
59
60
        $this->parameters = $resolver->resolve($parameters);
61
        $this->setSandbox($sandbox);
62
    }
63
64
    /**
65
     * Retrieve if sandbox.
66
     *
67
     * @return bool
68
     */
69
    public function isSandbox()
70
    {
71
        return $this->sandbox;
72
    }
73
74
    /**
75
     * Set Sandbox.
76
     *
77
     * @param bool $sandbox
78
     */
79
    public function setSandbox($sandbox)
80
    {
81
        $this->sandbox = (bool) $sandbox;
82
83
        return $this;
84
    }
85
}
86