Completed
Push — develop ( a15bf8...2ec1b5 )
by Abdelrahman
01:44
created

RegistrationController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Tenants\Http\Controllers\Frontarea;
6
7
use Rinvex\Fort\Contracts\UserContract;
8
use Cortex\Foundation\Http\Controllers\AbstractController;
9
use Cortex\Tenants\Http\Requests\Frontarea\RegistrationRequest;
10
use Cortex\Tenants\Http\Requests\Frontarea\RegistrationProcessRequest;
11
use Rinvex\Tenants\Contracts\TenantContract;
12
13
class RegistrationController extends AbstractController
14
{
15
    /**
16
     * Create a new registration controller instance.
17
     */
18
    public function __construct()
19
    {
20
        $this->middleware($this->getGuestMiddleware(), ['except' => $this->middlewareWhitelist]);
21
    }
22
23
    /**
24
     * Show the registration form.
25
     *
26
     * @param \Cortex\Fort\Http\Requests\Frontarea\RegistrationRequest $request
0 ignored issues
show
Documentation introduced by
Should the type for parameter $request not be RegistrationRequest?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
27
     *
28
     * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
29
     */
30
    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...
31
    {
32
        $countries = countries();
33
        $languages = collect(languages())->pluck('name', 'iso_639_1');
34
35
        return view('cortex/tenants::frontarea.pages.registration', compact('countries', 'languages'));
36
    }
37
38
    /**
39
     * Process the registration form.
40
     *
41
     * @param \Cortex\Fort\Http\Requests\Frontarea\RegistrationProcessRequest $request
0 ignored issues
show
Documentation introduced by
Should the type for parameter $request not be RegistrationProcessRequest?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
42
     * @param \Rinvex\Fort\Contracts\UserContract                             $user
43
     * @param \Rinvex\Tenants\Contracts\TenantContract                        $tenant
44
     *
45
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
46
     */
47
    public function register(RegistrationProcessRequest $request, UserContract $user, TenantContract $tenant)
48
    {
49
        // Prepare registration data
50
        $userInput = $request->get('user');
51
52
        // Fire the register start event
53
        event('rinvex.fort.register.start', [$userInput]);
54
55
        $user->fill($userInput)->save();
56
57
        // Save hub
58
        $tenantInput = $request->get('tenant') + ['owner_id' => $user->id];
0 ignored issues
show
Bug introduced by
Accessing id on the interface Rinvex\Fort\Contracts\UserContract suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
59
        $tenant->fill($tenantInput)->save();
60
61
        // Fire the register success event
62
        event('rinvex.fort.register.success', [$user]);
63
64
        // Send verification if required
65
        ! config('rinvex.fort.emailverification.required')
66
        || app('rinvex.fort.emailverification')->broker()->sendVerificationLink(['email' => $user->email]);
0 ignored issues
show
Bug introduced by
Accessing email on the interface Rinvex\Fort\Contracts\UserContract suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
67
68
        // Registration completed successfully
69
        return view('cortex/tenants::frontarea.pages.registration_success', compact('user', 'tenant'));
70
    }
71
}
72