LocaleInCookie   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 5 2
A match() 0 3 1
1
<?php
2
3
namespace mindtwo\LaravelMultilingual\Http\Middleware\LocaleDetectors;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Crypt;
7
use mindtwo\LaravelMultilingual\Services\Locale;
8
9
class LocaleInCookie implements LocaleDetector
10
{
11
    /**
12
     * @param Request $request
13
     * @param Locale  $locale
14
     *
15
     * @return bool
16
     */
17
    public function match(Request $request, Locale $locale): bool
18
    {
19
        return $request->hasCookie('locale');
20
    }
21
22
    /**
23
     * @param Request $request
24
     * @param Locale  $locale
25
     *
26
     * @return string
27
     */
28
    public function get(Request $request, Locale $locale): string
29
    {
30
        $locale = $request->cookie('locale');
31
32
        return strlen($locale) > 5 ? Crypt::decrypt($locale) : $locale;
0 ignored issues
show
Bug Best Practice introduced by
The expression return strlen($locale) >...rypt($locale) : $locale could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
Bug introduced by
It seems like $locale can also be of type array; however, parameter $string of strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
        return strlen(/** @scrutinizer ignore-type */ $locale) > 5 ? Crypt::decrypt($locale) : $locale;
Loading history...
Bug introduced by
It seems like $locale can also be of type array; however, parameter $payload of Illuminate\Support\Facades\Crypt::decrypt() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
        return strlen($locale) > 5 ? Crypt::decrypt(/** @scrutinizer ignore-type */ $locale) : $locale;
Loading history...
33
    }
34
}
35