GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

GistsController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 6
dl 0
loc 57
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 17 1
B backup() 0 22 4
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Helpers\GistBackupHandler;
6
use App\Helpers\GistFinder;
7
use Carbon\Carbon;
8
9
class GistsController extends Controller
10
{
11
    /**
12
     * Show gists list.
13
     *
14
     * @param GistFinder $gistFinder
15
     *
16
     * @return \Illuminate\View\View
17
     */
18
    public function index(GistFinder $gistFinder)
19
    {
20
        $gistsAndTags = $gistFinder->getGistsAndTags();
21
22
        $authUser = auth()->user();
0 ignored issues
show
Bug introduced by
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
23
        $state = collect([
24
            'user'  => [
25
                'name'     => $authUser->name,
26
                'nickname' => $authUser->nickname,
27
                'avatar'   => $authUser->avatar
28
            ],
29
            'gists' => $gistsAndTags['gists'],
30
            'tags'  => $gistsAndTags['tags']
31
        ]);
32
33
        return view('gists.index', compact('state'));
0 ignored issues
show
Bug Compatibility introduced by
The expression view('gists.index', compact('state')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 33 which is incompatible with the return type documented by App\Http\Controllers\GistsController::index of type Illuminate\View\View.
Loading history...
34
    }
35
36
    /**
37
     * Backup authorized user gists.
38
     *
39
     * @param GistBackupHandler $backupHandler
40
     *
41
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
42
     */
43
    public function backup(GistBackupHandler $backupHandler)
44
    {
45
        if (auth()->user()->gists_backup_at) {
46
            $lastBackup = Carbon::createFromFormat('Y-m-d H:i:s', auth()->user()->gists_backup_at);
0 ignored issues
show
Bug introduced by
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
47
            if ($lastBackup->gt(Carbon::now()->subMinutes(5))) {
48
                return response('WAIT_A_MINUTE', 429);
49
            };
50
        }
51
52
        $zipPath = $backupHandler->backup();
53
54
        if ($zipPath === 0) {
55
            return response('NO_FILES', 404);
56
        }
57
58
        auth()->user()->update(['gists_backup_at' => date('Y-m-d H:i:s')]);
59
60
        return response()->download($zipPath, null, [
61
            'Set-Cookie'   => 'fileDownload=true; path=/',
62
            'Content-Type' => 'application/zip'
63
        ])->deleteFileAfterSend(true);
64
    }
65
}
66