MemberRegistrationController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A form() 0 4 1
A register() 0 23 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Auth\Http\Controllers\Frontarea;
6
7
use Cortex\Auth\Models\Member;
8
use Illuminate\Auth\Events\Registered;
9
use Cortex\Auth\Http\Requests\Frontarea\MemberRegistrationRequest;
10
use Cortex\Auth\Http\Requests\Frontarea\MemberRegistrationProcessRequest;
11
12
class MemberRegistrationController extends RegistrationController
13
{
14
    /**
15
     * Show the registration form.
16
     *
17
     * @param \Cortex\Auth\Http\Requests\Frontarea\MemberRegistrationRequest $request
18
     *
19
     * @return \Illuminate\View\View
20
     */
21
    public function form(MemberRegistrationRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
    {
23
        return view('cortex/auth::frontarea.pages.member-registration');
24
    }
25
26
    /**
27
     * Process the registration form.
28
     *
29
     * @param \Cortex\Auth\Http\Requests\Frontarea\MemberRegistrationProcessRequest $request
30
     * @param \Cortex\Auth\Models\Member                                            $member
31
     *
32
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
33
     */
34
    public function register(MemberRegistrationProcessRequest $request, Member $member)
35
    {
36
        // Prepare registration data
37
        $data = $request->validated();
38
39
        $member->fill($data)->save();
40
41
        // Fire the register success event
42
        event(new Registered($member));
43
44
        // Send verification if required
45
        ! config('cortex.auth.emails.verification')
46
        || app('rinvex.auth.emailverification')->broker($this->getEmailVerificationBroker())->sendVerificationLink(['email' => $member->email]);
47
48
        // Auto-login registered member
49
        auth()->guard(config('auth.defaults.guard'))->login($member);
0 ignored issues
show
Bug introduced by
The method guard does only exist in Illuminate\Contracts\Auth\Factory, but not in Illuminate\Contracts\Auth\Guard.

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...
50
51
        // Registration completed successfully
52
        return intend([
53
            'intended' => route('frontarea.home'),
54
            'with' => ['success' => trans('cortex/auth::messages.register.success')],
55
        ]);
56
    }
57
}
58