| Conditions | 3 |
| Paths | 3 |
| Total Lines | 99 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | $adminBlocks = [ |
||
| 105 | 'block-admin-users', |
||
| 106 | 'block-admin-courses', |
||
| 107 | 'block-admin-sessions', |
||
| 108 | 'block-admin-gradebook', |
||
| 109 | 'block-admin-skills', |
||
| 110 | 'block-admin-privacy', |
||
| 111 | 'block-admin-settings', |
||
| 112 | 'block-admin-platform', |
||
| 113 | 'block-admin-chamilo', |
||
| 114 | ]; |
||
| 115 | |||
| 116 | foreach ($adminBlocks as $nameBlock) { |
||
| 117 | $usersAdminBlock = (new PageCategory()) |
||
| 118 | ->setTitle($nameBlock) |
||
| 119 | ->setType('grid') |
||
| 120 | ->setCreator($user) |
||
| 121 | ; |
||
| 122 | $this->pageCategoryRepository->update($usersAdminBlock); |
||
| 123 | } |
||
| 124 | |||
| 125 | return true; |
||
| 126 | } |
||
| 128 |