| 1 | <?php |
||
| 26 | class ProjectsController extends Controller |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * Display list of active/archived projects. |
||
| 30 | * |
||
| 31 | * @param int $status |
||
| 32 | * |
||
| 33 | * @return \Illuminate\View\View |
||
| 34 | */ |
||
| 35 | 5 | public function getIndex($status = Project::STATUS_OPEN) |
|
| 69 | |||
| 70 | /** |
||
| 71 | * Add new project form. |
||
| 72 | * |
||
| 73 | * @param Form $form |
||
| 74 | * |
||
| 75 | * @return \Illuminate\View\View |
||
| 76 | */ |
||
| 77 | 1 | public function getNew(Form $form) |
|
| 78 | { |
||
| 79 | 1 | return view('projects.new', [ |
|
| 80 | 1 | 'form' => $form, |
|
| 81 | 1 | 'projects' => $this->auth->user()->projects()->get(), |
|
| 82 | ]); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * To create a new project. |
||
| 87 | * |
||
| 88 | * @param Project $project |
||
| 89 | * @param FormRequest\Project $request |
||
| 90 | * |
||
| 91 | * @return \Illuminate\Http\RedirectResponse |
||
| 92 | */ |
||
| 93 | 1 | public function postNew(Project $project, FormRequest\Project $request) |
|
| 94 | { |
||
| 95 | 1 | $project->createProject($request->all()); |
|
| 96 | |||
| 97 | 1 | return redirect($project->to()); |
|
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Ajax: Calculate the progress of user projects. |
||
| 102 | * |
||
| 103 | * @param Request $request |
||
| 104 | * @param Project $project |
||
| 105 | * |
||
| 106 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 107 | */ |
||
| 108 | 1 | public function postProgress(Request $request, Project $project) |
|
| 109 | { |
||
| 110 | // Get all projects with count of closed and opened issues |
||
| 111 | 1 | $projects = $project->projectsWithCountIssues((array) $request->input('ids')); |
|
| 112 | |||
| 113 | // The project progress Html and value |
||
| 114 | 1 | $progress = $projects->transform(function (Project $project) { |
|
| 115 | 1 | $progress = $project->getProgress(); |
|
| 116 | 1 | $view = view('partials/progress', ['text' => $progress . '%', 'progress' => $progress])->render(); |
|
|
1 ignored issue
–
show
|
|||
| 117 | |||
| 118 | return [ |
||
| 119 | 1 | 'id' => $project->id, |
|
| 120 | 'progress' => [ |
||
| 121 | 1 | 'html' => $view, |
|
| 122 | 1 | 'value' => $progress, |
|
| 123 | ], |
||
| 124 | ]; |
||
| 125 | 1 | })->lists('progress', 'id')->all(); |
|
| 126 | |||
| 127 | 1 | return response()->json(['status' => true, 'progress' => $progress]); |
|
| 128 | } |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Add new issue form. |
||
| 132 | * |
||
| 133 | * @param IssueForm $form |
||
| 134 | * |
||
| 135 | * @return \Illuminate\View\View |
||
| 136 | */ |
||
| 137 | 1 | public function getNewIssue(IssueForm $form) |
|
| 144 | |||
| 145 | /** |
||
| 146 | * To create a new issue. |
||
| 147 | * |
||
| 148 | * @param Project\Issue $issue |
||
| 149 | * @param FormRequest\GlobalIssue $request |
||
| 150 | * |
||
| 151 | * @return \Illuminate\Http\RedirectResponse |
||
| 152 | */ |
||
| 153 | 1 | public function postNewIssue(Project\Issue $issue, FormRequest\GlobalIssue $request) |
|
| 171 | } |
||
| 172 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: