Skip to content

Commit 7beba99

Browse files
Add missing types in code templates
1 parent 169d46f commit 7beba99

File tree

11 files changed

+88
-101
lines changed

11 files changed

+88
-101
lines changed

src/Maker/MakeVoter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\Console\Command\Command;
1919
use Symfony\Component\Console\Input\InputArgument;
2020
use Symfony\Component\Console\Input\InputInterface;
21-
use Symfony\Component\HttpKernel\Kernel;
2221
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
2322

2423
/**
@@ -56,9 +55,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
5655
$generator->generateClass(
5756
$voterClassNameDetails->getFullName(),
5857
'security/Voter.tpl.php',
59-
[
60-
'use_type_hints' => 50000 <= Kernel::VERSION_ID,
61-
]
58+
[]
6259
);
6360

6461
$generator->writeChanges();

src/Resources/skeleton/doctrine/Repository.tpl.php

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -70,33 +70,29 @@ public function upgradePassword(<?= sprintf('%s ', $password_upgrade_user_interf
7070

7171
<?php endif ?>
7272
<?php if ($include_example_comments): ?>
73-
// /**
74-
// * @return <?= $entity_class_name ?>[] Returns an array of <?= $entity_class_name ?> objects
75-
// */
76-
/*
77-
public function findByExampleField($value)
78-
{
79-
return $this->createQueryBuilder('<?= $entity_alias; ?>')
80-
->andWhere('<?= $entity_alias; ?>.exampleField = :val')
81-
->setParameter('val', $value)
82-
->orderBy('<?= $entity_alias; ?>.id', 'ASC')
83-
->setMaxResults(10)
84-
->getQuery()
85-
->getResult()
86-
;
87-
}
88-
*/
73+
// /**
74+
// * @return <?= $entity_class_name ?>[] Returns an array of <?= $entity_class_name ?> objects
75+
// */
76+
// public function findByExampleField($value): array
77+
// {
78+
// return $this->createQueryBuilder('<?= $entity_alias; ?>')
79+
// ->andWhere('<?= $entity_alias; ?>.exampleField = :val')
80+
// ->setParameter('val', $value)
81+
// ->orderBy('<?= $entity_alias; ?>.id', 'ASC')
82+
// ->setMaxResults(10)
83+
// ->getQuery()
84+
// ->getResult()
85+
// ;
86+
// }
8987

90-
/*
91-
public function findOneBySomeField($value): ?<?= $entity_class_name."\n" ?>
92-
{
93-
return $this->createQueryBuilder('<?= $entity_alias ?>')
94-
->andWhere('<?= $entity_alias ?>.exampleField = :val')
95-
->setParameter('val', $value)
96-
->getQuery()
97-
->getOneOrNullResult()
98-
;
99-
}
100-
*/
88+
// public function findOneBySomeField($value): ?<?= $entity_class_name."\n" ?>
89+
// {
90+
// return $this->createQueryBuilder('<?= $entity_alias ?>')
91+
// ->andWhere('<?= $entity_alias ?>.exampleField = :val')
92+
// ->setParameter('val', $value)
93+
// ->getQuery()
94+
// ->getOneOrNullResult()
95+
// ;
96+
// }
10197
<?php endif; ?>
10298
}

