Issues (51)

Admin/CRUD/Context/BatchElementContext.php (1 issue)

1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminBundle\Admin\CRUD\Context;
13
14
use FSi\Bundle\AdminBundle\Admin\Context\ContextAbstract;
15
use FSi\Bundle\AdminBundle\Admin\CRUD\BatchElement;
16
use FSi\Bundle\AdminBundle\Admin\CRUD\FormElement;
17
use FSi\Bundle\AdminBundle\Admin\Element;
18
use FSi\Bundle\AdminBundle\Event\AdminEvent;
19
use FSi\Bundle\AdminBundle\Event\FormEvent;
20
use Symfony\Component\Form\FormInterface;
21
use Symfony\Component\Form\FormBuilderInterface;
22
use Symfony\Component\HttpFoundation\Request;
23
24
class BatchElementContext extends ContextAbstract
25
{
26
    /**
27
     * @var FormElement
28
     */
29
    protected $element;
30
31
    /**
32
     * @var FormInterface
33
     */
34
    protected $form;
35
36
    /**
37
     * @var array
38
     */
39
    protected $indexes;
40
41
    public function __construct(array $requestHandlers, FormBuilderInterface $formBuilder)
42
    {
43
        parent::__construct($requestHandlers);
44
        $this->form = $formBuilder->getForm();
45
    }
46
47
    public function getData(): array
48
    {
49
        return [
50
            'element' => $this->element,
51
            'indexes' => $this->indexes,
52
            'form' => $this->form->createView()
53
        ];
54
    }
55
56
    public function setElement(Element $element): void
57
    {
58
        $this->element = $element;
0 ignored issues
show
Documentation Bug introduced by
$element is of type FSi\Bundle\AdminBundle\Admin\Element, but the property $element was declared to be of type FSi\Bundle\AdminBundle\Admin\CRUD\FormElement. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
59
    }
60
61
    protected function createEvent(Request $request): AdminEvent
62
    {
63
        $this->indexes = $request->request->get('indexes', []);
64
65
        return new FormEvent($this->element, $request, $this->form);
66
    }
67
68
    protected function getSupportedRoute(): string
69
    {
70
        return 'fsi_admin_batch';
71
    }
72
73
    protected function supportsElement(Element $element): bool
74
    {
75
        return $element instanceof BatchElement;
76
    }
77
}
78