| 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 |
||
| 114 | public function createDefaultData(): void |
||
| 115 | { |
||
| 116 | // create the default block positions - left, right and center for the traditional 3 column layout |
||
| 117 | $positions = [ |
||
| 118 | 'left' => $this->trans('Left blocks'), |
||
| 119 | 'right' => $this->trans('Right blocks'), |
||
| 120 | 'center' => $this->trans('Center blocks'), |
||
| 121 | 'search' => $this->trans('Search block'), |
||
| 122 | 'header' => $this->trans('Header block'), |
||
| 123 | 'footer' => $this->trans('Footer block'), |
||
| 124 | 'topnav' => $this->trans('Top navigation block'), |
||
| 125 | 'bottomnav' => $this->trans('Bottom navigation block') |
||
| 126 | ]; |
||
| 127 | foreach ($positions as $name => $description) { |
||
| 128 | $positions[$name] = new BlockPositionEntity(); |
||
| 129 | $positions[$name]->setName($name); |
||
| 130 | $positions[$name]->setDescription($description); |
||
| 131 | $this->entityManager->persist($positions[$name]); |
||
| 132 | } |
||
| 133 | $this->entityManager->flush(); |
||
| 134 | |||
| 135 | $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>'); |
||
| 136 | |||
| 137 | $blocks = []; |
||
| 138 | $extensionRepo = $this->entityManager->getRepository(ExtensionEntity::class); |
||
| 139 | $blocksModuleEntity = $extensionRepo->findOneBy(['name' => 'ZikulaBlocksModule']); |
||
| 140 | $searchModuleEntity = $extensionRepo->findOneBy(['name' => 'ZikulaSearchModule']); |
||
| 141 | $usersModuleEntity = $extensionRepo->findOneBy(['name' => 'ZikulaUsersModule']); |
||
| 142 | $blocks[] = [ |
||
| 143 | 'bkey' => SearchBlock::class, |
||
| 144 | 'blocktype' => 'Search', |
||
| 145 | 'language' => '', |
||
| 146 | 'module' => $searchModuleEntity, |
||
| 147 | 'title' => $this->trans('Search box'), |
||
| 148 | 'description' => $this->trans('Search block'), |
||
| 149 | 'properties' => [ |
||
| 150 | 'displaySearchBtn' => true, |
||
| 151 | 'active' => ['ZikulaUsersModule' => 1] |
||
| 152 | ], |
||
| 153 | 'position' => $positions['left'] |
||
| 154 | ]; |
||
| 155 | $blocks[] = [ |
||
| 156 | 'bkey' => HtmlBlock::class, |
||
| 157 | 'blocktype' => 'Html', |
||
| 158 | 'language' => '', |
||
| 159 | 'module' => $blocksModuleEntity, |
||
| 160 | 'title' => $this->trans('This site is powered by Zikula!'), |
||
| 161 | 'description' => $this->trans('HTML block'), |
||
| 162 | 'properties' => ['content' => $hellomessage], |
||
| 163 | 'position' => $positions['center'] |
||
| 164 | ]; |
||
| 165 | $blocks[] = [ |
||
| 166 | 'bkey' => LoginBlock::class, |
||
| 167 | 'blocktype' => 'Login', |
||
| 168 | 'language' => '', |
||
| 169 | 'module' => $usersModuleEntity, |
||
| 170 | 'title' => $this->trans('User log-in'), |
||
| 171 | 'description' => $this->trans('Login block'), |
||
| 172 | 'position' => $positions['topnav'], |
||
| 173 | 'order' => 1, |
||
| 174 | 'filters' => [[ |
||
| 175 | 'attribute' => '_route', |
||
| 176 | 'queryParameter' => null, |
||
| 177 | 'comparator' => '!=', |
||
| 178 | 'value' => 'zikulausersmodule_access_login' |
||
| 179 | ]] |
||
| 180 | ]; |
||
| 181 | |||
| 182 | foreach ($blocks as $block) { |
||
| 183 | $blockEntity = new BlockEntity(); |
||
| 184 | $position = $block['position']; |
||
| 185 | $sortOrder = !empty($block['order']) ? $block['order'] : 0; |
||
| 186 | unset($block['position'], $block['order']); |
||
| 187 | $blockEntity->merge($block); |
||
| 188 | $this->entityManager->persist($blockEntity); |
||
| 189 | $placement = new BlockPlacementEntity(); |
||
| 190 | $placement->setBlock($blockEntity); |
||
| 191 | $placement->setPosition($position); |
||
| 192 | $placement->setSortorder($sortOrder); |
||
| 193 | $this->entityManager->persist($placement); |
||
| 194 | } |
||
| 195 | $this->entityManager->flush(); |
||
| 196 | } |
||
| 198 |