src/Resources/skeleton/event/Subscriber.tpl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
class <?= $class_name ?> implements EventSubscriberInterface
99
{
10-
public function <?= $method_name ?>(<?= $event_arg ?>)
10+
public function <?= $method_name ?>(<?= $event_arg ?>): void
1111
{
1212
// ...
1313
}
1414

15-
public static function getSubscribedEvents()
15+
public static function getSubscribedEvents(): array
1616
{
1717
return [
1818
<?= $event ?> => '<?= $method_name ?>',

src/Resources/skeleton/message/Message.tpl.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
final class <?= $class_name."\n" ?>
66
{
77
/*
8-
* Add whatever properties & methods you need to hold the
9-
* data for this message class.
8+
* Add whatever properties and methods you need
9+
* to hold the data for this message class.
1010
*/
1111

1212
// private $name;
13-
//
13+
1414
// public function __construct(string $name)
1515
// {
1616
// $this->name = $name;
1717
// }
18-
//
18+
1919
// public function getName(): string
2020
// {
2121
// return $this->name;

src/Resources/skeleton/security/UserProvider.tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function refreshUser(UserInterface $user): UserInterface
6464
/**
6565
* Tells Symfony to use this provider for this User class.
6666
*/
67-
public function supportsClass($class): bool
67+
public function supportsClass(string $class): bool
6868
{
6969
return <?= $user_short_name ?>::class === $class || is_subclass_of($class, <?= $user_short_name ?>::class);
7070
}

src/Resources/skeleton/security/Voter.tpl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ class <?= $class_name ?> extends Voter
1111
public const EDIT = 'POST_EDIT';
1212
public const VIEW = 'POST_VIEW';
1313

14-
protected function supports(<?= $use_type_hints ? 'string ' : null ?>$attribute, $subject): bool
14+
protected function supports(string $attribute, $subject): bool
1515
{
1616
// replace with your own logic
1717
// https://symfony.com/doc/current/security/voters.html
1818
return in_array($attribute, [self::EDIT, self::VIEW])
1919
&& $subject instanceof \App\Entity\<?= str_replace('Voter', null, $class_name) ?>;
2020
}
2121

22-
protected function voteOnAttribute(<?= $use_type_hints ? 'string ' : null ?>$attribute, $subject, TokenInterface $token): bool
22+
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
2323
{
2424
$user = $token->getUser();
2525
// if the user is anonymous, do not grant access

src/Resources/skeleton/serializer/Encoder.tpl.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ class <?= $class_name ?> implements EncoderInterface, DecoderInterface
99
{
1010
public const FORMAT = '<?= $format ?>';
1111

12-
public function encode($data, $format, array $context = [])
12+
public function encode($data, string $format, array $context = []): string
1313
{
1414
// TODO: return your encoded data
1515
return '';
1616
}
1717

18-
public function supportsEncoding($format): bool
18+
public function supportsEncoding(string $format, array $context = []): bool
1919
{
2020
return self::FORMAT === $format;
2121
}
2222

23-
public function decode($data, $format, array $context = [])
23+
public function decode(string $data, string $format, array $context = [])
2424
{
2525
// TODO: return your decoded data
2626
return '';
2727
}
2828

29-
public function supportsDecoding($format): bool
29+
public function supportsDecoding(string $format, array $context = []): bool
3030
{
3131
return self::FORMAT === $format;
3232
}

src/Resources/skeleton/serializer/Normalizer.tpl.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ public function __construct(ObjectNormalizer $normalizer)
1515
$this->normalizer = $normalizer;
1616
}
1717

18-
public function normalize($object, $format = null, array $context = []): array
18+
public function normalize($object, string $format = null, array $context = []): array
1919
{
2020
$data = $this->normalizer->normalize($object, $format, $context);
2121

22-
// Here: add, edit, or delete some data
22+
// TODO: add, edit, or delete some data
2323

2424
return $data;
2525
}
2626

27-
public function supportsNormalization($data, $format = null): bool
27+
public function supportsNormalization($data, string $format = null, array $context = []): bool
2828
{
2929
return $data instanceof \App\Entity\<?= str_replace('Normalizer', null, $class_name) ?>;
3030
}

src/Resources/skeleton/validator/Constraint.tpl.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
/**
88
* @Annotation
9+
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
910
*/
11+
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
1012
class <?= $class_name ?> extends Constraint
1113
{
1214
/*

tests/Doctrine/fixtures/expected_xml/src/Repository/UserRepository.php

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,28 @@ public function remove(UserXml $entity, bool $flush = false): void
4747
}
4848
}
4949

50-
// /**
51-
// * @return UserXml[] Returns an array of UserXml objects
52-
// */
53-
/*
54-
public function findByExampleField($value)
55-
{
56-
return $this->createQueryBuilder('u')
57-
->andWhere('u.exampleField = :val')
58-
->setParameter('val', $value)
59-
->orderBy('u.id', 'ASC')
60-
->setMaxResults(10)
61-
->getQuery()
62-
->getResult()
63-
;
64-
}
65-
*/
50+
// /**
51+
// * @return UserXml[] Returns an array of UserXml objects
52+
// */
53+
// public function findByExampleField($value): array
54+
// {
55+
// return $this->createQueryBuilder('u')
56+
// ->andWhere('u.exampleField = :val')
57+
// ->setParameter('val', $value)
58+
// ->orderBy('u.id', 'ASC')
59+
// ->setMaxResults(10)
60+
// ->getQuery()
61+
// ->getResult()
62+
// ;
63+
// }
6664

67-
/*
68-
public function findOneBySomeField($value): ?UserXml
69-
{
70-
return $this->createQueryBuilder('u')
71-
->andWhere('u.exampleField = :val')
72-
->setParameter('val', $value)
73-
->getQuery()
74-
->getOneOrNullResult()
75-
;
76-
}
77-
*/
65+
// public function findOneBySomeField($value): ?UserXml
66+
// {
67+
// return $this->createQueryBuilder('u')
68+
// ->andWhere('u.exampleField = :val')
69+
// ->setParameter('val', $value)
70+
// ->getQuery()
71+
// ->getOneOrNullResult()
72+
// ;
73+
// }
7874
}

tests/Doctrine/fixtures/expected_xml/src/Repository/XOtherRepository.php

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,28 @@ public function remove(XOther $entity, bool $flush = false): void
4747
}
4848
}
4949

50-
// /**
51-
// * @return XOther[] Returns an array of XOther objects
52-
// */
53-
/*
54-
public function findByExampleField($value)
55-
{
56-
return $this->createQueryBuilder('x')
57-
->andWhere('x.exampleField = :val')
58-
->setParameter('val', $value)
59-
->orderBy('x.id', 'ASC')
60-
->setMaxResults(10)
61-
->getQuery()
62-
->getResult()
63-
;
64-
}
65-
*/
50+
// /**
51+
// * @return XOther[] Returns an array of XOther objects
52+
// */
53+
// public function findByExampleField($value): array
54+
// {
55+
// return $this->createQueryBuilder('x')
56+
// ->andWhere('x.exampleField = :val')
57+
// ->setParameter('val', $value)
58+
// ->orderBy('x.id', 'ASC')
59+
// ->setMaxResults(10)
60+
// ->getQuery()
61+
// ->getResult()
62+
// ;
63+
// }
6664

67-
/*
68-
public function findOneBySomeField($value): ?XOther
69-
{
70-
return $this->createQueryBuilder('x')
71-
->andWhere('x.exampleField = :val')
72-
->setParameter('val', $value)
73-
->getQuery()
74-
->getOneOrNullResult()
75-
;
76-
}
77-
*/
65+
// public function findOneBySomeField($value): ?XOther
66+
// {
67+
// return $this->createQueryBuilder('x')
68+
// ->andWhere('x.exampleField = :val')
69+
// ->setParameter('val', $value)
70+
// ->getQuery()
71+
// ->getOneOrNullResult()
72+
// ;
73+
// }
7874
}

0 commit comments

Comments
 (0)