UserElement::getClassName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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\AdminSecurityBundle\Doctrine\Admin;
13
14
use FSi\Bundle\AdminBundle\Doctrine\Admin\CRUDElement;
15
use FSi\Component\DataGrid\DataGridFactoryInterface;
16
use FSi\Component\DataGrid\DataGridInterface;
17
use FSi\Component\DataSource\DataSourceFactoryInterface;
18
use FSi\Component\DataSource\DataSourceInterface;
19
use Symfony\Component\Form\FormFactoryInterface;
20
use Symfony\Component\Form\FormInterface;
21
22
class UserElement extends CRUDElement
23
{
24
    /**
25
     * @var string
26
     */
27
    private $userModel;
28
29
    /**
30
     * @var string
31
     */
32
    private $formClass;
33
34
    public function __construct(array $options, string $userModel, string $formClass)
35
    {
36
        parent::__construct($options);
37
38
        $this->userModel = $userModel;
39
        $this->formClass = $formClass;
40
    }
41
42
    public function getId(): string
43
    {
44
        return 'admin_security_user';
45
    }
46
47
    public function getClassName(): string
48
    {
49
        return $this->userModel;
50
    }
51
52
    protected function initDataGrid(DataGridFactoryInterface $factory): DataGridInterface
53
    {
54
        return $factory->createDataGrid('admin_security_user');
55
    }
56
57
    protected function initDataSource(DataSourceFactoryInterface $factory): DataSourceInterface
58
    {
59
        return $factory->createDataSource(
60
            'doctrine-orm',
61
            ['entity' => $this->getClassName()],
62
            $this->getId()
63
        )->setMaxResults(20);
64
    }
65
66
    protected function initForm(FormFactoryInterface $factory, $data = null): FormInterface
67
    {
68
        return $factory->create($this->formClass, $data);
69
    }
70
}
71