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

CellFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 4
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