Skip to content

Commit 0ca7dd1

Browse files
committed
chore: backport of Psalm fix
1 parent 06c0c7d commit 0ca7dd1

File tree

10 files changed

+18
-5
lines changed

10 files changed

+18
-5
lines changed

bin/coverage-checker.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
$checkedElements += (int) $metric['coveredelements'];
4040
}
4141

42-
$coverage = round(($checkedElements / $totalElements) * 100, 2);
42+
$coverage = round(((float) $checkedElements / (float) $totalElements) * 100.0, 2);
4343
if ($coverage < $percentage) {
44-
echo ' > Code coverage: '.$coverage.'%, which is below the accepted '.$percentage.'%'.\PHP_EOL.\PHP_EOL;
44+
echo sprintf(' > Code coverage: %s%%, which is below the accepted threshold: %s%%', $coverage, $percentage).\PHP_EOL.\PHP_EOL;
4545
exit(1);
4646
}
4747

48-
echo \PHP_EOL.' > Code coverage: '.$coverage.'% - OK! ✅'.\PHP_EOL.\PHP_EOL;
48+
echo \PHP_EOL.sprintf(' > Code coverage: %s%% - OK! ✅', $coverage).\PHP_EOL.\PHP_EOL;

src/Controller/FormAction.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function __invoke(Request $request): Response
2525
$dto = new RegisterFormDto();
2626
$form = $this->createForm(RegisterForm::class, $dto)->handleRequest($request);
2727
if ($form->isSubmitted() && $form->isValid()) {
28+
/** @var RegisterFormDto $dto */
2829
// just for the example, the DTO has already been updated at this point
2930
$dto = $form->getData();
3031
}

src/Entity/User.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#[ORM\Entity(repositoryClass: UserRepository::class)]
1919
#[ORM\Table(name: '`user`')]
2020
#[ORM\HasLifecycleCallbacks]
21-
class User implements \Stringable, UserInterface, PasswordAuthenticatedUserInterface
21+
final class User implements \Stringable, UserInterface, PasswordAuthenticatedUserInterface
2222
{
2323
final public const string ROLE_USER = 'ROLE_USER';
2424

@@ -61,6 +61,7 @@ public function getId(): int
6161
return $this->id;
6262
}
6363

64+
#[\Override]
6465
public function __toString(): string
6566
{
6667
return $this->getUserIdentifier().' ('.$this->getId().')';
@@ -82,6 +83,7 @@ public function __unserialize(array $data): void
8283
[$this->id, $this->username, $this->password, $this->email] = $data;
8384
}
8485

86+
#[\Override]
8587
public function getUserIdentifier(): string
8688
{
8789
if ($this->username === '') {
@@ -94,6 +96,7 @@ public function getUserIdentifier(): string
9496
/**
9597
* Returns the roles or permissions granted to the user for security.
9698
*/
99+
#[\Override]
97100
public function getRoles(): array
98101
{
99102
return [self::ROLE_USER];
@@ -114,6 +117,7 @@ public function setEmail(string $email): self
114117
return $this;
115118
}
116119

120+
#[\Override]
117121
public function getPassword(): string
118122
{
119123
return $this->password;

src/Factory/UserFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
final class UserFactory extends PersistentObjectFactory
1616
{
17+
#[\Override]
1718
public static function class(): string
1819
{
1920
return User::class;
@@ -22,6 +23,7 @@ public static function class(): string
2223
/**
2324
* @return array<string, mixed>
2425
*/
26+
#[\Override]
2527
protected function defaults(): array
2628
{
2729
return [

src/Form/Type/RegisterForm.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
final class RegisterForm extends AbstractType
2525
{
26+
#[\Override]
2627
public function buildForm(FormBuilderInterface $builder, array $options): void
2728
{
2829
$builder
@@ -46,6 +47,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
4647
/**
4748
* @see https://www.strangebuzz.com/en/blog/disable-the-html5-validation-of-all-your-symfony-forms-with-a-feature-flag
4849
*/
50+
#[\Override]
4951
public function configureOptions(OptionsResolver $resolver): void
5052
{
5153
$resolver->setDefaults([

src/Repository/UserRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* @see https://github.com/symfony/demo/blob/main/src/Repository/UserRepository.php
2424
*/
25-
class UserRepository extends ServiceEntityRepository
25+
final class UserRepository extends ServiceEntityRepository
2626
{
2727
public function __construct(ManagerRegistry $registry)
2828
{

src/Story/AppStory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#[AsFixture(name: 'main')]
1515
final class AppStory extends Story
1616
{
17+
#[\Override]
1718
public function build(): void
1819
{
1920
UserFactory::createMany(10);

src/Twig/Extension/EnvExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ final class EnvExtension extends AbstractExtension implements GlobalsInterface
1616
/**
1717
* @return array<string,string>
1818
*/
19+
#[\Override]
1920
public function getGlobals(): array
2021
{
2122
return [

tests/Integration/Entity/UserTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ final class UserTest extends KernelTestCase
1515

1616
public function testPersistNewUserSuccess(): void
1717
{
18+
/** @var EntityManagerInterface $em */
1819
$em = self::getContainer()->get(EntityManagerInterface::class);
1920
$user = new User(
2021
email: 'test@example.com',

tests/Integration/Twig/Extension/RoutingExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ final class RoutingExtensionTest extends KernelTestCase
1616
public function testRoutingExtensionInvalidArgumentException(): void
1717
{
1818
self::bootKernel();
19+
/** @var RoutingExtension $extension */
1920
$extension = self::getContainer()->get(RoutingExtension::class);
2021
$this->expectException(\InvalidArgumentException::class);
2122
$extension->getControllerFqcn('foo');

0 commit comments

Comments
 (0)