Completed
Pull Request — master (#18)
by Daniel
06:17 queued 02:37
created

CellFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A create() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid;
6
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
class CellFactory
10
{
11
    private $registry;
12
13
    public function __construct(
14
        CellRegistry $registry
15
16
    ) {
17
        $this->registry = $registry;
18
    }
19
20
    public function create(string $columnName, string $typeName, $data, array $options): CellViewInterface
21
    {
22
        $resolver = new OptionsResolver();
23
        $resolver->setDefault('column_name', $columnName);
24
        $type = $this->registry->get($typeName);
25
        $type->configureOptions($resolver);
26
27
        $options = $resolver->resolve($options);
28
29
        return $type->createView($data, $options);
30
    }
31
}
32