Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/Maker/MakeVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;

/**
Expand Down Expand Up @@ -56,9 +55,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
$generator->generateClass(
$voterClassNameDetails->getFullName(),
'security/Voter.tpl.php',
[
'use_type_hints' => 50000 <= Kernel::VERSION_ID,
]
[]
);

$generator->writeChanges();
Expand Down
50 changes: 23 additions & 27 deletions src/Resources/skeleton/doctrine/Repository.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,29 @@ public function upgradePassword(<?= sprintf('%s ', $password_upgrade_user_interf

<?php endif ?>
<?php if ($include_example_comments): ?>
// /**
// * @return <?= $entity_class_name ?>[] Returns an array of <?= $entity_class_name ?> objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('<?= $entity_alias; ?>')
->andWhere('<?= $entity_alias; ?>.exampleField = :val')
->setParameter('val', $value)
->orderBy('<?= $entity_alias; ?>.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
// /**
// * @return <?= $entity_class_name ?>[] Returns an array of <?= $entity_class_name ?> objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('<?= $entity_alias; ?>')
// ->andWhere('<?= $entity_alias; ?>.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('<?= $entity_alias; ?>.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sticking to a consistent CS for examples


/*
public function findOneBySomeField($value): ?<?= $entity_class_name."\n" ?>
{
return $this->createQueryBuilder('<?= $entity_alias ?>')
->andWhere('<?= $entity_alias ?>.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
// public function findOneBySomeField($value): ?<?= $entity_class_name."\n" ?>
// {
// return $this->createQueryBuilder('<?= $entity_alias ?>')
// ->andWhere('<?= $entity_alias ?>.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
<?php endif; ?>
}
4 changes: 2 additions & 2 deletions src/Resources/skeleton/event/Subscriber.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

class <?= $class_name ?> implements EventSubscriberInterface
{
public function <?= $method_name ?>(<?= $event_arg ?>)
public function <?= $method_name ?>(<?= $event_arg ?>): void
{
// ...
}

public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

triggers a deprecation without the return type

{
return [
<?= $event ?> => '<?= $method_name ?>',
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/skeleton/message/Message.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
final class <?= $class_name."\n" ?>
{
/*
* Add whatever properties & methods you need to hold the
* data for this message class.
* Add whatever properties and methods you need
* to hold the data for this message class.
*/

// private $name;
//

// public function __construct(string $name)
// {
// $this->name = $name;
// }
//

// public function getName(): string
// {
// return $this->name;
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/security/UserProvider.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function refreshUser(UserInterface $user): UserInterface
/**
* Tells Symfony to use this provider for this User class.
*/
public function supportsClass($class): bool
public function supportsClass(string $class): bool
{
return <?= $user_short_name ?>::class === $class || is_subclass_of($class, <?= $user_short_name ?>::class);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/skeleton/security/Voter.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class <?= $class_name ?> extends Voter
public const EDIT = 'POST_EDIT';
public const VIEW = 'POST_VIEW';

protected function supports(<?= $use_type_hints ? 'string ' : null ?>$attribute, $subject): bool
protected function supports(string $attribute, $subject): bool
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kernel is at 5.4 minimum already

{
// replace with your own logic
// https://symfony.com/doc/current/security/voters.html
return in_array($attribute, [self::EDIT, self::VIEW])
&& $subject instanceof \App\Entity\<?= str_replace('Voter', null, $class_name) ?>;
}

protected function voteOnAttribute(<?= $use_type_hints ? 'string ' : null ?>$attribute, $subject, TokenInterface $token): bool
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
$user = $token->getUser();
// if the user is anonymous, do not grant access
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/skeleton/serializer/Encoder.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ class <?= $class_name ?> implements EncoderInterface, DecoderInterface
{
public const FORMAT = '<?= $format ?>';

public function encode($data, $format, array $context = [])
public function encode($data, string $format, array $context = []): string
{
// TODO: return your encoded data
return '';
}

public function supportsEncoding($format): bool
public function supportsEncoding(string $format, array $context = []): bool
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not adding $context is deprecated

{
return self::FORMAT === $format;
}

public function decode($data, $format, array $context = [])
public function decode(string $data, string $format, array $context = [])
{
// TODO: return your decoded data
return '';
}

public function supportsDecoding($format): bool
public function supportsDecoding(string $format, array $context = []): bool
{
return self::FORMAT === $format;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/skeleton/serializer/Normalizer.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ public function __construct(ObjectNormalizer $normalizer)
$this->normalizer = $normalizer;
}

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

// Here: add, edit, or delete some data
// TODO: add, edit, or delete some data
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistency


return $data;
}

public function supportsNormalization($data, $format = null): bool
public function supportsNormalization($data, string $format = null, array $context = []): bool
{
return $data instanceof \App\Entity\<?= str_replace('Normalizer', null, $class_name) ?>;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/skeleton/validator/Constraint.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

/**
* @Annotation
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we can, isn't it?

class <?= $class_name ?> extends Constraint
{
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,28 @@ public function remove(UserXml $entity, bool $flush = false): void
}
}

// /**
// * @return UserXml[] Returns an array of UserXml objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('u')
->andWhere('u.exampleField = :val')
->setParameter('val', $value)
->orderBy('u.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
// /**
// * @return UserXml[] Returns an array of UserXml objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('u.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }

/*
public function findOneBySomeField($value): ?UserXml
{
return $this->createQueryBuilder('u')
->andWhere('u.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
// public function findOneBySomeField($value): ?UserXml
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,28 @@ public function remove(XOther $entity, bool $flush = false): void
}
}

// /**
// * @return XOther[] Returns an array of XOther objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('x')
->andWhere('x.exampleField = :val')
->setParameter('val', $value)
->orderBy('x.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
// /**
// * @return XOther[] Returns an array of XOther objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('x')
// ->andWhere('x.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('x.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }

/*
public function findOneBySomeField($value): ?XOther
{
return $this->createQueryBuilder('x')
->andWhere('x.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
// public function findOneBySomeField($value): ?XOther
// {
// return $this->createQueryBuilder('x')
// ->andWhere('x.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}