LaravelLocalization::unparseUrl()   F
last analyzed

Complexity

Conditions 14
Paths 1025

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 2.1
c 0
b 0
f 0
cc 14
nc 1025
nop 1

How to fix   Complexity   

Long Method

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:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Foundation\Overrides\Mcamara\LaravelLocalization;
6
7
use Mcamara\LaravelLocalization\LaravelLocalization as BaseLaravelLocalization;
8
9
class LaravelLocalization extends BaseLaravelLocalization
10
{
11
    /**
12
     * Return default application locales.
13
     *
14
     * @return array
15
     */
16
    public function getAppLocales(): array
17
    {
18
        return array_unique([
19
            $this->configRepository->get('app.locale'),
20
            $this->configRepository->get('app.fallback_locale'),
21
        ]);
22
    }
23
24
    /**
25
     * Build URL using array data from parse_url.
26
     *
27
     * @param array|false $parsed_url Array of data from parse_url function
28
     *
29
     * @return string Returns URL as string.
30
     */
31
    protected function unparseUrl($parsed_url)
32
    {
33
        if (empty($parsed_url)) {
34
            return '';
35
        }
36
37
        $url = '';
38
        $url .= isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : '';
39
        $url .= $parsed_url['host'] ?? '';
40
        $url .= isset($parsed_url['port']) ? ':'.$parsed_url['port'] : '';
41
        $user = $parsed_url['user'] ?? '';
42
        $pass = isset($parsed_url['pass']) ? ':'.$parsed_url['pass'] : '';
43
        $url .= $user.(($user || $pass) ? "{$pass}@" : '');
44
45
        if (! empty($url)) {
46
            $url .= isset($parsed_url['path']) ? '/'.ltrim($parsed_url['path'], '/').(config('cortex.foundation.route.trailing_slash') ? '/' : '') : '';
47
        } else {
48
            $url .= isset($parsed_url['path']) ? $parsed_url['path'].(config('cortex.foundation.route.trailing_slash') ? '/' : '') : '';
49
        }
50
51
        $url .= isset($parsed_url['query']) ? '?'.$parsed_url['query'] : '';
52
        $url .= isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment'] : '';
53
54
        return $url;
55
    }
56
}
57