Completed
Push — master ( b64fc1...5651bd )
by Raffael
16:20 queued 08:39
created

Validator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 26
Duplicated Lines 23.08 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 6
loc 26
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 6 20 8

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
declare(strict_types=1);
4
5
/**
6
 * tubee
7
 *
8
 * @copyright   Copryright (c) 2017-2019 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Tubee\Endpoint;
13
14
use InvalidArgumentException;
15
use Tubee\Helper;
16
17
class Validator
18
{
19
    /**
20
     * Validate resource.
21
     */
22
    public static function validate(array $resource): array
23
    {
24
        if ($resource['data']['type'] === EndpointInterface::TYPE_SOURCE && (!is_array($resource['data']['options']['import']) || count($resource['data']['options']['import']) === 0)) {
25
            throw new InvalidArgumentException('source endpoint must include at least one options.import attribute');
26
        }
27
28
        if ($resource['data']['type'] === EndpointInterface::TYPE_DESTINATION && !isset($resource['data']['options']['filter_one'])) {
29
            throw new InvalidArgumentException('destintation endpoint must have single object filter options.filter_one as a string');
30
        }
31
32 View Code Duplication
        if (isset($resource['data']['options']['filter_one'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
33
            Helper::jsonDecode(stripslashes($resource['data']['options']['filter_one']), true);
34
        }
35
36 View Code Duplication
        if (isset($resource['data']['options']['filter_all'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
37
            Helper::jsonDecode(stripslashes($resource['data']['options']['filter_all']), true);
38
        }
39
40
        return $resource;
41
    }
42
}
43