| Conditions | 14 |
| Paths | 1280 |
| Total Lines | 191 |
| Code Lines | 132 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 113 | public function load(array $configs, ContainerBuilder $container) |
||
| 114 | { |
||
| 115 | $bundles = $container->getParameter('kernel.bundles'); |
||
| 116 | |||
| 117 | if (isset($bundles['SonataUserBundle'])) { |
||
| 118 | // integrate the SonataUserBundle / FOSUserBundle if the bundle exists |
||
| 119 | array_unshift($configs, [ |
||
| 120 | 'templates' => [ |
||
| 121 | 'user_block' => 'SonataUserBundle:Admin/Core:user_block.html.twig', |
||
| 122 | ], |
||
| 123 | ]); |
||
| 124 | } |
||
| 125 | |||
| 126 | if (isset($bundles['SonataIntlBundle'])) { |
||
| 127 | // integrate the SonataUserBundle if the bundle exists |
||
| 128 | array_unshift($configs, [ |
||
| 129 | 'templates' => [ |
||
| 130 | 'history_revision_timestamp' => 'SonataIntlBundle:CRUD:history_revision_timestamp.html.twig', |
||
| 131 | ], |
||
| 132 | ]); |
||
| 133 | } |
||
| 134 | |||
| 135 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
||
| 136 | $loader->load('twig.xml'); |
||
| 137 | $loader->load('core.xml'); |
||
| 138 | $loader->load('form_types.xml'); |
||
| 139 | $loader->load('validator.xml'); |
||
| 140 | $loader->load('route.xml'); |
||
| 141 | $loader->load('block.xml'); |
||
| 142 | $loader->load('menu.xml'); |
||
| 143 | $loader->load('commands.xml'); |
||
| 144 | |||
| 145 | if (isset($bundles['SonataExporterBundle'])) { |
||
| 146 | $loader->load('exporter.xml'); |
||
| 147 | } |
||
| 148 | |||
| 149 | $container->getDefinition('sonata.admin.exporter')->setDeprecated( |
||
| 150 | 'The service "%service_id%" is deprecated in favor of the "sonata.exporter.exporter" service' |
||
| 151 | ); |
||
| 152 | |||
| 153 | $configuration = $this->getConfiguration($configs, $container); |
||
| 154 | $config = $this->processConfiguration($configuration, $configs); |
||
| 155 | |||
| 156 | $config['options']['javascripts'] = $this->buildJavascripts($config); |
||
| 157 | $config['options']['stylesheets'] = $this->buildStylesheets($config); |
||
| 158 | $config['options']['role_admin'] = $config['security']['role_admin']; |
||
| 159 | $config['options']['role_super_admin'] = $config['security']['role_super_admin']; |
||
| 160 | |||
| 161 | $pool = $container->getDefinition('sonata.admin.pool'); |
||
| 162 | $pool->replaceArgument(1, $config['title']); |
||
| 163 | $pool->replaceArgument(2, $config['title_logo']); |
||
| 164 | $pool->replaceArgument(3, $config['options']); |
||
| 165 | |||
| 166 | if (false === $config['options']['lock_protection']) { |
||
| 167 | $container->removeDefinition('sonata.admin.lock.extension'); |
||
| 168 | } |
||
| 169 | |||
| 170 | $container->setParameter('sonata.admin.configuration.global_search.empty_boxes', $config['global_search']['empty_boxes']); |
||
| 171 | $container->setParameter('sonata.admin.configuration.templates', $config['templates'] + [ |
||
| 172 | 'user_block' => 'SonataAdminBundle:Core:user_block.html.twig', |
||
| 173 | 'add_block' => 'SonataAdminBundle:Core:add_block.html.twig', |
||
| 174 | 'layout' => 'SonataAdminBundle::standard_layout.html.twig', |
||
| 175 | 'ajax' => 'SonataAdminBundle::ajax_layout.html.twig', |
||
| 176 | 'dashboard' => 'SonataAdminBundle:Core:dashboard.html.twig', |
||
| 177 | 'list' => 'SonataAdminBundle:CRUD:list.html.twig', |
||
| 178 | 'filter' => 'SonataAdminBundle:Form:filter_admin_fields.html.twig', |
||
| 179 | 'show' => 'SonataAdminBundle:CRUD:show.html.twig', |
||
| 180 | 'show_compare' => 'SonataAdminBundle:CRUD:show_compare.html.twig', |
||
| 181 | 'edit' => 'SonataAdminBundle:CRUD:edit.html.twig', |
||
| 182 | 'history' => 'SonataAdminBundle:CRUD:history.html.twig', |
||
| 183 | 'history_revision_timestamp' => 'SonataAdminBundle:CRUD:history_revision_timestamp.html.twig', |
||
| 184 | 'acl' => 'SonataAdminBundle:CRUD:acl.html.twig', |
||
| 185 | 'action' => 'SonataAdminBundle:CRUD:action.html.twig', |
||
| 186 | 'short_object_description' => 'SonataAdminBundle:Helper:short-object-description.html.twig', |
||
| 187 | 'preview' => 'SonataAdminBundle:CRUD:preview.html.twig', |
||
| 188 | 'list_block' => 'SonataAdminBundle:Block:block_admin_list.html.twig', |
||
| 189 | 'delete' => 'SonataAdminBundle:CRUD:delete.html.twig', |
||
| 190 | 'batch' => 'SonataAdminBundle:CRUD:list__batch.html.twig', |
||
| 191 | 'select' => 'SonataAdminBundle:CRUD:list__select.html.twig', |
||
| 192 | 'batch_confirmation' => 'SonataAdminBundle:CRUD:batch_confirmation.html.twig', |
||
| 193 | 'inner_list_row' => 'SonataAdminBundle:CRUD:list_inner_row.html.twig', |
||
| 194 | 'base_list_field' => 'SonataAdminBundle:CRUD:base_list_field.html.twig', |
||
| 195 | 'pager_links' => 'SonataAdminBundle:Pager:links.html.twig', |
||
| 196 | 'pager_results' => 'SonataAdminBundle:Pager:results.html.twig', |
||
| 197 | 'tab_menu_template' => 'SonataAdminBundle:Core:tab_menu_template.html.twig', |
||
| 198 | 'knp_menu_template' => 'SonataAdminBundle:Menu:sonata_menu.html.twig', |
||
| 199 | 'outer_list_rows_mosaic' => 'SonataAdminBundle:CRUD:list_outer_rows_mosaic.html.twig', |
||
| 200 | 'outer_list_rows_list' => 'SonataAdminBundle:CRUD:list_outer_rows_list.html.twig', |
||
| 201 | 'outer_list_rows_tree' => 'SonataAdminBundle:CRUD:list_outer_rows_tree.html.twig', |
||
| 202 | ]); |
||
| 203 | $container->setParameter('sonata.admin.configuration.admin_services', $config['admin_services']); |
||
| 204 | $container->setParameter('sonata.admin.configuration.dashboard_groups', $config['dashboard']['groups']); |
||
| 205 | $container->setParameter('sonata.admin.configuration.dashboard_blocks', $config['dashboard']['blocks']); |
||
| 206 | $container->setParameter('sonata.admin.configuration.sort_admins', $config['options']['sort_admins']); |
||
| 207 | $container->setParameter('sonata.admin.configuration.breadcrumbs', $config['breadcrumbs']); |
||
| 208 | |||
| 209 | if (null === $config['security']['acl_user_manager'] && isset($bundles['FOSUserBundle'])) { |
||
| 210 | $container->setParameter('sonata.admin.security.acl_user_manager', 'fos_user.user_manager'); |
||
| 211 | } else { |
||
| 212 | $container->setParameter('sonata.admin.security.acl_user_manager', $config['security']['acl_user_manager']); |
||
| 213 | } |
||
| 214 | |||
| 215 | $container->setAlias('sonata.admin.security.handler', $config['security']['handler']); |
||
| 216 | |||
| 217 | switch ($config['security']['handler']) { |
||
| 218 | case 'sonata.admin.security.handler.role': |
||
| 219 | if (0 === count($config['security']['information'])) { |
||
| 220 | $config['security']['information'] = [ |
||
| 221 | 'EDIT' => ['EDIT'], |
||
| 222 | 'LIST' => ['LIST'], |
||
| 223 | 'CREATE' => ['CREATE'], |
||
| 224 | 'VIEW' => ['VIEW'], |
||
| 225 | 'DELETE' => ['DELETE'], |
||
| 226 | 'EXPORT' => ['EXPORT'], |
||
| 227 | 'ALL' => ['ALL'], |
||
| 228 | ]; |
||
| 229 | } |
||
| 230 | |||
| 231 | break; |
||
| 232 | case 'sonata.admin.security.handler.acl': |
||
| 233 | if (0 === count($config['security']['information'])) { |
||
| 234 | $config['security']['information'] = [ |
||
| 235 | 'GUEST' => ['VIEW', 'LIST'], |
||
| 236 | 'STAFF' => ['EDIT', 'LIST', 'CREATE'], |
||
| 237 | 'EDITOR' => ['OPERATOR', 'EXPORT'], |
||
| 238 | 'ADMIN' => ['MASTER'], |
||
| 239 | ]; |
||
| 240 | } |
||
| 241 | |||
| 242 | break; |
||
| 243 | } |
||
| 244 | |||
| 245 | $container->setParameter('sonata.admin.configuration.security.role_admin', $config['security']['role_admin']); |
||
| 246 | $container->setParameter('sonata.admin.configuration.security.role_super_admin', $config['security']['role_super_admin']); |
||
| 247 | $container->setParameter('sonata.admin.configuration.security.information', $config['security']['information']); |
||
| 248 | $container->setParameter('sonata.admin.configuration.security.admin_permissions', $config['security']['admin_permissions']); |
||
| 249 | $container->setParameter('sonata.admin.configuration.security.object_permissions', $config['security']['object_permissions']); |
||
| 250 | |||
| 251 | $loader->load('security.xml'); |
||
| 252 | |||
| 253 | $container->setParameter('sonata.admin.extension.map', $config['extensions']); |
||
| 254 | |||
| 255 | /* |
||
| 256 | * This is a work in progress, so for now it is hardcoded |
||
| 257 | */ |
||
| 258 | $classes = [ |
||
| 259 | 'email' => '', |
||
| 260 | 'textarea' => '', |
||
| 261 | 'text' => '', |
||
| 262 | 'choice' => '', |
||
| 263 | 'integer' => '', |
||
| 264 | 'datetime' => 'sonata-medium-date', |
||
| 265 | 'date' => 'sonata-medium-date', |
||
| 266 | |||
| 267 | // SF3+ |
||
| 268 | SymfonyChoiceType::class => '', |
||
| 269 | SymfonyDateType::class => 'sonata-medium-date', |
||
| 270 | SymfonyDateTimeType::class => 'sonata-medium-date', |
||
| 271 | SymfonyEmailType::class => '', |
||
| 272 | SymfonyIntegerType::class => '', |
||
| 273 | SymfonyTextareaType::class => '', |
||
| 274 | SymfonyTextType::class => '', |
||
| 275 | ]; |
||
| 276 | |||
| 277 | $container->getDefinition('sonata.admin.form.extension.field') |
||
| 278 | ->replaceArgument(0, $classes) |
||
| 279 | ->replaceArgument(1, $config['options']); |
||
| 280 | |||
| 281 | // remove non used service |
||
| 282 | if (!isset($bundles['JMSTranslationBundle'])) { |
||
| 283 | $container->removeDefinition('sonata.admin.translator.extractor.jms_translator_bundle'); |
||
| 284 | } |
||
| 285 | |||
| 286 | //remove non-Mopa compatibility layer |
||
| 287 | if (isset($bundles['MopaBootstrapBundle'])) { |
||
| 288 | $container->removeDefinition('sonata.admin.form.extension.field.mopa'); |
||
| 289 | } |
||
| 290 | |||
| 291 | // set filter persistence |
||
| 292 | $container->setParameter('sonata.admin.configuration.filters.persist', $config['persist_filters']); |
||
| 293 | |||
| 294 | $container->setParameter('sonata.admin.configuration.show.mosaic.button', $config['show_mosaic_button']); |
||
| 295 | |||
| 296 | $container->setParameter('sonata.admin.configuration.translate_group_label', $config['translate_group_label']); |
||
| 297 | |||
| 298 | if (\PHP_VERSION_ID < 70000) { |
||
| 299 | $this->configureClassesToCompile(); |
||
| 300 | } |
||
| 301 | |||
| 302 | $this->replacePropertyAccessor($container); |
||
| 303 | } |
||
| 304 | |||
| 499 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: