Completed
Push — master ( e66c58...0a0a0f )
by Daniel
9s
created

PropertyColumn::buildCell()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid\Column;
6
7
use Psi\Component\Grid\ColumnInterface;
8
use Psi\Component\Grid\View\Cell;
9
use Symfony\Component\OptionsResolver\OptionsResolver;
10
use Symfony\Component\PropertyAccess\PropertyAccess;
11
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
12
13
class PropertyColumn implements ColumnInterface
14
{
15
    /**
16
     * @var PropertyAccessor
17
     */
18
    private $accessor;
19
20
    public function __construct(PropertyAccessorInterface $propertyAccessor = null)
21
    {
22
        $this->accessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
0 ignored issues
show
Documentation Bug introduced by
It seems like $propertyAccessor ?: \Sy...reatePropertyAccessor() of type object<Symfony\Component...pertyAccessorInterface> or object<Symfony\Component...ccess\PropertyAccessor> is incompatible with the declared type object<Psi\Component\Gri...olumn\PropertyAccessor> of property $accessor.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
23
    }
24
25
    public function buildCell(Cell $cell, array $options)
26
    {
27
        $property = $options['property'];
28
        $cell->template = 'Property';
29
        $cell->value = $this->accessor->getValue($cell->context, $property);
30
    }
31
32
    public function configureOptions(OptionsResolver $options)
33
    {
34
        $options->setDefault('property', null);
35
        $options->setAllowedTypes('property', ['string', 'null']);
36
        $options->setNormalizer('property', function (OptionsResolver $options, $value) {
37
            if (null !== $value) {
38
                return $value;
39
            }
40
41
            return $options['column_name'];
42
        });
43
        $options->setNormalizer('sort_field', function (OptionsResolver $options, $value) {
44
            if (null !== $value) {
45
                return $value;
46
            }
47
48
            return $options['column_name'];
49
        });
50
    }
51
52
    public function getParent()
53
    {
54
    }
55
}
56