Skip to content

Commit

Permalink
Change le namespace de Twig (#1627)
Browse files Browse the repository at this point in the history
  • Loading branch information
stakovicz authored Feb 12, 2025
1 parent a5360df commit 035f995
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 31 deletions.
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Rector\Config\RectorConfig;
use Rector\Symfony\Set\SymfonySetList;
use Rector\Symfony\Set\TwigSetList;

return RectorConfig::configure()
->withPaths([
Expand All @@ -26,5 +27,6 @@
SymfonySetList::SYMFONY_44,
SymfonySetList::SYMFONY_CODE_QUALITY,
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
TwigSetList::TWIG_UNDERSCORE_TO_NAMESPACE
])
;
4 changes: 2 additions & 2 deletions sources/Afup/Utils/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use AppBundle\Email\Mailer\Adapter\PhpMailerAdapter;
use AppBundle\Email\Mailer\Mailer;
use Psr\Log\NullLogger;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Twig_Environment;

class Mail
{
Expand All @@ -20,7 +20,7 @@ public static function createMailer(): Mailer

return new Mailer(
new NullLogger(),
new Twig_Environment(new FilesystemLoader(self::PROJECT_DIR . '/app/Resources/views/')),
new Environment(new FilesystemLoader(self::PROJECT_DIR . '/app/Resources/views/')),
PhpMailerAdapter::createFromConfiguration($configuration),
$configuration
);
Expand Down
6 changes: 3 additions & 3 deletions sources/AppBundle/Controller/Event/CFP/EditAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Translation\TranslatorInterface;
use Twig_Environment;
use Twig\Environment;

class EditAction
{
private UrlGeneratorInterface $urlGenerator;
private \Twig_Environment $twig;
private Environment $twig;
private SpeakerFactory $speakerFactory;
private FormFactoryInterface $formFactory;
private TranslatorInterface $translator;
Expand All @@ -52,7 +52,7 @@ class EditAction
public function __construct(
EventActionHelper $eventActionHelper,
UrlGeneratorInterface $urlGenerator,
Twig_Environment $twig,
Environment $twig,
FormFactoryInterface $formFactory,
TalkRepository $talkRepository,
TalkInvitationRepository $talkInvitationRepository,
Expand Down
6 changes: 3 additions & 3 deletions sources/AppBundle/Controller/Event/CFP/IndexAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig_Environment;
use Twig\Environment;

class IndexAction
{
const MAX_EVENTS_HISTORY = 50;
private TalkRepository $talkRepository;
private UrlGeneratorInterface $urlGenerator;
private \Twig_Environment $twig;
private Environment $twig;
private SpeakerFactory $speakerFactory;
private PhotoStorage $photoStorage;
private SidebarRenderer $sidebarRenderer;
Expand All @@ -36,7 +36,7 @@ public function __construct(
EventRepository $eventRepository,
TalkRepository $talkRepository,
UrlGeneratorInterface $urlGenerator,
Twig_Environment $twig,
Environment $twig,
SpeakerFactory $speakerFactory,
PhotoStorage $photoStorage,
SidebarRenderer $sidebarRenderer
Expand Down
6 changes: 3 additions & 3 deletions sources/AppBundle/Controller/Event/CFP/ProposeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Twig_Environment;
use Twig\Environment;

class ProposeAction
{
private UrlGeneratorInterface $urlGenerator;
private \Twig_Environment $twig;
private Environment $twig;
private SpeakerFactory $speakerFactory;
private FormFactoryInterface $formFactory;
private TranslatorInterface $translator;
Expand All @@ -33,7 +33,7 @@ class ProposeAction

public function __construct(
UrlGeneratorInterface $urlGenerator,
Twig_Environment $twig,
Environment $twig,
FormFactoryInterface $formFactory,
TalkFormHandler $talkFormHandler,
SpeakerFactory $speakerFactory,
Expand Down
6 changes: 3 additions & 3 deletions sources/AppBundle/Controller/Event/CFP/SidebarRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\TalkRepository;
use DateTime;
use Twig_Environment;
use Twig\Environment;

class SidebarRenderer
{
private TalkRepository $talkRepository;
private SpeakerFactory $speakerFactory;
private \Twig_Environment $twig;
private Environment $twig;

public function __construct(
TalkRepository $talkRepository,
SpeakerFactory $speakerFactory,
Twig_Environment $twig
Environment $twig
) {
$this->talkRepository = $talkRepository;
$this->speakerFactory = $speakerFactory;
Expand Down
6 changes: 3 additions & 3 deletions sources/AppBundle/Controller/Event/CFP/SpeakerAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Twig_Environment;
use Twig\Environment;

class SpeakerAction
{
private UrlGeneratorInterface $urlGenerator;
private \Twig_Environment $twig;
private Environment $twig;
private SpeakerFactory $speakerFactory;
private PhotoStorage $photoStorage;
private SpeakerRepository $speakerRepository;
Expand All @@ -38,7 +38,7 @@ class SpeakerAction
public function __construct(
EventActionHelper $eventActionHelper,
UrlGeneratorInterface $urlGenerator,
Twig_Environment $twig,
Environment $twig,
FormFactoryInterface $formFactory,
SpeakerFactory $speakerFactory,
SpeakerRepository $speakerRepository,
Expand Down
2 changes: 1 addition & 1 deletion sources/AppBundle/Controller/Website/MemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function index(): Response

if ($hasGeneralMeetingPlanned
&& null !== $latestDate
&& ($latestDate->format('Y-m-d') == (new \DateTime('-1 day'))->format('Y-m-d'))
&& ($latestDate->format('Y-m-d') === (new \DateTime('-1 day'))->format('Y-m-d'))
&& count($generalMeetingQuestionRepository->loadByDate($latestDate)) > 0
) {
$displayLinkToGeneralMeetingVote = true;
Expand Down
6 changes: 3 additions & 3 deletions sources/AppBundle/Email/Mailer/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use Afup\Site\Utils\Configuration;
use AppBundle\Email\Mailer\Adapter\MailerAdapter;
use Psr\Log\LoggerInterface;
use Twig_Environment;
use Twig\Environment;

/**
* Send emails
*/
class Mailer
{
private LoggerInterface $logger;
private \Twig_Environment $twig;
private Environment $twig;
private MailerAdapter $adapter;
/** @var string|null */
private $forcedRecipient;
Expand All @@ -24,7 +24,7 @@ class Mailer

public function __construct(
LoggerInterface $logger,
Twig_Environment $twig,
Environment $twig,
MailerAdapter $adapter,
Configuration $configuration
) {
Expand Down
8 changes: 4 additions & 4 deletions sources/AppBundle/Offices/OfficeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ protected function locateNearestLocalOffice(Coordinates $coordinates): array
private function haversineGreatCircleDistance(float $latitudeFrom, float $longitudeFrom, float $latitudeTo, float $longitudeTo, int $earthRadius = 6371000): float
{
// convert from degrees to radians
$latFrom = deg2rad((float) $latitudeFrom);
$lonFrom = deg2rad((float) $longitudeFrom);
$latTo = deg2rad((float) $latitudeTo);
$lonTo = deg2rad((float) $longitudeTo);
$latFrom = deg2rad($latitudeFrom);
$lonFrom = deg2rad($longitudeFrom);
$latTo = deg2rad($latitudeTo);
$lonTo = deg2rad($longitudeTo);

$latDelta = $latTo - $latFrom;
$lonDelta = $lonTo - $lonFrom;
Expand Down
8 changes: 6 additions & 2 deletions sources/AppBundle/Twig/AssetsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

namespace AppBundle\Twig;

class AssetsExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
use Twig\Extension\AbstractExtension;
use Twig\Extension\GlobalsInterface;
use Twig\TwigFunction;

class AssetsExtension extends AbstractExtension implements GlobalsInterface
{
private $kernelRootDir;

Expand All @@ -20,7 +24,7 @@ public function __construct($kernelRootDir)
public function getFunctions()
{
return [
new \Twig_SimpleFunction('asset_md5_start', function (string $url) {
new TwigFunction('asset_md5_start', function (string $url) {
$path = $this->kernelRootDir . '/../htdocs/' . $url;

return substr(md5_file($path), 0, 8);
Expand Down
10 changes: 6 additions & 4 deletions sources/AppBundle/Twig/OfficesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@
namespace AppBundle\Twig;

use AppBundle\Offices\OfficesCollection;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class OfficesExtension extends \Twig_Extension
class OfficesExtension extends AbstractExtension
{
/**
* {@inheritdoc}
*/
public function getFunctions()
{
return [
new \Twig_SimpleFunction('office_name', function ($code) {
new TwigFunction('office_name', function ($code) {
$collection = new OfficesCollection();
return $collection->findByCode($code)['label'];
}),
new \Twig_SimpleFunction('office_logo', function ($code) {
new TwigFunction('office_logo', function ($code) {
$collection = new OfficesCollection();
return $collection->findByCode($code)['logo_url'];
}),
new \Twig_SimpleFunction('office_meetup_urlname', function ($code) {
new TwigFunction('office_meetup_urlname', function ($code) {
$collection = new OfficesCollection();
return $collection->findByCode($code)['meetup_urlname'];
}),
Expand Down

0 comments on commit 035f995

Please sign in to comment.