Completed
Pull Request — master (#28)
by Daniel
03:48 queued 01:45
created

ColumnFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
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 ColumnFactory
10
{
11
    private $registry;
12
13
    public function __construct(
14
        ColumnRegistry $registry
15
16
    ) {
17
        $this->registry = $registry;
18
    }
19
20
    // TODO: Rename to createCell -- add createHeader
21
    public function create(string $columnName, string $typeName, RowData $data, array $options): CellInterface
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->createCell($data, $options);
31
    }
32
}
33