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

Validator::validate()   B

Complexity

Conditions 8
Paths 6

Size

Total Lines 20

Duplication

Lines 6
Ratio 30 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
dl 6
loc 20
ccs 0
cts 16
cp 0
rs 8.4444
c 0
b 0
f 0
cc 8
nc 6
nop 1
crap 72
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