Passed
Push — 5.0.0 ( f10804...44b42e )
by Fèvre
15:04 queued 07:40
created

AccountController::update()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 30
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 21
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 30
rs 9.584
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Http\Controllers\User;
6
7
use Illuminate\Http\RedirectResponse;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Auth;
10
use Illuminate\View\View;
11
use Xetaio\Mentions\Parser\MentionParser;
12
use Xetaravel\Http\Controllers\Controller;
13
use Xetaravel\Models\Repositories\AccountRepository;
14
use Xetaravel\Models\User;
15
use Xetaravel\Models\Validators\AccountValidator;
0 ignored issues
show
Bug introduced by
The type Xetaravel\Models\Validators\AccountValidator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
class AccountController extends Controller
18
{
19
    /**
20
     * Show the account update form.
21
     *
22
     * @return View
23
     */
24
    public function index(): View
25
    {
26
        $user = User::with('account')->find(Auth::id());
27
28
        $this->breadcrumbs->addCrumb('
29
                <svg class="inline w-5 h-5 mr-2" fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M224 256A128 128 0 1 0 224 0a128 128 0 1 0 0 256zm-45.7 48C79.8 304 0 383.8 0 482.3C0 498.7 13.3 512 29.7 512l293.1 0c-3.1-8.8-3.7-18.4-1.4-27.8l15-60.1c2.8-11.3 8.6-21.5 16.8-29.7l40.3-40.3c-32.1-31-75.7-50.1-123.9-50.1l-91.4 0zm435.5-68.3c-15.6-15.6-40.9-15.6-56.6 0l-29.4 29.4 71 71 29.4-29.4c15.6-15.6 15.6-40.9 0-56.6l-14.4-14.4zM375.9 417c-4.1 4.1-7 9.2-8.4 14.9l-15 60.1c-1.4 5.5 .2 11.2 4.2 15.2s9.7 5.6 15.2 4.2l60.1-15c5.6-1.4 10.8-4.3 14.9-8.4L576.1 358.7l-71-71L375.9 417z"></path></svg>
30
                Account', route('user.account.index'));
31
32
        return view('account.index', ['user' => $user, 'breadcrumbs' => $this->breadcrumbs]);
33
    }
34
35
    /**
36
     * Handle an account update request for the application.
37
     *
38
     * @param Request $request
39
     *
40
     * @return RedirectResponse
41
     */
42
    public function update(Request $request): RedirectResponse
43
    {
44
        AccountValidator::update($request->all())->validate();
45
        $account = AccountRepository::update($request->all(), Auth::id());
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Facades\Auth::id() can also be of type null and string; however, parameter $id of Xetaravel\Models\Reposit...untRepository::update() does only seem to accept integer, 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

45
        $account = AccountRepository::update($request->all(), /** @scrutinizer ignore-type */ Auth::id());
Loading history...
46
47
        $parser = new MentionParser($account, [
48
            'regex' => config('mentions.regex'),
49
            'mention' => false
50
        ]);
51
        $signature = $parser->parse($account->signature);
52
        $biography = $parser->parse($account->biography);
53
54
        $account->signature = $signature;
55
        $account->biography = $biography;
56
        $account->save();
57
58
        $user = User::find(Auth::id());
59
60
        if (!is_null($request->file('avatar'))) {
61
            $user->clearMediaCollection('avatar');
62
            $user->addMedia($request->file('avatar'))
63
                ->preservingOriginal()
64
                ->setName(mb_substr(md5($user->username), 0, 10))
65
                ->setFileName(mb_substr(md5($user->username), 0, 10))
66
                ->toMediaCollection('avatar');
67
        }
68
69
        return redirect()
70
            ->route('user.account.index')
0 ignored issues
show
Bug introduced by
The method route() does not exist on Illuminate\Routing\Redirector. ( Ignorable by Annotation )

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

70
            ->/** @scrutinizer ignore-call */ route('user.account.index')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
            ->success('Your account has been updated successfully !');
72
    }
73
}
74