Completed
Push — master ( ba882f...81a586 )
by Mark
20s queued 14s
created

IndexController::version()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Socialblue\LaravelQueryAdviser\Http\Controllers;
4
5
use Composer\InstalledVersions;
6
use Illuminate\Http\Response;
7
use Illuminate\Routing\Controller;
8
use Illuminate\Support\Facades\Http;
9
use Socialblue\LaravelQueryAdviser\Helper\QueryBuilderHelper;
10
11
/**
12
 * Class QueryController
13
 * @package Socialblue\LaravelQueryAdviser\Http\Controllers
14
 */
15
class IndexController extends Controller
16
{
17
    /**
18
     * Show view
19
     *
20
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
21
     */
22
    public function index()
23
    {
24
        return view('QueryAdviser::index');
25
    }
26
27
    public function serverInfo(): array
28
    {
29
        return QueryBuilderHelper::getServerInfo();
30
    }
31
32
    public function version()
33
    {
34
        $installedVersion = InstalledVersions::getPrettyVersion('socialblue/laravel-query-adviser');
35
        $latestVersion = Http::get('https://api.github.com/repos/socialblue/laravel-query-adviser/releases/latest')
36
            ->json('tag_name');
37
38
        return (new Response([
39
            'installed' => $installedVersion,
40
            'latest' => $latestVersion,
41
            'update' => version_compare($installedVersion, $latestVersion),
0 ignored issues
show
Bug introduced by
It seems like $installedVersion can also be of type null; however, parameter $version1 of version_compare() 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

41
            'update' => version_compare(/** @scrutinizer ignore-type */ $installedVersion, $latestVersion),
Loading history...
42
        ]))->header('Access-Control-Allow-Origin', '*');
43
    }
44
}
45