Packages   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B initializeParameters() 0 19 5
stringify() 0 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