PackagistVersion   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 21 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Http\Middleware;
6
7
use Closure;
8
use GuzzleHttp\Client;
9
use Illuminate\Http\Request;
10
use Illuminate\Support\Facades\Cache;
11
12
class PackagistVersion
13
{
14
    /**
15
     * Handle an incoming request.
16
     *
17
     * @param  Request  $request
18
     * @param  Closure  $next
19
     * @param string|null $guard
20
     * @return mixed
21
     */
22
    public function handle(Request $request, Closure $next, string $guard = null): mixed
0 ignored issues
show
Unused Code introduced by
The parameter $guard is not used and could be removed. ( Ignorable by Annotation )

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

22
    public function handle(Request $request, Closure $next, /** @scrutinizer ignore-unused */ string $guard = null): mixed

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    {
24
        $version = Cache::remember(
25
            'Packagist.version',
26
            config('xetaravel.site.packagist_cache_timeout'),
27
            function () {
28
                $client = new Client();
29
                $res = $client->request('GET', config('xetaravel.site.packagist_url'));
30
                if ($res->getStatusCode() !== 200) {
31
                    return false;
32
                }
33
34
                $array = json_decode($res->getBody()->getContents(), true);
35
36
                return $array['packages']['xetaio/xetaravel'][0]['version'];
37
            }
38
        );
39
40
        config(['xetaravel.version' => $version]);
41
42
        return $next($request);
43
    }
44
}
45