RegistrationController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
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\Tenantarea;
6
7
use Cortex\Auth\Models\Member;
8
use Illuminate\Auth\Events\Registered;
9
use Cortex\Foundation\Http\Controllers\AbstractController;
10
use Cortex\Auth\Http\Requests\Tenantarea\RegistrationRequest;
11
use Cortex\Auth\Http\Requests\Tenantarea\RegistrationProcessRequest;
12
13
class RegistrationController extends AbstractController
14
{
15
    /**
16
     * Create a new registration controller instance.
17
     */
18
    public function __construct()
19
    {
20
        parent::__construct();
21
22
        $this->middleware($this->getGuestMiddleware())->except($this->middlewareWhitelist);
23
    }
24
25
    /**
26
     * Show the registration form.
27
     *
28
     * @param \Cortex\Auth\Http\Requests\Tenantarea\RegistrationRequest $request
29
     *
30
     * @return \Illuminate\View\View
31
     */
32
    public function form(RegistrationRequest $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...
33
    {
34
        return view('cortex/auth::tenantarea.pages.member-registration');
35
    }
36
37
    /**
38
     * Process the registration form.
39
     *
40
     * @param \Cortex\Auth\Http\Requests\Tenantarea\RegistrationProcessRequest $request
41
     * @param \Cortex\Auth\Models\Member                                       $member
42
     *
43
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
44
     */
45
    public function register(RegistrationProcessRequest $request, Member $member)
46
    {
47
        // Prepare registration data
48
        $data = $request->validated();
49
50
        $member->fill($data)->save();
51
52
        // Fire the register success event
53
        event(new Registered($member));
54
55
        // Send verification if required
56
        ! config('cortex.auth.emails.verification')
57
        || app('rinvex.auth.emailverification')->broker($this->getEmailVerificationBroker())->sendVerificationLink(['email' => $data['email']]);
58
59
        // Auto-login registered member
60
        auth()->guard($this->getGuard())->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...
61
62
        // Registration completed successfully
63
        return intend([
64
            'intended' => route('tenantarea.home'),
65
            'with' => ['success' => trans('cortex/auth::messages.register.success')],
66
        ]);
67
    }
68
}
69