Completed
Push — master ( abe227...316baf )
by Raffael
13:55 queued 08:01
created

Validator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 38
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B validateWorkflow() 0 32 6
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * tubee.io
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\Workflow;
13
14
use InvalidArgumentException;
15
use Tubee\AttributeMap\Validator as AttributeMapValidator;
16
use Tubee\Resource\Validator as ResourceValidator;
17
18
class Validator extends ResourceValidator
19
{
20
    /**
21
     * Validate resource.
22
     */
23
    public static function validateWorkflow(array $resource): array
24
    {
25
        $resource = parent::validate($resource);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (validate() instead of validateWorkflow()). Are you sure this is correct? If so, you might want to change this to $this->validate().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
26
        $defaults = [
27
            'data' => [
28
                'ensure' => WorkflowInterface::ENSURE_LAST,
29
                'priority' => 0,
30
                'map' => [],
31
                'condition' => null,
32
            ],
33
        ];
34
35
        $resource = array_replace_recursive($defaults, $resource);
36
37
        if (!isset($resource['data']['ensure']) || !in_array($resource['data']['ensure'], WorkflowInterface::VALID_ENSURES)) {
38
            throw new InvalidArgumentException('data.ensure as string must be provided (one of exists,last,disabled,absent)');
39
        }
40
41
        if (isset($resource['data']['condition'])) {
42
            if (!is_string($resource['data']['condition'])) {
43
                throw new InvalidArgumentException('provided data.condition must be a string');
44
            }
45
        }
46
47
        if (!is_int($resource['data']['priority'])) {
48
            throw new InvalidArgumentException('provided data.priority must be an integer');
49
        }
50
51
        $resource['data']['map'] = AttributeMapValidator::validate($resource['data']['map']);
52
53
        return $resource;
54
    }
55
}
56