| Conditions | 3 |
| Paths | 3 |
| Total Lines | 95 |
| Code Lines | 63 |
| 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 |
||
| 27 | public function createDefaultPages(User $user, AccessUrl $url, string $locale): bool |
||
| 28 | { |
||
| 29 | $categories = $this->pageCategoryRepository->findAll(); |
||
| 30 | |||
| 31 | if (!empty($categories)) { |
||
| 32 | return false; |
||
| 33 | } |
||
| 34 | |||
| 35 | $category = (new PageCategory()) |
||
| 36 | ->setTitle('home') |
||
| 37 | ->setType('grid') |
||
| 38 | ->setCreator($user) |
||
| 39 | ; |
||
| 40 | $this->pageCategoryRepository->update($category); |
||
| 41 | |||
| 42 | $indexCategory = (new PageCategory()) |
||
| 43 | ->setTitle('index') |
||
| 44 | ->setType('grid') |
||
| 45 | ->setCreator($user) |
||
| 46 | ; |
||
| 47 | $this->pageCategoryRepository->update($indexCategory); |
||
| 48 | |||
| 49 | $indexCategory = (new PageCategory()) |
||
| 50 | ->setTitle('faq') |
||
| 51 | ->setType('grid') |
||
| 52 | ->setCreator($user) |
||
| 53 | ; |
||
| 54 | $this->pageCategoryRepository->update($indexCategory); |
||
| 55 | |||
| 56 | $indexCategory = (new PageCategory()) |
||
| 57 | ->setTitle('demo') |
||
| 58 | ->setType('grid') |
||
| 59 | ->setCreator($user) |
||
| 60 | ; |
||
| 61 | $this->pageCategoryRepository->update($indexCategory); |
||
| 62 | |||
| 63 | $page = (new Page()) |
||
| 64 | ->setTitle('Welcome') |
||
| 65 | ->setContent('Welcome to Chamilo') |
||
| 66 | ->setCategory($category) |
||
| 67 | ->setCreator($user) |
||
| 68 | ->setLocale($locale) |
||
| 69 | ->setEnabled(true) |
||
| 70 | ->setUrl($url) |
||
| 71 | ; |
||
| 72 | |||
| 73 | $this->pageRepository->update($page); |
||
| 74 | |||
| 75 | $indexPage = (new Page()) |
||
| 76 | ->setTitle('Welcome') |
||
| 77 | ->setContent('<img src="/img/document/images/mr_chamilo/svg/teaching.svg" />') |
||
| 78 | ->setCategory($indexCategory) |
||
| 79 | ->setCreator($user) |
||
| 80 | ->setLocale($locale) |
||
| 81 | ->setEnabled(true) |
||
| 82 | ->setUrl($url) |
||
| 83 | ; |
||
| 84 | $this->pageRepository->update($indexPage); |
||
| 85 | |||
| 86 | $footerPublicCategory = (new PageCategory()) |
||
| 87 | ->setTitle('footer_public') |
||
| 88 | ->setType('grid') |
||
| 89 | ->setCreator($user) |
||
| 90 | ; |
||
| 91 | |||
| 92 | $this->pageCategoryRepository->update($footerPublicCategory); |
||
| 93 | |||
| 94 | $footerPrivateCategory = (new PageCategory()) |
||
| 95 | ->setTitle('footer_private') |
||
| 96 | ->setType('grid') |
||
| 97 | ->setCreator($user) |
||
| 98 | ; |
||
| 99 | |||
| 100 | $this->pageCategoryRepository->update($footerPrivateCategory); |
||
| 101 | |||
| 102 | // Categories for extra content in admin blocks |
||
| 103 | |||
| 104 | foreach (self::getCategoriesForAdminBlocks() as $nameBlock) { |
||
| 105 | $usersAdminBlock = (new PageCategory()) |
||
| 106 | ->setTitle($nameBlock) |
||
| 107 | ->setType('grid') |
||
| 108 | ->setCreator($user) |
||
| 109 | ; |
||
| 110 | $this->pageCategoryRepository->update($usersAdminBlock); |
||
| 111 | } |
||
| 112 | |||
| 113 | $publicCategory = (new PageCategory()) |
||
| 114 | ->setTitle('public') |
||
| 115 | ->setType('grid') |
||
| 116 | ->setCreator($user) |
||
| 117 | ; |
||
| 118 | |||
| 119 | $this->pageCategoryRepository->update($publicCategory); |
||
| 120 | |||
| 121 | return true; |
||
| 122 | } |
||
| 139 |