ProviderValidator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 59.26 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 2
dl 16
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 16 16 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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