Skip to content

Commit 190dd93

Browse files
Resolve PHPStan issues
1 parent 4de4eb8 commit 190dd93

13 files changed

+35
-28
lines changed

src/BoltFormsConfig.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class BoltFormsConfig
1515
{
1616
private ?Collection $config = null;
17-
private ?ExtensionInterface $extension = null;
17+
private ?Extension $extension = null;
1818

1919
public function __construct(
2020
private readonly ExtensionRegistry $registry,
@@ -44,7 +44,9 @@ public function getBoltConfig(): Config
4444
public function getExtension(): Extension
4545
{
4646
if ($this->extension === null) {
47-
$this->extension = $this->registry->getExtension(Extension::class);
47+
/** @var Extension $retrievedExtension */
48+
$retrievedExtension = $this->registry->getExtension(Extension::class);
49+
$this->extension = $retrievedExtension;
4850
}
4951

5052
return $this->extension;

src/EventSubscriber/AbstractPersistSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function handleSave(PostSubmitEvent $event): void
2323
$config = collect($event->getFormConfig()->get('database', false));
2424

2525
// If content type is not configured, bail out.
26-
if (! $config) {
26+
if ($config->isEmpty()) {
2727
return;
2828
}
2929

src/EventSubscriber/ContentTypePersister.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Carbon\Carbon;
1313
use DateTimeInterface;
1414
use Doctrine\ORM\EntityManagerInterface;
15+
use http\Exception\RuntimeException;
1516
use Illuminate\Support\Collection;
1617
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1718
use Symfony\Component\Form\FormInterface;
@@ -30,7 +31,7 @@ public function save(PostSubmitEvent $event, FormInterface $form, Collection $co
3031
{
3132
$config = collect($config->get('contenttype', []));
3233

33-
if (! $config) {
34+
if ($config->isEmpty()) {
3435
return;
3536
}
3637

@@ -48,7 +49,7 @@ public function save(PostSubmitEvent $event, FormInterface $form, Collection $co
4849
private function setContentData(Content $content, Collection $config): void
4950
{
5051
$content->setStatus($config->get('status', Statuses::PUBLISHED));
51-
$contentType = $this->boltConfig->getContentType($config->get('name'));
52+
$contentType = $this->boltConfig->getContentType($config->get('name')) ?? throw new RuntimeException('Content type not found');
5253
$content->setContentType($contentType->get('slug'));
5354
$content->setDefinition($contentType);
5455

@@ -58,7 +59,7 @@ private function setContentData(Content $content, Collection $config): void
5859
}
5960
}
6061

61-
private function setContentFields(Content $content, Form $form, PostSubmitEvent $event, Collection $config): void
62+
private function setContentFields(Content $content, FormInterface $form, PostSubmitEvent $event, Collection $config): void
6263
{
6364
$mapping = collect($config->get('field_map'));
6465

src/EventSubscriber/DbTablePersister.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function save(PostSubmitEvent $event, FormInterface $form, Collection $co
3030
{
3131
$config = collect($config->get('table', []));
3232

33-
if (! $config) {
33+
if ($config->isEmpty()) {
3434
return;
3535
}
3636

@@ -87,7 +87,7 @@ private function saveToTable(string $table, array $fields): void
8787
->setParameters($parameters);
8888

8989
try {
90-
$this->query->execute();
90+
$this->query->executeQuery();
9191
} catch (Throwable $exception) {
9292
$this->log->error($exception->getMessage());
9393
}

src/EventSubscriber/Logger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Logger implements EventSubscriberInterface
1414
{
1515
use LoggerTrait;
1616

17-
private ?PostSubmitEvent $event = null;
17+
private PostSubmitEvent $event;
1818

1919
public function handleEvent(PostSubmitEvent $event): void
2020
{

src/EventSubscriber/Mailer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Mailer implements EventSubscriberInterface
1717
{
1818
use LoggerTrait;
1919

20-
private ?PostSubmitEvent $event = null;
20+
private PostSubmitEvent $event;
2121

2222
public function __construct(
2323
private readonly MailerInterface $mailer
@@ -62,7 +62,7 @@ public function buildEmail(): TemplatedEmail
6262
$email = (new EmailFactory())->create($this->event->getFormConfig(), $this->event->getConfig(), $this->event->getForm(), $meta);
6363

6464
if ($this->event->isSpam()) {
65-
$subject = Str::ensureStartsWith($email->getSubject(), '[SPAM] ');
65+
$subject = Str::ensureStartsWith($email->getSubject() ?? '', '[SPAM] ');
6666
$email->subject($subject);
6767
}
6868

src/EventSubscriber/Redirect.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
use Illuminate\Support\Collection;
1111
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1212
use Symfony\Component\HttpFoundation\RedirectResponse;
13+
use Symfony\Component\HttpFoundation\Response;
1314
use Symfony\Component\HttpKernel\Exception\HttpException;
1415

1516
class Redirect implements EventSubscriberInterface
1617
{
1718
use LoggerTrait;
1819

19-
private ?PostSubmitEvent $event = null;
20-
private ?Collection $formConfig = null;
21-
private ?Collection $feedback = null;
20+
private PostSubmitEvent $event;
21+
private Collection $formConfig;
22+
private Collection $feedback;
2223

2324
public function handleEvent(PostSubmitEvent $event): void
2425
{
@@ -52,7 +53,7 @@ public function redirect(): void
5253
throw new HttpException(Response::HTTP_FOUND, '', null, []);
5354
}
5455

55-
protected function getRedirectResponse(array $redirect): ?RedirectResponse
56+
protected function getRedirectResponse(array $redirect): RedirectResponse
5657
{
5758
$url = $this->makeUrl($redirect);
5859

src/Extension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function dump(mixed ...$moreVars): void
3030

3131
public function install(): void
3232
{
33+
/** @var string $projectDir */
3334
$projectDir = $this->getContainer()->getParameter('kernel.project_dir');
3435

3536
$filesystem = new Filesystem();

src/Factory/EmailFactory.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@
66

77
use Bolt\Common\Str;
88
use Illuminate\Support\Collection;
9-
use Sirius\Upload\Result\File;
109
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
1110
use Symfony\Component\Form\FormInterface;
1211
use Symfony\Component\Mime\Address;
1312

1413
class EmailFactory
1514
{
16-
private ?FormInterface $form = null;
17-
private ?Collection $config = null;
18-
private ?Collection $notification = null;
19-
private ?Collection $formConfig = null;
15+
private FormInterface $form;
16+
private Collection $config;
17+
private Collection $notification;
18+
private Collection $formConfig;
2019

21-
/**
20+
/**
2221
* @param Collection $formConfig The config specific for the current form
2322
* @param Collection $config The global config defined config/extensions/bolt-boltforms.yaml
2423
* @param FormInterface $form The form object
@@ -61,7 +60,6 @@ public function create(Collection $formConfig, Collection $config, FormInterface
6160
}
6261

6362
foreach ($attachments as $name => $attachment) {
64-
/** @var File $attachment */
6563
foreach ($attachment as $file) {
6664
$email->attachFromPath($file, $name . '.' . pathinfo((string) $file, PATHINFO_EXTENSION));
6765
}

src/Factory/FieldConstraints.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public static function get(string $formName, array $field): array
2323
$inputType = \gettype($item);
2424

2525
if ($inputType === 'string') {
26-
$class = static::getClassFromString($formName, $item);
26+
$class = self::getClassFromString($formName, $item);
2727
} elseif ($inputType === 'array') {
28-
$class = static::getClassFromArray($formName, $item);
28+
$class = self::getClassFromArray($formName, $item);
2929
} else {
3030
throw new RuntimeException(sprintf("Constraint for Field '%s' must be string or array. '%s' given.", $formName, $inputType));
3131
}
@@ -55,6 +55,6 @@ private static function getClassFromString(string $formName, string $input, arra
5555

5656
private static function getClassFromArray(string $formName, array $input): object
5757
{
58-
return self::getClassFromString($formName, key($input), current($input));
58+
return self::getClassFromString($formName, (string)key($input), current($input));
5959
}
6060
}

0 commit comments

Comments
 (0)