| Conditions | 3 |
| Paths | 3 |
| Total Lines | 101 |
| 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 |
||
| 45 | public function createDefaultPages(User $user, AccessUrl $url, string $locale): bool |
||
| 46 | { |
||
| 47 | $categories = $this->pageCategoryRepository->findAll(); |
||
| 48 | |||
| 49 | if (!empty($categories)) { |
||
| 50 | return false; |
||
| 51 | } |
||
| 52 | |||
| 53 | $category = (new PageCategory()) |
||
| 54 | ->setTitle('home') |
||
| 55 | ->setType('grid') |
||
| 56 | ->setCreator($user) |
||
| 57 | ; |
||
| 58 | $this->pageCategoryRepository->update($category); |
||
| 59 | |||
| 60 | $indexCategory = (new PageCategory()) |
||
| 61 | ->setTitle('index') |
||
| 62 | ->setType('grid') |
||
| 63 | ->setCreator($user) |
||
| 64 | ; |
||
| 65 | $this->pageCategoryRepository->update($indexCategory); |
||
| 66 | |||
| 67 | $indexCategory = (new PageCategory()) |
||
| 68 | ->setTitle('faq') |
||
| 69 | ->setType('grid') |
||
| 70 | ->setCreator($user) |
||
| 71 | ; |
||
| 72 | $this->pageCategoryRepository->update($indexCategory); |
||
| 73 | |||
| 74 | $indexCategory = (new PageCategory()) |
||
| 75 | ->setTitle('demo') |
||
| 76 | ->setType('grid') |
||
| 77 | ->setCreator($user) |
||
| 78 | ; |
||
| 79 | $this->pageCategoryRepository->update($indexCategory); |
||
| 80 | |||
| 81 | $page = (new Page()) |
||
| 82 | ->setTitle('Welcome') |
||
| 83 | ->setContent('Welcome to Chamilo') |
||
| 84 | ->setCategory($category) |
||
| 85 | ->setCreator($user) |
||
| 86 | ->setLocale($locale) |
||
| 87 | ->setEnabled(true) |
||
| 88 | ->setUrl($url) |
||
| 89 | ; |
||
| 90 | |||
| 91 | $this->pageRepository->update($page); |
||
| 92 | |||
| 93 | $indexPage = (new Page()) |
||
| 94 | ->setTitle('Welcome') |
||
| 95 | ->setContent('<img src="/img/document/images/mr_chamilo/svg/teaching.svg" />') |
||
| 96 | ->setCategory($indexCategory) |
||
| 97 | ->setCreator($user) |
||
| 98 | ->setLocale($locale) |
||
| 99 | ->setEnabled(true) |
||
| 100 | ->setUrl($url) |
||
| 101 | ; |
||
| 102 | $this->pageRepository->update($indexPage); |
||
| 103 | |||
| 104 | $footerPublicCategory = (new PageCategory()) |
||
| 105 | ->setTitle('footer_public') |
||
| 106 | ->setType('grid') |
||
| 107 | ->setCreator($user) |
||
| 108 | ; |
||
| 109 | |||
| 110 | $this->pageCategoryRepository->update($footerPublicCategory); |
||
| 111 | |||
| 112 | $footerPrivateCategory = (new PageCategory()) |
||
| 113 | ->setTitle('footer_private') |
||
| 114 | ->setType('grid') |
||
| 115 | ->setCreator($user) |
||
| 116 | ; |
||
| 117 | |||
| 118 | $this->pageCategoryRepository->update($footerPrivateCategory); |
||
| 119 | |||
| 120 | // Categories for extra content in admin blocks. |
||
| 121 | foreach (self::getCategoriesForAdminBlocks() as $nameBlock) { |
||
| 122 | $usersAdminBlock = (new PageCategory()) |
||
| 123 | ->setTitle($nameBlock) |
||
| 124 | ->setType('grid') |
||
| 125 | ->setCreator($user) |
||
| 126 | ; |
||
| 127 | $this->pageCategoryRepository->update($usersAdminBlock); |
||
| 128 | } |
||
| 129 | |||
| 130 | $publicCategory = (new PageCategory()) |
||
| 131 | ->setTitle('public') |
||
| 132 | ->setType('grid') |
||
| 133 | ->setCreator($user) |
||
| 134 | ; |
||
| 135 | |||
| 136 | $this->pageCategoryRepository->update($publicCategory); |
||
| 137 | |||
| 138 | $introductionCategory = (new PageCategory()) |
||
| 139 | ->setTitle('introduction') |
||
| 140 | ->setType('grid') |
||
| 141 | ->setCreator($user) |
||
| 142 | ; |
||
| 143 | $this->pageCategoryRepository->update($introductionCategory); |
||
| 144 | |||
| 145 | return true; |
||
| 146 | } |
||
| 227 |