Completed
Pull Request — 8.x-1.x (#7)
by
unknown
106:26 queued 41:26
created

RouteParameters::__construct()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 17
nc 7
nop 1
1
<?php
2
3
namespace Drupal\controller_annotations\RouteModifier;
4
5
/**
6
 * @Annotation
7
 */
8
class RouteParameters extends RouteOptionsBase {
9
10
  /**
11
   * @param array $values
12
   */
13
  public function __construct(array $values) {
14
15
    $parameters = [];
16
17
    foreach ($values as $k => $v) {
18
      if (is_string($v)) {
19
        $parameters[$k] = ['type' => $v];
20
      }
21
      elseif ([] === $v) {
22
        // @todo Is this allowed?
23
        $parameters[$k] = [];
24
      }
25
      elseif (is_array($v)) {
26
        if ('type' !== array_keys($v)) {
27
          throw new \RuntimeException("Parameter array must have only one key, 'type'.");
28
        }
29
        $type = $v['type'];
30
        if (!is_string($type)) {
31
          throw new \RuntimeException("Parameter type must be a string.");
32
        }
33
        $parameters[$k] = ['type' => $type];
34
      }
35
      else {
36
        throw new \RuntimeException("Parameter must be an array or a string.");
37
      }
38
    }
39
40
    parent::__construct(['options' => $parameters]);
41
  }
42
43
}
44