Completed
Pull Request — master (#18)
by Daniel
04:14
created

CellFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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