Passed
Pull Request — master (#300)
by Arnaud
14:15 queued 08:05
created

LinkNormalizer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B normalize() 0 22 7
1
<?php
2
3
namespace LAG\AdminBundle\Admin\Configuration\Normalizer;
4
5
use LAG\AdminBundle\Exception\Exception;
6
7
class LinkNormalizer
8
{
9
    public static function normalize(array $value, ?string $adminName = null, ?string $actionName = null): array
10
    {
11
        if (isset($value['route'])) {
12
            return $value;
13
        }
14
15
        if (isset($value['url'])) {
16
            return $value;
17
        }
18
19
        if (isset($value['admin']) && isset($value['action'])) {
20
            return $value;
21
        }
22
23
        if ($adminName !== null && $actionName !== null) {
24
            $value['admin'] = $adminName;
25
            $value['action'] = $actionName;
26
27
            return $value;
28
        }
29
30
        throw new Exception('The link action should contains an url, a route, or an admin and action');
31
    }
32
}
33