| Conditions | 4 |
| Paths | 6 |
| Total Lines | 82 |
| Code Lines | 68 |
| 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 |
||
| 169 | public function createDefaultData(): void |
||
| 170 | { |
||
| 171 | // create the default block positions - left, right and center for the traditional 3 column layout |
||
| 172 | $positions = [ |
||
| 173 | 'left' => $this->trans('Left blocks'), |
||
| 174 | 'right' => $this->trans('Right blocks'), |
||
| 175 | 'center' => $this->trans('Center blocks'), |
||
| 176 | 'search' => $this->trans('Search block'), |
||
| 177 | 'header' => $this->trans('Header block'), |
||
| 178 | 'footer' => $this->trans('Footer block'), |
||
| 179 | 'topnav' => $this->trans('Top navigation block'), |
||
| 180 | 'bottomnav' => $this->trans('Bottom navigation block') |
||
| 181 | ]; |
||
| 182 | foreach ($positions as $name => $description) { |
||
| 183 | $positions[$name] = new BlockPositionEntity(); |
||
| 184 | $positions[$name]->setName($name); |
||
| 185 | $positions[$name]->setDescription($description); |
||
| 186 | $this->entityManager->persist($positions[$name]); |
||
| 187 | } |
||
| 188 | $this->entityManager->flush(); |
||
| 189 | |||
| 190 | $hellomessage = $this->trans('<p><a href="https://ziku.la">Zikula</a> is an Open Source Content Application Framework built on top of Symfony.</p><p>With Zikula you get:</p><ul><li><strong>Power:</strong> You get the all the features of <a href="https://symfony.com">Symfony</a> PLUS: </li><li><strong>User Management:</strong> Built in User and Group management with Rights/Roles control</li><li><strong>Front end control:</strong> You can customise all aspects of the site\'s appearance through themes, with support for <a href="http://jquery.com">jQuery</a>, <a href="http://getbootstrap.com">Bootstrap</a> and many other modern technologies</li><li><strong>Internationalization (i18n):</strong> You can mark content as being suitable for either a single language or for all languages, and can control all aspects of localisation of your site</li><li><strong>Extensibility:</strong> you get a standard application-programming interface (API) that lets you easily extend your site\'s functionality through modules</li><li><strong>More:</strong> Admin UI, global categories, site-wide search, content blocks, menu creation, and more!</li><li><strong>Support:</strong> you can get help and support from the Zikula community of webmasters and developers at <a href="https://ziku.la">ziku.la</a>, <a href="https://github.com/zikula/core">Github</a> and <a href="https://zikula.slack.com/">Slack</a>.</li></ul><p>Enjoy using Zikula!</p><p><strong>The Zikula team</strong></p><p><em>Note: Zikula is Free Open Source Software (FOSS) licensed under the GNU General Public License.</em></p>'); |
||
| 191 | |||
| 192 | $blocks = []; |
||
| 193 | $extensionRepo = $this->entityManager->getRepository(ExtensionEntity::class); |
||
| 194 | $blocksModuleEntity = $extensionRepo->findOneBy(['name' => 'ZikulaBlocksModule']); |
||
| 195 | $searchModuleEntity = $extensionRepo->findOneBy(['name' => 'ZikulaSearchModule']); |
||
| 196 | $usersModuleEntity = $extensionRepo->findOneBy(['name' => 'ZikulaUsersModule']); |
||
| 197 | $blocks[] = [ |
||
| 198 | 'bkey' => SearchBlock::class, |
||
| 199 | 'blocktype' => 'Search', |
||
| 200 | 'language' => '', |
||
| 201 | 'module' => $searchModuleEntity, |
||
| 202 | 'title' => $this->trans('Search box'), |
||
| 203 | 'description' => $this->trans('Search block'), |
||
| 204 | 'properties' => [ |
||
| 205 | 'displaySearchBtn' => true, |
||
| 206 | 'active' => ['ZikulaUsersModule' => 1] |
||
| 207 | ], |
||
| 208 | 'position' => $positions['left'] |
||
| 209 | ]; |
||
| 210 | $blocks[] = [ |
||
| 211 | 'bkey' => HtmlBlock::class, |
||
| 212 | 'blocktype' => 'Html', |
||
| 213 | 'language' => '', |
||
| 214 | 'module' => $blocksModuleEntity, |
||
| 215 | 'title' => $this->trans('This site is powered by Zikula!'), |
||
| 216 | 'description' => $this->trans('HTML block'), |
||
| 217 | 'properties' => ['content' => $hellomessage], |
||
| 218 | 'position' => $positions['center'] |
||
| 219 | ]; |
||
| 220 | $blocks[] = [ |
||
| 221 | 'bkey' => LoginBlock::class, |
||
| 222 | 'blocktype' => 'Login', |
||
| 223 | 'language' => '', |
||
| 224 | 'module' => $usersModuleEntity, |
||
| 225 | 'title' => $this->trans('User log-in'), |
||
| 226 | 'description' => $this->trans('Login block'), |
||
| 227 | 'position' => $positions['topnav'], |
||
| 228 | 'order' => 1, |
||
| 229 | 'filters' => [[ |
||
| 230 | 'attribute' => '_route', |
||
| 231 | 'queryParameter' => null, |
||
| 232 | 'comparator' => '!=', |
||
| 233 | 'value' => 'zikulausersmodule_access_login' |
||
| 234 | ]] |
||
| 235 | ]; |
||
| 236 | |||
| 237 | foreach ($blocks as $block) { |
||
| 238 | $blockEntity = new BlockEntity(); |
||
| 239 | $position = $block['position']; |
||
| 240 | $sortOrder = !empty($block['order']) ? $block['order'] : 0; |
||
| 241 | unset($block['position'], $block['order']); |
||
| 242 | $blockEntity->merge($block); |
||
| 243 | $this->entityManager->persist($blockEntity); |
||
| 244 | $placement = new BlockPlacementEntity(); |
||
| 245 | $placement->setBlock($blockEntity); |
||
| 246 | $placement->setPosition($position); |
||
| 247 | $placement->setSortorder($sortOrder); |
||
| 248 | $this->entityManager->persist($placement); |
||
| 249 | } |
||
| 250 | $this->entityManager->flush(); |
||
| 251 | } |
||
| 253 |