xoco70 /
kendozone
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace App\Http\Controllers; |
||||||
| 4 | |||||||
| 5 | use App\Http\Requests\InviteRequest; |
||||||
| 6 | use App\Invite; |
||||||
| 7 | use App\Notifications\InviteCompetitor; |
||||||
| 8 | use App\Tournament; |
||||||
| 9 | use App\User; |
||||||
| 10 | use Illuminate\Http\Request; |
||||||
| 11 | use Illuminate\Support\Facades\Auth; |
||||||
| 12 | use Illuminate\Support\Facades\URL; |
||||||
| 13 | use Illuminate\Support\Facades\View; |
||||||
| 14 | use Maatwebsite\Excel\Facades\Excel; |
||||||
| 15 | |||||||
| 16 | class InviteController extends Controller |
||||||
| 17 | { |
||||||
| 18 | protected $emailBadFormat; |
||||||
| 19 | protected $wrongEmail; |
||||||
| 20 | |||||||
| 21 | |||||||
| 22 | /** |
||||||
| 23 | * Display a listing of all invitations. |
||||||
| 24 | * |
||||||
| 25 | * @return View |
||||||
| 26 | */ |
||||||
| 27 | public function index() |
||||||
| 28 | { |
||||||
| 29 | $invites = Auth::user() |
||||||
| 30 | ->invites() |
||||||
| 31 | ->with('tournament.owner') |
||||||
| 32 | ->paginate(config('constants.PAGINATION')); |
||||||
| 33 | return view('invitation.index', compact('invites')); |
||||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||||
| 34 | } |
||||||
| 35 | |||||||
| 36 | /** |
||||||
| 37 | * Display the UI for inviting competitors |
||||||
| 38 | * |
||||||
| 39 | * @param Tournament $tournament |
||||||
| 40 | * @return View |
||||||
| 41 | */ |
||||||
| 42 | 1 | public function create(Tournament $tournament) |
|||||
| 43 | { |
||||||
| 44 | // Should dd $tournament |
||||||
| 45 | 1 | return view('invitation.show', compact('tournament')); |
|||||
|
0 ignored issues
–
show
|
|||||||
| 46 | } |
||||||
| 47 | |||||||
| 48 | |||||||
| 49 | /** |
||||||
| 50 | * Send an email to competitor and store invitation. |
||||||
| 51 | * |
||||||
| 52 | * @param InviteRequest|Request $request |
||||||
| 53 | * @return \Illuminate\Http\Response |
||||||
| 54 | */ |
||||||
| 55 | 1 | public function store(Request $request) |
|||||
| 56 | { |
||||||
| 57 | //TODO check that recipient is list of emails |
||||||
| 58 | 1 | $this->validate($request, [ |
|||||
| 59 | 1 | 'recipients' => 'required' |
|||||
| 60 | ]); |
||||||
| 61 | |||||||
| 62 | 1 | $tournament = Tournament::where('slug', $request->tournamentSlug)->first(); |
|||||
| 63 | 1 | $recipients = json_decode($request->get("recipients")); |
|||||
| 64 | 1 | foreach ($recipients as $recipient) { |
|||||
| 65 | // Mail to Recipients |
||||||
| 66 | 1 | $code = resolve(Invite::class)->generateTournamentInvite($recipient, $tournament); |
|||||
| 67 | 1 | $user = new User(); |
|||||
| 68 | 1 | $user->email = $recipient; |
|||||
| 69 | 1 | $user->notify(new InviteCompetitor($user, $tournament, $code, null)); |
|||||
| 70 | } |
||||||
| 71 | 1 | flash()->success(trans('msg.invitation_sent')); |
|||||
|
0 ignored issues
–
show
Are you sure the usage of
flash() is correct as it seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||||||
| 72 | 1 | return redirect(URL::action('TournamentController@edit', $tournament->slug)); |
|||||
|
0 ignored issues
–
show
|
|||||||
| 73 | } |
||||||
| 74 | |||||||
| 75 | |||||||
| 76 | /** |
||||||
| 77 | * Send an email to competitor and store invitation. |
||||||
| 78 | * |
||||||
| 79 | * @param InviteRequest|Request $request |
||||||
| 80 | * @return \Illuminate\Http\Response |
||||||
| 81 | */ |
||||||
| 82 | public function upload(Request $request) |
||||||
| 83 | { |
||||||
| 84 | $this->emailBadFormat = false; |
||||||
| 85 | $file = $request->file('invites')->store('invites'); |
||||||
| 86 | $tournament = Tournament::where('slug', $request->tournamentSlug)->first(); |
||||||
| 87 | // Parse Csv File |
||||||
| 88 | |||||||
| 89 | $reader = Excel::load("storage/app/" . $file, function ($reader) { |
||||||
|
0 ignored issues
–
show
Are you sure
$file of type false|string can be used in concatenation?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
The parameter
$reader is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 90 | })->get(); |
||||||
| 91 | |||||||
| 92 | // Checking if malformed email |
||||||
| 93 | resolve(Invite::class)->checkBadEmailsInExcel($reader, $tournament); |
||||||
| 94 | if ($this->emailBadFormat == true) { |
||||||
|
0 ignored issues
–
show
|
|||||||
| 95 | flash()->error(trans('msg.email_not_valid', ['email' => $this->wrongEmail])); |
||||||
| 96 | return redirect(URL::action('InviteController@create', $tournament->slug)); |
||||||
| 97 | } |
||||||
| 98 | Invite::sendInvites($reader, $tournament); |
||||||
| 99 | flash()->success(trans('msg.invitation_sent')); |
||||||
|
0 ignored issues
–
show
Are you sure the usage of
flash() is correct as it seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||||||
| 100 | return redirect(URL::action('InviteController@create', $tournament->slug)); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 101 | } |
||||||
| 102 | } |
||||||
| 103 |