ProviderValidator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 14 7
1
<?php
2
3
namespace Eliurkis\laravelcdn\Validators;
4
5
use Eliurkis\laravelcdn\Exceptions\MissingConfigurationException;
6
use Eliurkis\laravelcdn\Validators\Contracts\ProviderValidatorInterface;
7
8
/**
9
 * Class ProviderValidator.
10
 *
11
 * @category
12
 *
13
 * @author  Mahmoud Zalt <[email protected]>
14
 */
15
class ProviderValidator extends Validator implements ProviderValidatorInterface
16
{
17
    /**
18
     * Checks for any required configuration is missed.
19
     *
20
     * @param $configuration
21
     * @param $required
22
     *
23
     * @throws \Eliurkis\laravelcdn\Exceptions\MissingConfigurationException
24
     */
25
    public function validate($configuration, $required)
26
    {
27
        // search for any null or empty field to throw an exception
28
        $missing = '';
29
        foreach ($configuration as $key => $value) {
30
            if (in_array($key, $required) &&
31
                (empty($value) || $value == null || $value == '')
32
            ) {
33
                $missing .= ' '.$key;
34
            }
35
        }
36
37
        if ($missing) {
38
            throw new MissingConfigurationException('Missed Configuration:'.$missing);
39
        }
40
    }
41
}
42