Completed
Push — master ( 907be4...4d46ed )
by Arthur
05:36
created

MemberInductionController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.4286
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
3
namespace BB\Http\Controllers;
4
5
use BB\Entities\User;
6
use BB\Repo\PolicyRepository;
7
use BB\Repo\UserRepository;
8
use BB\Validators\InductionValidator;
9
use Illuminate\Http\Request;
10
use BB\Http\Requests;
11
use Michelf\Markdown;
12
13
class MemberInductionController extends Controller
14
{
15
16
    /**
17
     * @var PolicyRepository
18
     */
19
    private $policyRepository;
20
    /**
21
     * @var UserRepository
22
     */
23
    private $userRepository;
24
    /**
25
     * @var InductionValidator
26
     */
27
    private $inductionValidator;
28
29
    function __construct(PolicyRepository $policyRepository, UserRepository $userRepository, InductionValidator $inductionValidator)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
30
    {
31
        $this->policyRepository = $policyRepository;
32
        $this->userRepository = $userRepository;
33
        $this->inductionValidator = $inductionValidator;
34
    }
35
36
    /**
37
     * Display a listing of the resource.
38
     *
39
     * @return \Illuminate\Http\Response
40
     */
41
    public function index()
42
    {
43
        //
44
    }
45
46
    /**
47
     * Display the specified resource.
48
     *
49
     * @param  int  $id
50
     * @return \Illuminate\Http\Response
51
     */
52
    public function show($id)
53
    {
54
        $user = User::findWithPermission($id);
55
56
        $document = $this->policyRepository->getByName('member-agreement');
57
58
        $htmlDocument = Markdown::defaultTransform($document);
59
60
        return view('account.induction')->with('user', $user)->with('document', $htmlDocument);
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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
63
    /**
64
     * Update the specified resource in storage.
65
     *
66
     * @param  \Illuminate\Http\Request  $request
67
     * @param  int  $id
68
     * @return \Illuminate\Http\Response
69
     */
70
    public function update(Request $request, $id)
71
    {
72
        $user = User::findWithPermission($id);
73
74
        $input = $request->only('rules_agreed', 'induction_completed');
75
76
        $this->inductionValidator->validate($input);
77
78
        $this->userRepository->recordInductionCompleted($id);
79
80
        return \Redirect::route('account.show', [$user->id]);
0 ignored issues
show
Bug introduced by
The method route() does not seem to exist on object<redirect>.

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...
81
    }
82
}
83