Packages::initializeParameters()   B
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 7
nop 1
1
<?php
2
3
/*
4
 * This file is part of the samshal/rando package.
5
 *
6
 * (c) Samuel Adeshina <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Samshal\Rando\Packages;
12
13
use Samshal\Rando\Exceptions\ArrayParametersExpectedException;
14
use Samshal\Rando\Exceptions\OptionNotSupportedException;
15
16
abstract class Packages
17
{
18
19
    public function initializeParameters($parameters = [])
20
    {
21
        if (!is_array($parameters)) {
22
            throw new ArrayParametersExpectedException();
23
        }
24
25
        if (empty($parameters)) {
26
            $this->initializeParameters($this->setDefaults());
27
        }
28
29
        foreach ($parameters as $parameter=>$value) {
30
            $paramSetter = 'set'.ucfirst(strtolower($parameter));
31
            if (method_exists($this, $paramSetter)) {
32
                $this->$paramSetter($value);
33
            } else {
34
                throw new OptionNotSupportedException();
35
            }
36
        }
37
    }
38
39
    abstract public function stringify();
40
}
41