HeaderConversion   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 48.28 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 14
loc 29
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A convert() 14 21 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * CalamandreiLorenzo\LaravelBrowserLang
4
 */
5
6
namespace CalamandreiLorenzo\LaravelBrowserLang;
7
8
use Illuminate\Support\Facades\App;
9
10
/**
11
 * Class HeaderConversion
12
 * @package CalamandreiLorenzo\LaravelBrowserLang
13
 * @author Lorenzo Calamandrei <[email protected]>
14
 * @github https://github.com/CalamandreiLorenzo
15
 */
16
class HeaderConversion implements HeaderConversionInterface
17
{
18
    /**
19
     * convert
20
     * @param string $header
21
     * @return string
22
     */
23 3
    public function convert(string $header): string
24
    {
25 3
        $langs = collect(explode(',', $header))->map(static function (string $lang) {
26 3 View Code Duplication
            if (str_contains($lang, ';')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27 1
                $langWithQ = explode(';', $lang);
28 1
                return collect([
29 1
                    'locale' => $langWithQ[0],
30 1
                    'q-factor' => $langWithQ[1]
31
                ]);
32
            }
33 3 View Code Duplication
            if (str_contains($lang, '-')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34 3
                $langParam = explode('-', $lang)[0];
35 3
                return collect([
36 3
                    'locale' => $langParam,
37
                    'q-factor' => null
38
                ]);
39
            }
40
            return $lang;
41 3
        })->whereIn('locale', config('browser-lang.available_locales', ['en']));
42 3
        return $langs->first()->get('locale', App::getLocale());
43
    }
44
}
45