Completed
Pull Request — master (#49)
by Daniel
08:41
created

PropertyColumn::getParent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid\Column;
6
7
use Psi\Component\Grid\CellInterface;
8
use Psi\Component\Grid\ColumnInterface;
9
use Psi\Component\Grid\GridContext;
10
use Psi\Component\Grid\View\Cell;
11
use Psi\Component\Grid\View\Header;
12
use Symfony\Component\OptionsResolver\OptionsResolver;
13
use Symfony\Component\PropertyAccess\PropertyAccess;
14
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
15
16
class PropertyColumn implements ColumnInterface
17
{
18
    /**
19
     * @var PropertyAccessor
20
     */
21
    private $accessor;
22
23
    public function __construct(PropertyAccessorInterface $propertyAccessor = null)
24
    {
25
        $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...
26
    }
27
28
    public function buildCell(Cell $cell, array $options)
29
    {
30
        $property = $options['property'];
31
        $cell->template = 'Property';
32
        $cell->value = $this->accessor->getValue($cell->context, $property);
33
    }
34
35
    public function configureOptions(OptionsResolver $options)
36
    {
37
        $options->setDefault('property', null);
38
        $options->setAllowedTypes('property', ['string', 'null']);
39
        $options->setNormalizer('property', function (OptionsResolver $options, $value) {
40
            if (null !== $value) {
41
                return $value;
42
            }
43
44
            return $options['column_name'];
45
        });
46
        $options->setNormalizer('sort_field', function (OptionsResolver $options, $value) {
47
            if (null !== $value) {
48
                return $value;
49
            }
50
51
            return $options['column_name'];
52
        });
53
    }
54
55
    public function getParent()
56
    {
57
    }
58
}
59