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.
Completed
Push — master ( 908067...0536c1 )
by K
04:51
created

GistsController::backup()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 8.9197
c 0
b 0
f 0
cc 4
eloc 12
nc 5
nop 1
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
        $state = collect([
23
            'user'  => 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...
24
            'gists' => $gistsAndTags['gists'],
25
            'tags'  => $gistsAndTags['tags']
26
        ]);
27
28
        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 28 which is incompatible with the return type documented by App\Http\Controllers\GistsController::index of type Illuminate\View\View.
Loading history...
29
    }
30
31
    /**
32
     * Backup authorized user gists.
33
     *
34
     * @param GistBackupHandler $backupHandler
35
     *
36
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
37
     */
38
    public function backup(GistBackupHandler $backupHandler)
39
    {
40
        if (auth()->user()->gists_backup_at) {
41
            $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...
42
            if ($lastBackup->gt(Carbon::now()->subMinutes(5))) {
43
                return response('WAIT_A_MINUTE', 429);
44
            };
45
        }
46
47
        $zipPath = $backupHandler->backup();
48
49
        if ($zipPath === 0) {
50
            return response('NO_FILES', 404);
51
        }
52
53
        auth()->user()->update(['gists_backup_at' => date('Y-m-d H:i:s')]);
54
55
        return response()->download($zipPath, null, [
56
            'Set-Cookie'   => 'fileDownload=true; path=/',
57
            'Content-Type' => 'application/zip'
58
        ]);
59
    }
60
}
61