ProviderValidator::validate()   B
last analyzed

Complexity

Conditions 7
Paths 6

Size

Total Lines 16
Code Lines 8

Duplication

Lines 16
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 16
loc 16
rs 8.2222
cc 7
eloc 8
nc 6
nop 2
1
<?php
2
3
namespace Vinelab\Cdn\Validators;
4
5
use Vinelab\Cdn\Exceptions\MissingConfigurationException;
6
use Vinelab\Cdn\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 \Vinelab\Cdn\Exceptions\MissingConfigurationException
24
     */
25 View Code Duplication
    public function validate($configuration, $required)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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