Completed
Pull Request — master (#34)
by Daniel
02:15
created

DriverUtil   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSourceMetadata() 0 6 1
A getViewMetadata() 0 6 1
A resolveConfigurableReference() 0 11 3
1
<?php
2
3
namespace Psi\Component\Grid\Metadata\Driver;
4
5
use Psi\Component\Grid\Metadata\SourceMetadata;
6
use Psi\Component\Grid\Metadata\ViewMetadata;
7
8
class DriverUtil
9
{
10
    public static function getSourceMetadata($options)
11
    {
12
        list($type, $options) = self::resolveConfigurableReference($options);
13
14
        return new SourceMetadata($type, $options);
15
    }
16
17
    public static function getViewMetadata($options)
18
    {
19
        list($type, $options) = self::resolveConfigurableReference($options);
20
21
        return new ViewMetadata($type, $options);
22
    }
23
24
    private static function resolveConfigurableReference($options)
25
    {
26
        if (is_string($options)) {
27
            $options = [ 'type' => $options ];
28
        }
29
30
        $type = isset($options['type']) ? $options['type'] : null;
31
        unset($options['type']);
32
33
        return [ $type, $options ];
34
    }
35
}
36