Test Failed
Push — feature-laravel-5.4 ( bce2b2...556e60 )
by Kirill
03:14
created

HomeController::react()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 2
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of laravel.su package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace App\Http\Controllers;
11
12
use App\Models\Article;
13
use App\Models\User;
14
use Illuminate\Contracts\Auth\Guard;
15
use Illuminate\Contracts\View\View;
16
use Tymon\JWTAuth\Providers\JWT\JWTInterface;
17
18
/**
19
 * Class HomeController.
20
 */
21
class HomeController extends Controller
22
{
23
    /**
24
     * @return View
25
     */
26
    public function index(): View
27
    {
28
        return view('page.home.home', [
29
            'articles'      => Article::latestPublished()->take(11)->get(),
0 ignored issues
show
Bug introduced by
The method latestPublished() does not exist on App\Models\Article. Did you maybe mean scopeLatestPublished()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
30
            'articlesCount' => Article::latestPublished()->count(),
0 ignored issues
show
Bug introduced by
The method latestPublished() does not exist on App\Models\Article. Did you maybe mean scopeLatestPublished()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
31
        ]);
32
    }
33
34
    /**
35
     * @param JWTInterface $jwt
36
     * @param Guard        $guard
37
     * @return \Illuminate\Contracts\View\Factory|View|\Illuminate\View\View
38
     */
39
    public function react(JWTInterface $jwt, Guard $guard): View
40
    {
41
        $user = User::guest();
42
43
        if ($guard->check()) {
44
            $user = $guard->user();
45
        }
46
47
        return view('layout.react', [
48
            'token' => $jwt->encode([
49
                'user'  => [
50
                    'id'       => $user->getAuthIdentifier(),
51
                    'password' => $user->getAuthPassword(),
52
                ],
53
                'token' => $user->getRememberToken(),
54
            ]),
55
        ]);
56
    }
57
}
58