Skip to content

Commit e6ec3ea

Browse files
committed
manual: Smaller cleanups to EventController
1 parent f103927 commit e6ec3ea

File tree

1 file changed

+25
-32
lines changed

1 file changed

+25
-32
lines changed

app/src/Event/EventController.php

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,22 @@
77
use Symfony\Component\Form\Form;
88
use Symfony\Component\Form\FormError;
99
use Symfony\Component\Form\FormFactoryInterface;
10-
use Symfony\Component\Validator\Validator;
10+
use Symfony\Component\Form\FormInterface;
1111
use Talk\TalkDb;
1212
use Talk\TalkApi;
1313
use Talk\TalkFormType;
1414
use Talk\TalkTypeApi;
15-
use User\UserDb;
1615
use User\UserApi;
1716
use Exception;
1817
use Slim\Slim;
1918
use Language\LanguageApi;
2019

2120
class EventController extends BaseController
2221
{
23-
private $itemsPerPage = 10;
22+
private int $itemsPerPage = 10;
2423

2524
private int $pendingItemsPerPage = 30;
2625

27-
public function __construct(Slim $slim)
28-
{
29-
parent::__construct($slim);
30-
}
31-
3226
protected function defineRoutes(Slim $slim): void
3327
{
3428
// named routes first; should an event pick the same name then at least our actions take precedence
@@ -201,7 +195,7 @@ public function eventDefault(string $friendly_name)
201195
}
202196

203197
$action = 'scheduleList';
204-
if (isset($_COOKIE['schedule-view']) && $_COOKIE['schedule-view'] == 'grid') {
198+
if (isset($_COOKIE['schedule-view']) && $_COOKIE['schedule-view'] === 'grid') {
205199
$action = 'scheduleGrid';
206200
}
207201

@@ -319,7 +313,7 @@ public function talkComments(string $friendly_name): void
319313
public function schedule(string $friendly_name): void
320314
{
321315
$scheduleView = 'list';
322-
if (isset($_COOKIE['schedule-view']) && $_COOKIE['schedule-view'] == 'grid') {
316+
if (isset($_COOKIE['schedule-view']) && $_COOKIE['schedule-view'] === 'grid') {
323317
$scheduleView = 'grid';
324318
}
325319

@@ -653,15 +647,15 @@ public function actionPendingEvent(string $friendly_name): void
653647
* Handles redirecting web1 event urls to web2
654648
* e.g. /event/view/3 -> /event/myevent
655649
*/
656-
public function redirectFromId(int $eventId, $extra = false)
650+
public function redirectFromId(int $eventId, $extra = false): void
657651
{
658652
$eventApi = $this->getEventApi();
659653
$event = $eventApi->getEventById($eventId);
660-
if (!$event instanceof \Event\EventEntity) {
654+
if (!$event instanceof EventEntity) {
661655
$this->application->notFound();
662656
}
663657

664-
if ($extra && is_array($extra) && ($extra[0] == "talk_comments")) {
658+
if ($extra && is_array($extra) && ($extra[0] === "talk_comments")) {
665659
$this->application->redirect(
666660
$this->application->urlFor(
667661
'event-talk-comments',
@@ -670,7 +664,7 @@ public function redirectFromId(int $eventId, $extra = false)
670664
);
671665
}
672666

673-
if ($extra && is_array($extra) && ($extra[0] == "comments")) {
667+
if ($extra && is_array($extra) && ($extra[0] === "comments")) {
674668
$this->application->redirect(
675669
$this->application->urlFor(
676670
'event-comments',
@@ -679,7 +673,7 @@ public function redirectFromId(int $eventId, $extra = false)
679673
);
680674
}
681675

682-
if ($extra && is_array($extra) && ($extra[0] == "talks")) {
676+
if ($extra && is_array($extra) && ($extra[0] === "talks")) {
683677
$this->application->redirect(
684678
$this->application->urlFor(
685679
'event-schedule',
@@ -705,7 +699,7 @@ public function redirectFromId(int $eventId, $extra = false)
705699
*
706700
* @return EventEntity|null|false
707701
*/
708-
private function addEventUsingForm(Form $form)
702+
private function addEventUsingForm(FormInterface $form)
709703
{
710704
$eventApi = $this->getEventApi();
711705
$values = $form->getData();
@@ -731,7 +725,7 @@ private function addEventUsingForm(Form $form)
731725
*
732726
* @return EventEntity|null|false
733727
*/
734-
private function editEventUsingForm(Form $form)
728+
private function editEventUsingForm(FormInterface $form)
735729
{
736730
$eventApi = $this->getEventApi();
737731
$values = $form->getData()->toArray();
@@ -924,7 +918,7 @@ public function moderateComment(string $friendly_name): void
924918
$decision = $this->application->request->post('decision');
925919

926920
$eventApi->moderateComment($reported_uri, $decision);
927-
if ($decision == 'approved') {
921+
if ($decision === 'approved') {
928922
$this->application->flash('message', 'Report accepted.');
929923
} else {
930924
$this->application->flash('message', 'Report rejected. Comment has been republished.');
@@ -966,18 +960,18 @@ public function talkClaims(string $friendly_name): void
966960
$action = $this->application->request->post('action');
967961

968962
if ($this->application->request->post('display_name')
969-
&& $this->application->request->post('display_name') == $claim->display_name
970-
&& $this->application->request->post('username') == $claim->user->getUsername()
971-
&& $this->application->request->post("talk") == $claim->talk->getStub()
963+
&& $this->application->request->post('display_name') === $claim->display_name
964+
&& $this->application->request->post('username') === $claim->user->getUsername()
965+
&& $this->application->request->post('talk') === $claim->talk->getStub()
972966
) {
973967
$data = [
974968
'display_name' => $this->application->request->post('display_name'),
975969
'username' => $this->application->request->post('username'),
976970
];
977971

978-
if ($action == "approve") {
972+
if ($action === 'approve') {
979973
$this->appoveClaimPendingTalk($talkApi, $claim, $data);
980-
} elseif ($action == "reject") {
974+
} elseif ($action === 'reject') {
981975
$this->rejectClaimPendingTalk($talkApi, $claim, $data);
982976
}
983977
}
@@ -995,8 +989,6 @@ public function talkClaims(string $friendly_name): void
995989

996990
public function removeHost(string $friendly_name, $host_name): void
997991
{
998-
$this->application->request();
999-
1000992
$eventApi = $this->getEventApi();
1001993
$event = $eventApi->getByFriendlyUrl($friendly_name);
1002994
if (! $event) {
@@ -1139,7 +1131,7 @@ public function addTalk(string $friendly_name)
11391131
}
11401132

11411133
if (!$event->getCanEdit()) {
1142-
$this->application->flash('error', "You do not have permission to do this.");
1134+
$this->application->flash('error', 'You do not have permission to do this.');
11431135
$this->redirectToDetailPage($event->getUrlFriendlyName());
11441136
}
11451137

@@ -1184,7 +1176,7 @@ public function addTalk(string $friendly_name)
11841176
$talkApi->addTalkToTrack($talk->getTracksUri(), $values['track']);
11851177
}
11861178

1187-
$this->application->flash('message', "Talk added");
1179+
$this->application->flash('message', 'Talk added');
11881180
$this->application->redirect(
11891181
$this->application->urlFor('event-schedule', ['friendly_name' => $event->getUrlFriendlyName()])
11901182
);
@@ -1217,7 +1209,7 @@ public function editTracks(string $friendly_name)
12171209
}
12181210

12191211
if (!$event->getCanEdit()) {
1220-
$this->application->flash('error', "You do not have permission to do this.");
1212+
$this->application->flash('error', 'You do not have permission to do this.');
12211213
$this->redirectToDetailPage($event->getUrlFriendlyName());
12221214
}
12231215

@@ -1262,7 +1254,7 @@ public function editTracks(string $friendly_name)
12621254
}
12631255
}
12641256

1265-
$this->application->flash('message', "Tracks updated");
1257+
$this->application->flash('message', 'Tracks updated');
12661258
$this->application->redirect(
12671259
$this->application->urlFor(
12681260
'event-edit-tracks',
@@ -1305,10 +1297,10 @@ public function eventImportCsv(string $eventSlug): void
13051297
if ($request->isPost()) {
13061298
try {
13071299
if (isset($_FILES['event_import']['error']['csv_file'])
1308-
&& $_FILES['event_import']['error']['csv_file'] == UPLOAD_ERR_OK) {
1300+
&& $_FILES['event_import']['error']['csv_file'] === UPLOAD_ERR_OK) {
13091301
$eventApi = $this->getEventApi();
13101302
$event = $eventApi->getByFriendlyUrl($eventSlug);
1311-
$handle = fopen($_FILES['event_import']['tmp_name']['csv_file'], "r");
1303+
$handle = fopen($_FILES['event_import']['tmp_name']['csv_file'], 'r');
13121304

13131305
while (!feof($handle)) {
13141306
$talk = fgetcsv($handle);
@@ -1379,7 +1371,8 @@ private function getTalkSlugsFromDb(array $comments): array
13791371

13801372
/** @var \Talk\TalkCommentEntity $comment */
13811373
foreach ($comments as $comment) {
1382-
$slugs[$comment->getTalkUri()] = $talkDb->getSlugFor($comment->getTalkUri());
1374+
$uri = $comment->getTalkUri();
1375+
$slugs[$uri] = $talkDb->getSlugFor($uri);
13831376
}
13841377

13851378
return $slugs;

0 commit comments

Comments
 (0)