| Conditions | 10 |
| Paths | 512 |
| Total Lines | 30 |
| Code Lines | 21 |
| 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 |
||
| 29 | #[Route('/_topbar-visibility', name: 'public_topbar_visibility', methods: ['GET'])] |
||
| 30 | public function topbarVisibility(Request $request, PageRepository $pageRepo): JsonResponse |
||
| 31 | { |
||
| 32 | $accessUrl = $this->accessUrlHelper->getCurrent(); |
||
| 33 | $locale = trim((string) $request->query->get('locale', '')); |
||
| 34 | |||
| 35 | // We first try exact locale, then fallback to the 2-letter prefix. |
||
| 36 | $prefix = $locale !== '' ? substr($locale, 0, 2) : ''; |
||
| 37 | |||
| 38 | $homeExact = $locale !== '' ? $pageRepo->countByCategoryAndLocale($accessUrl, 'index', $locale) : 0; |
||
| 39 | $homePrefix = $prefix !== '' ? $pageRepo->countByCategoryAndLocalePrefix($accessUrl, 'index', $prefix) : 0; |
||
| 40 | $home = ($homeExact + $homePrefix) > 0; |
||
| 41 | |||
| 42 | $faqExact = $locale !== '' ? $pageRepo->countByCategoryAndLocale($accessUrl, 'faq', $locale) : 0; |
||
| 43 | $faqPrefix = $prefix !== '' ? $pageRepo->countByCategoryAndLocalePrefix($accessUrl, 'faq', $prefix) : 0; |
||
| 44 | $faq = ($faqExact + $faqPrefix) > 0; |
||
| 45 | |||
| 46 | $demoExact = $locale !== '' ? $pageRepo->countByCategoryAndLocale($accessUrl, 'demo', $locale) : 0; |
||
| 47 | $demoPrefix = $prefix !== '' ? $pageRepo->countByCategoryAndLocalePrefix($accessUrl, 'demo', $prefix) : 0; |
||
| 48 | $demo = ($demoExact + $demoPrefix) > 0; |
||
| 49 | |||
| 50 | $contactExact = $locale !== '' ? $pageRepo->countByCategoryAndLocale($accessUrl, 'contact', $locale) : 0; |
||
| 51 | $contactPrefix = $prefix !== '' ? $pageRepo->countByCategoryAndLocalePrefix($accessUrl, 'contact', $prefix) : 0; |
||
| 52 | $contact = ($contactExact + $contactPrefix) > 0; |
||
| 53 | |||
| 54 | return $this->json([ |
||
| 55 | 'home' => $home, |
||
| 56 | 'faq' => $faq, |
||
| 57 | 'demo' => $demo, |
||
| 58 | 'contact' => $contact, |
||
| 59 | ]); |
||
| 97 |