These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the Sonata Project package. |
||
7 | * |
||
8 | * (c) Thomas Rabaix <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Sonata\AdminBundle\Command; |
||
15 | |||
16 | use Sonata\AdminBundle\Admin\Pool; |
||
17 | use Symfony\Component\Console\Command\Command; |
||
18 | use Symfony\Component\Console\Input\InputArgument; |
||
19 | use Symfony\Component\Console\Input\InputInterface; |
||
20 | use Symfony\Component\Console\Output\OutputInterface; |
||
21 | use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; |
||
22 | |||
23 | /** |
||
24 | * @final since sonata-project/admin-bundle 3.52 |
||
25 | * |
||
26 | * @author Thomas Rabaix <[email protected]> |
||
27 | */ |
||
28 | class ExplainAdminCommand extends Command |
||
29 | { |
||
30 | protected static $defaultName = 'sonata:admin:explain'; |
||
31 | |||
32 | /** |
||
33 | * @var Pool |
||
34 | */ |
||
35 | private $pool; |
||
36 | |||
37 | /** |
||
38 | * @var MetadataFactoryInterface |
||
39 | */ |
||
40 | private $validator; |
||
41 | |||
42 | public function __construct(Pool $pool, MetadataFactoryInterface $validator) |
||
43 | { |
||
44 | $this->pool = $pool; |
||
45 | $this->validator = $validator; |
||
46 | |||
47 | parent::__construct(); |
||
48 | } |
||
49 | |||
50 | public function configure() |
||
51 | { |
||
52 | $this->setDescription('Explain an admin service'); |
||
53 | |||
54 | $this->addArgument('admin', InputArgument::REQUIRED, 'The admin service id'); |
||
55 | } |
||
56 | |||
57 | public function execute(InputInterface $input, OutputInterface $output) |
||
58 | { |
||
59 | $admin = $this->pool->getInstance($input->getArgument('admin')); |
||
60 | |||
61 | $output->writeln('<comment>AdminBundle Information</comment>'); |
||
62 | $output->writeln(sprintf('<info>% -20s</info> : %s', 'id', $admin->getCode())); |
||
63 | $output->writeln(sprintf('<info>% -20s</info> : %s', 'Admin', \get_class($admin))); |
||
64 | $output->writeln(sprintf('<info>% -20s</info> : %s', 'Model', $admin->getClass())); |
||
65 | $output->writeln(sprintf('<info>% -20s</info> : %s', 'Controller', $admin->getBaseControllerName())); |
||
66 | $output->writeln(sprintf('<info>% -20s</info> : %s', 'Model Manager', \get_class($admin->getModelManager()))); |
||
67 | $output->writeln(sprintf('<info>% -20s</info> : %s', 'Form Builder', \get_class($admin->getFormBuilder()))); |
||
68 | $output->writeln(sprintf('<info>% -20s</info> : %s', 'Datagrid Builder', \get_class($admin->getDatagridBuilder()))); |
||
69 | $output->writeln(sprintf('<info>% -20s</info> : %s', 'List Builder', \get_class($admin->getListBuilder()))); |
||
70 | |||
71 | if ($admin->isChild()) { |
||
72 | $output->writeln(sprintf('<info>% -15s</info> : %s', 'Parent', $admin->getParent()->getCode())); |
||
73 | } |
||
74 | |||
75 | $output->writeln(''); |
||
76 | $output->writeln('<info>Routes</info>'); |
||
77 | foreach ($admin->getRoutes()->getElements() as $route) { |
||
78 | $output->writeln(sprintf(' - % -25s %s', $route->getDefault('_sonata_name'), $route->getPath())); |
||
79 | } |
||
80 | |||
81 | $output->writeln(''); |
||
82 | $output->writeln('<info>Datagrid Columns</info>'); |
||
83 | foreach ($admin->getListFieldDescriptions() as $name => $fieldDescription) { |
||
84 | $output->writeln(sprintf( |
||
85 | ' - % -25s % -15s % -15s', |
||
86 | $name, |
||
87 | $fieldDescription->getType(), |
||
88 | $fieldDescription->getTemplate() |
||
89 | )); |
||
90 | } |
||
91 | |||
92 | $output->writeln(''); |
||
93 | $output->writeln('<info>Datagrid Filters</info>'); |
||
94 | foreach ($admin->getFilterFieldDescriptions() as $name => $fieldDescription) { |
||
95 | $output->writeln(sprintf( |
||
96 | ' - % -25s % -15s % -15s', |
||
97 | $name, |
||
98 | $fieldDescription->getType(), |
||
99 | $fieldDescription->getTemplate() |
||
100 | )); |
||
101 | } |
||
102 | |||
103 | $output->writeln(''); |
||
104 | $output->writeln('<info>Form theme(s)</info>'); |
||
105 | foreach ($admin->getFormTheme() as $template) { |
||
106 | $output->writeln(sprintf(' - %s', $template)); |
||
107 | } |
||
108 | |||
109 | $output->writeln(''); |
||
110 | $output->writeln('<info>Form Fields</info>'); |
||
111 | foreach ($admin->getFormFieldDescriptions() as $name => $fieldDescription) { |
||
112 | $output->writeln(sprintf( |
||
113 | ' - % -25s % -15s % -15s', |
||
114 | $name, |
||
115 | $fieldDescription->getType(), |
||
116 | $fieldDescription->getTemplate() |
||
117 | )); |
||
118 | } |
||
119 | |||
120 | $metadata = $this->validator->getMetadataFor($admin->getClass()); |
||
121 | |||
122 | $output->writeln(''); |
||
123 | $output->writeln('<comment>Validation Framework</comment> - http://symfony.com/doc/3.0/book/validation.html'); |
||
124 | $output->writeln('<info>Properties constraints</info>'); |
||
125 | |||
126 | if (0 === \count($metadata->properties)) { |
||
0 ignored issues
–
show
|
|||
127 | $output->writeln(' <error>no property constraints defined !!</error>'); |
||
128 | } else { |
||
129 | foreach ($metadata->properties as $name => $property) { |
||
0 ignored issues
–
show
Accessing
properties on the interface Symfony\Component\Valida...pping\MetadataInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
130 | $output->writeln(sprintf(' - %s', $name)); |
||
131 | |||
132 | foreach ($property->getConstraints() as $constraint) { |
||
133 | $output->writeln(sprintf( |
||
134 | ' % -70s %s', |
||
135 | \get_class($constraint), |
||
136 | implode('|', $constraint->groups) |
||
137 | )); |
||
138 | } |
||
139 | } |
||
140 | } |
||
141 | |||
142 | $output->writeln(''); |
||
143 | $output->writeln('<info>Getters constraints</info>'); |
||
144 | |||
145 | if (0 === \count($metadata->getters)) { |
||
0 ignored issues
–
show
Accessing
getters on the interface Symfony\Component\Valida...pping\MetadataInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
146 | $output->writeln(' <error>no getter constraints defined !!</error>'); |
||
147 | } else { |
||
148 | foreach ($metadata->getters as $name => $property) { |
||
0 ignored issues
–
show
Accessing
getters on the interface Symfony\Component\Valida...pping\MetadataInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
149 | $output->writeln(sprintf(' - %s', $name)); |
||
150 | |||
151 | foreach ($property->getConstraints() as $constraint) { |
||
152 | $output->writeln(sprintf( |
||
153 | ' % -70s %s', |
||
154 | \get_class($constraint), |
||
155 | implode('|', $constraint->groups) |
||
156 | )); |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | |||
161 | $output->writeln(''); |
||
162 | $output->writeln('<info>done!</info>'); |
||
163 | |||
164 | return 0; |
||
165 | } |
||
166 | } |
||
167 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: