Skip to content

Commit 45373be

Browse files
authored
Bump PHPStan templates check to level 4 (#143)
Ref #141
2 parents ce5bfe4 + ec3bf68 commit 45373be

File tree

74 files changed

+839
-353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+839
-353
lines changed

site/app/Admin/Presenters/BlogPresenter.php

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@
99
use MichalSpacekCz\Articles\Blog\Exceptions\BlogPostDoesNotExistException;
1010
use MichalSpacekCz\Form\PostFormFactory;
1111
use MichalSpacekCz\Formatter\TexyFormatter;
12-
use MichalSpacekCz\Tags\Tags;
1312
use Nette\Application\BadRequestException;
1413
use Nette\Application\UI\Form;
1514
use Nette\Utils\Html;
16-
use Nette\Utils\Json;
1715

1816
class BlogPresenter extends BasePresenter
1917
{
2018

21-
private BlogPost $post;
19+
private ?BlogPost $post = null;
2220

2321

2422
public function __construct(
2523
private readonly BlogPosts $blogPosts,
2624
private readonly TexyFormatter $texyFormatter,
27-
private readonly Tags $tags,
2825
private readonly PostFormFactory $postFormFactory,
2926
) {
3027
parent::__construct();
@@ -47,19 +44,27 @@ public function actionDefault(): void
4744
public function actionAdd(): void
4845
{
4946
$this->template->pageTitle = 'Přidat příspěvek';
47+
$this->setView('edit');
5048
}
5149

5250

53-
protected function createComponentAddPost(): Form
51+
protected function createComponentPost(): Form
5452
{
5553
return $this->postFormFactory->create(
5654
function (BlogPost $post): never {
5755
$this->blogPosts->add($post);
5856
$this->flashMessage($this->texyFormatter->translate('messages.blog.admin.postadded', [$post->titleTexy, $this->link('edit', [$post->postId]), $post->href]));
5957
$this->redirect('Blog:');
6058
},
59+
function (BlogPost $post): never {
60+
$post->previousSlugTags = $this->post->slugTags ?? [];
61+
$this->blogPosts->update($post);
62+
$this->flashMessage($this->texyFormatter->translate('messages.blog.admin.postupdated', [$post->titleTexy, $this->link('edit', [$post->postId]), $post->href]));
63+
$this->redirect('Blog:');
64+
},
6165
$this->template,
6266
$this->sendTemplate(...),
67+
$this->post,
6368
);
6469
}
6570

@@ -74,44 +79,4 @@ public function actionEdit(int $param): void
7479
$this->blogPosts->setTemplateTitleAndHeader($this->post, $this->template, Html::el()->setText('Příspěvek '));
7580
}
7681

77-
78-
protected function createComponentEditPost(): Form
79-
{
80-
$form = $this->postFormFactory->create(
81-
function (BlogPost $post): never {
82-
$post->previousSlugTags = $this->post->slugTags;
83-
$this->blogPosts->update($post);
84-
$this->flashMessage($this->texyFormatter->translate('messages.blog.admin.postupdated', [$post->titleTexy, $this->link('edit', [$post->postId]), $post->href]));
85-
$this->redirect('Blog:');
86-
},
87-
$this->template,
88-
$this->sendTemplate(...),
89-
$this->post->postId,
90-
);
91-
92-
$values = [
93-
'translationGroup' => $this->post->translationGroupId,
94-
'locale' => $this->post->localeId,
95-
'title' => $this->post->titleTexy,
96-
'slug' => $this->post->slug,
97-
'published' => $this->post->published?->format('Y-m-d H:i'),
98-
'previewKey' => $this->post->previewKey,
99-
'lead' => $this->post->leadTexy,
100-
'text' => $this->post->textTexy,
101-
'originally' => $this->post->originallyTexy,
102-
'ogImage' => $this->post->ogImage,
103-
'twitterCard' => $this->post->twitterCard?->getCard(),
104-
'tags' => ($this->post->tags ? $this->tags->toString($this->post->tags) : null),
105-
'recommended' => (empty($this->post->recommended) ? null : Json::encode($this->post->recommended)),
106-
'cspSnippets' => $this->post->cspSnippets,
107-
'allowedTags' => $this->post->allowedTags,
108-
'omitExports' => $this->post->omitExports,
109-
];
110-
$form->setDefaults($values);
111-
$form->getComponent('editSummary')
112-
->setDisabled($this->post->needsPreviewKey());
113-
$form->getComponent('submit')->caption = 'Upravit';
114-
return $form;
115-
}
116-
11782
}

site/app/Admin/Presenters/HomepagePresenter.php

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
namespace MichalSpacekCz\Admin\Presenters;
55

6-
use DateTime;
76
use MichalSpacekCz\Tls\Certificate;
87
use MichalSpacekCz\Tls\Certificates;
98
use MichalSpacekCz\Training\Applications;
9+
use MichalSpacekCz\Training\DateList\DateListOrder;
10+
use MichalSpacekCz\Training\DateList\TrainingApplicationsList;
11+
use MichalSpacekCz\Training\DateList\TrainingApplicationsListFactory;
1012
use MichalSpacekCz\Training\Dates\TrainingDates;
1113
use MichalSpacekCz\Training\Dates\UpcomingTrainingDates;
1214
use MichalSpacekCz\Training\Mails;
@@ -23,30 +25,14 @@ public function __construct(
2325
private readonly TrainingDates $trainingDates,
2426
private readonly UpcomingTrainingDates $upcomingTrainingDates,
2527
private readonly Certificates $certificates,
28+
private readonly TrainingApplicationsListFactory $trainingApplicationsListFactory,
2629
) {
2730
parent::__construct();
2831
}
2932

3033

3134
public function actionDefault(): void
3235
{
33-
$trainings = $this->trainingDates->getAllTrainingsInterval('-1 week');
34-
foreach ($this->upcomingTrainingDates->getAllUpcoming() as $training) {
35-
foreach ($training->getDates() as $date) {
36-
$trainings[] = $date;
37-
}
38-
}
39-
$dates = [];
40-
foreach ($trainings as $date) {
41-
$date->setApplications($this->trainingApplications->getValidByDate($date->getId()));
42-
$date->setCanceledApplications($this->trainingApplications->getCanceledPaidByDate($date->getId()));
43-
$dates[$date->getStart()->getTimestamp()] = $date;
44-
}
45-
ksort($dates);
46-
$this->template->upcomingApplications = $dates;
47-
$this->template->now = new DateTime();
48-
$this->template->upcomingIds = $this->upcomingTrainingDates->getPublicUpcomingIds();
49-
5036
$this->template->pageTitle = 'Administrace';
5137
$this->template->emailsToSend = count($this->trainingMails->getApplications());
5238
$this->template->unpaidInvoices = $this->trainingApplications->getValidUnpaidCount();
@@ -73,4 +59,23 @@ private function certsNeedAttention(array $certificates): bool
7359
return false;
7460
}
7561

62+
63+
protected function createComponentTrainingApplicationsList(): TrainingApplicationsList
64+
{
65+
$trainings = $this->trainingDates->getAllTrainingsInterval('-1 week');
66+
foreach ($this->upcomingTrainingDates->getAllUpcoming() as $training) {
67+
foreach ($training->getDates() as $date) {
68+
$trainings[] = $date;
69+
}
70+
}
71+
$dates = [];
72+
foreach ($trainings as $date) {
73+
$date->setApplications($this->trainingApplications->getValidByDate($date->getId()));
74+
$date->setCanceledApplications($this->trainingApplications->getCanceledPaidByDate($date->getId()));
75+
$dates[$date->getStart()->getTimestamp()] = $date;
76+
}
77+
ksort($dates);
78+
return $this->trainingApplicationsListFactory->create(array_values($dates), DateListOrder::Asc);
79+
}
80+
7681
}

site/app/Admin/Presenters/InterviewsPresenter.php

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33

44
namespace MichalSpacekCz\Admin\Presenters;
55

6-
use MichalSpacekCz\Form\InterviewFormFactory;
76
use MichalSpacekCz\Formatter\TexyFormatter;
87
use MichalSpacekCz\Interviews\Exceptions\InterviewDoesNotExistException;
98
use MichalSpacekCz\Interviews\Interview;
9+
use MichalSpacekCz\Interviews\InterviewInputs;
10+
use MichalSpacekCz\Interviews\InterviewInputsFactory;
1011
use MichalSpacekCz\Interviews\Interviews;
11-
use MichalSpacekCz\Media\VideoThumbnails;
1212
use Nette\Application\BadRequestException;
13-
use Nette\Forms\Form;
1413

1514
class InterviewsPresenter extends BasePresenter
1615
{
@@ -21,8 +20,7 @@ class InterviewsPresenter extends BasePresenter
2120
public function __construct(
2221
private readonly TexyFormatter $texyFormatter,
2322
private readonly Interviews $interviews,
24-
private readonly InterviewFormFactory $interviewFormFactory,
25-
private readonly VideoThumbnails $videoThumbnails,
23+
private readonly InterviewInputsFactory $interviewInputsFactory,
2624
) {
2725
parent::__construct();
2826
}
@@ -32,8 +30,6 @@ public function renderDefault(): void
3230
{
3331
$this->template->pageTitle = $this->translator->translate('messages.title.interviews');
3432
$this->template->interviews = $this->interviews->getAll();
35-
$this->template->videoThumbnailWidth = $this->videoThumbnails->getWidth();
36-
$this->template->videoThumbnailHeight = $this->videoThumbnails->getHeight();
3733
}
3834

3935

@@ -46,32 +42,18 @@ public function actionInterview(int $param): void
4642
}
4743

4844
$this->template->pageTitle = $this->texyFormatter->translate('messages.title.interview', [strip_tags($this->interview->getTitle())]);
49-
$this->template->interview = $this->interview;
50-
$this->template->videoThumbnailWidth = $this->videoThumbnails->getWidth();
51-
$this->template->videoThumbnailHeight = $this->videoThumbnails->getHeight();
5245
}
5346

5447

55-
protected function createComponentEditInterview(): Form
48+
protected function createComponentEditInterviewInputs(): InterviewInputs
5649
{
57-
return $this->interviewFormFactory->create(
58-
function (): never {
59-
$this->flashMessage('Rozhovor upraven');
60-
$this->redirect('Interviews:');
61-
},
62-
$this->interview,
63-
);
50+
return $this->interviewInputsFactory->createFor($this->interview);
6451
}
6552

6653

67-
protected function createComponentAddInterview(): Form
54+
protected function createComponentAddInterviewInputs(): InterviewInputs
6855
{
69-
return $this->interviewFormFactory->create(
70-
function (): never {
71-
$this->flashMessage('Rozhovor přidán');
72-
$this->redirect('Interviews:');
73-
},
74-
);
56+
return $this->interviewInputsFactory->create();
7557
}
7658

7759
}

site/app/Admin/Presenters/InvoicesPresenter.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
namespace MichalSpacekCz\Admin\Presenters;
55

6-
use DateTime;
76
use MichalSpacekCz\Form\TrainingInvoiceFormFactory;
87
use MichalSpacekCz\Training\Applications;
8+
use MichalSpacekCz\Training\DateList\DateListOrder;
9+
use MichalSpacekCz\Training\DateList\TrainingApplicationsList;
10+
use MichalSpacekCz\Training\DateList\TrainingApplicationsListFactory;
11+
use MichalSpacekCz\Training\Dates\TrainingDate;
912
use MichalSpacekCz\Training\Dates\TrainingDates;
10-
use MichalSpacekCz\Training\Dates\UpcomingTrainingDates;
1113
use Nette\Forms\Form;
1214

1315
class InvoicesPresenter extends BasePresenter
@@ -16,12 +18,15 @@ class InvoicesPresenter extends BasePresenter
1618
/** @var array<int, string> */
1719
private array $allUnpaidInvoiceIds = [];
1820

21+
/** @var list<TrainingDate> */
22+
private array $datesWithUnpaid = [];
23+
1924

2025
public function __construct(
2126
private readonly Applications $trainingApplications,
2227
private readonly TrainingDates $trainingDates,
23-
private readonly UpcomingTrainingDates $upcomingTrainingDates,
2428
private readonly TrainingInvoiceFormFactory $trainingInvoiceFormFactory,
29+
private readonly TrainingApplicationsListFactory $trainingApplicationsListFactory,
2530
) {
2631
parent::__construct();
2732
}
@@ -39,9 +44,9 @@ public function actionUnpaid(): void
3944
$dates[$date->getStart()->getTimestamp()] = $date;
4045
}
4146
ksort($dates);
42-
$this->template->unpaidApplications = $dates;
43-
$this->template->now = new DateTime();
44-
$this->template->upcomingIds = $this->upcomingTrainingDates->getPublicUpcomingIds();
47+
$this->template->unpaidApplications = (bool)$dates;
48+
$this->datesWithUnpaid = array_values($dates);
49+
4550
$this->template->pageTitle = 'Nezaplacené faktury';
4651
}
4752

@@ -65,4 +70,10 @@ function (): never {
6570
);
6671
}
6772

73+
74+
protected function createComponentTrainingApplicationsList(): TrainingApplicationsList
75+
{
76+
return $this->trainingApplicationsListFactory->create($this->datesWithUnpaid, DateListOrder::Asc);
77+
}
78+
6879
}

site/app/Admin/Presenters/PresenterTemplates/Interviews/InterviewsInterview.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33

44
namespace MichalSpacekCz\Admin\Presenters\PresenterTemplates\Interviews;
55

6+
use MichalSpacekCz\Interviews\Interview;
67
use Nette\Bridges\ApplicationLatte\Template;
7-
use Nette\Database\Row;
88

99
class InterviewsInterview extends Template
1010
{
1111

1212
public string $pageTitle;
1313

14-
/** @var Row<mixed> */
15-
public Row $interview;
16-
17-
public int $videoThumbnailWidth;
18-
19-
public int $videoThumbnailHeight;
14+
public Interview $interview;
2015

2116
}

site/app/Admin/Presenters/ReviewsPresenter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
namespace MichalSpacekCz\Admin\Presenters;
55

6-
use MichalSpacekCz\Training\Reviews;
6+
use MichalSpacekCz\Training\Reviews\TrainingReviews;
77
use MichalSpacekCz\Training\Trainings;
88

99
class ReviewsPresenter extends BasePresenter
1010
{
1111

1212
public function __construct(
1313
private readonly Trainings $trainings,
14-
private readonly Reviews $trainingReviews,
14+
private readonly TrainingReviews $trainingReviews,
1515
) {
1616
parent::__construct();
1717
}

0 commit comments

Comments
 (0)