Skip to content

Commit

Permalink
PHP 8 syntax in bundles #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Feb 3, 2022
1 parent c21aa88 commit cc311a0
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 121 deletions.
6 changes: 1 addition & 5 deletions Block/BlockEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@
*/
final class BlockEventListener
{
private string $template;

public function __construct(string $template)
public function __construct(private string $template)
{
@trigger_error(
sprintf('Using "%s" to add blocks to the templates is deprecated since Sylius 1.7 and will be removed in Sylius 2.0. Use "sylius_ui" configuration instead.', self::class),
\E_USER_DEPRECATED
);

$this->template = $template;
}

public function onBlockEvent(BlockEvent $event): void
Expand Down
6 changes: 1 addition & 5 deletions Command/DebugTemplateEventCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ final class DebugTemplateEventCommand extends Command
{
protected static $defaultName = 'sylius:debug:template-event';

private TemplateBlockRegistryInterface $templateBlockRegistry;

public function __construct(TemplateBlockRegistryInterface $templateBlockRegistry)
public function __construct(private TemplateBlockRegistryInterface $templateBlockRegistry)
{
parent::__construct();

$this->templateBlockRegistry = $templateBlockRegistry;
}

protected function configure(): void
Expand Down
25 changes: 2 additions & 23 deletions Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,11 @@

final class SecurityController
{
private AuthenticationUtils $authenticationUtils;

private FormFactoryInterface $formFactory;

/** @var EngineInterface|Environment */
private $templatingEngine;

private AuthorizationCheckerInterface $authorizationChecker;

private RouterInterface $router;

/**
* @param EngineInterface|Environment $templatingEngine
*/
public function __construct(
AuthenticationUtils $authenticationUtils,
FormFactoryInterface $formFactory,
object $templatingEngine,
AuthorizationCheckerInterface $authorizationChecker,
RouterInterface $router
) {
$this->authenticationUtils = $authenticationUtils;
$this->formFactory = $formFactory;
$this->templatingEngine = $templatingEngine;
$this->authorizationChecker = $authorizationChecker;
$this->router = $router;
public function __construct(private AuthenticationUtils $authenticationUtils, private FormFactoryInterface $formFactory, private object $templatingEngine, private AuthorizationCheckerInterface $authorizationChecker, private RouterInterface $router)
{
}

public function loginAction(Request $request): Response
Expand Down
5 changes: 1 addition & 4 deletions DataCollector/TemplateBlockDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
*/
final class TemplateBlockDataCollector extends DataCollector
{
private TemplateBlockRenderingHistory $templateBlockRenderingHistory;

public function __construct(TemplateBlockRenderingHistory $templateBlockRenderingHistory)
public function __construct(private TemplateBlockRenderingHistory $templateBlockRenderingHistory)
{
$this->templateBlockRenderingHistory = $templateBlockRenderingHistory;
$this->reset();
}

Expand Down
8 changes: 1 addition & 7 deletions DataCollector/TraceableTemplateBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@
*/
final class TraceableTemplateBlockRenderer implements TemplateBlockRendererInterface
{
private TemplateBlockRendererInterface $templateBlockRenderer;

private TemplateBlockRenderingHistory $templateBlockRenderingHistory;

public function __construct(TemplateBlockRendererInterface $templateBlockRenderer, TemplateBlockRenderingHistory $templateBlockRenderingHistory)
public function __construct(private TemplateBlockRendererInterface $templateBlockRenderer, private TemplateBlockRenderingHistory $templateBlockRenderingHistory)
{
$this->templateBlockRenderer = $templateBlockRenderer;
$this->templateBlockRenderingHistory = $templateBlockRenderingHistory;
}

public function render(TemplateBlock $templateBlock, array $context = []): string
Expand Down
8 changes: 1 addition & 7 deletions DataCollector/TraceableTemplateEventRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@
*/
final class TraceableTemplateEventRenderer implements TemplateEventRendererInterface
{
private TemplateEventRendererInterface $templateEventRenderer;

private TemplateBlockRenderingHistory $templateBlockRenderingHistory;

public function __construct(TemplateEventRendererInterface $templateEventRenderer, TemplateBlockRenderingHistory $templateBlockRenderingHistory)
public function __construct(private TemplateEventRendererInterface $templateEventRenderer, private TemplateBlockRenderingHistory $templateBlockRenderingHistory)
{
$this->templateEventRenderer = $templateEventRenderer;
$this->templateBlockRenderingHistory = $templateBlockRenderingHistory;
}

public function render(array $eventNames, array $context = []): string
Expand Down
8 changes: 1 addition & 7 deletions Menu/Event/MenuBuilderEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@

class MenuBuilderEvent extends Event
{
private FactoryInterface $factory;

private ItemInterface $menu;

public function __construct(FactoryInterface $factory, ItemInterface $menu)
public function __construct(private FactoryInterface $factory, private ItemInterface $menu)
{
$this->factory = $factory;
$this->menu = $menu;
}

public function getFactory(): FactoryInterface
Expand Down
28 changes: 2 additions & 26 deletions Registry/TemplateBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,8 @@
*/
final class TemplateBlock
{
private string $name;

private string $eventName;

private ?string $template;

private ?array $context;

private ?int $priority;

private ?bool $enabled;

public function __construct(
string $name,
string $eventName,
?string $template,
?array $context,
?int $priority,
?bool $enabled
) {
$this->name = $name;
$this->eventName = $eventName;
$this->template = $template;
$this->context = $context;
$this->priority = $priority;
$this->enabled = $enabled;
public function __construct(private string $name, private string $eventName, private ?string $template, private ?array $context, private ?int $priority, private ?bool $enabled)
{
}

public function getName(): string
Expand Down
8 changes: 1 addition & 7 deletions Renderer/DelegatingTemplateEventRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@
*/
final class DelegatingTemplateEventRenderer implements TemplateEventRendererInterface
{
private TemplateBlockRegistryInterface $templateBlockRegistry;

private TemplateBlockRendererInterface $templateBlockRenderer;

public function __construct(TemplateBlockRegistryInterface $templateBlockRegistry, TemplateBlockRendererInterface $templateBlockRenderer)
public function __construct(private TemplateBlockRegistryInterface $templateBlockRegistry, private TemplateBlockRendererInterface $templateBlockRenderer)
{
$this->templateBlockRegistry = $templateBlockRegistry;
$this->templateBlockRenderer = $templateBlockRenderer;
}

public function render(array $eventNames, array $context = []): string
Expand Down
5 changes: 1 addition & 4 deletions Renderer/HtmlDebugTemplateBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
*/
final class HtmlDebugTemplateBlockRenderer implements TemplateBlockRendererInterface
{
private TemplateBlockRendererInterface $templateBlockRenderer;

public function __construct(TemplateBlockRendererInterface $templateBlockRenderer)
public function __construct(private TemplateBlockRendererInterface $templateBlockRenderer)
{
$this->templateBlockRenderer = $templateBlockRenderer;
}

public function render(TemplateBlock $templateBlock, array $context = []): string
Expand Down
8 changes: 1 addition & 7 deletions Renderer/HtmlDebugTemplateEventRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@
*/
final class HtmlDebugTemplateEventRenderer implements TemplateEventRendererInterface
{
private TemplateEventRendererInterface $templateEventRenderer;

private TemplateBlockRegistryInterface $templateBlockRegistry;

public function __construct(TemplateEventRendererInterface $templateEventRenderer, TemplateBlockRegistryInterface $templateBlockRegistry)
public function __construct(private TemplateEventRendererInterface $templateEventRenderer, private TemplateBlockRegistryInterface $templateBlockRegistry)
{
$this->templateEventRenderer = $templateEventRenderer;
$this->templateBlockRegistry = $templateBlockRegistry;
}

public function render(array $eventNames, array $context = []): string
Expand Down
5 changes: 1 addition & 4 deletions Renderer/TwigTemplateBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@
*/
final class TwigTemplateBlockRenderer implements TemplateBlockRendererInterface
{
private Environment $twig;

public function __construct(Environment $twig)
public function __construct(private Environment $twig)
{
$this->twig = $twig;
}

public function render(TemplateBlock $templateBlock, array $context = []): string
Expand Down
7 changes: 2 additions & 5 deletions Twig/TemplateEventExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@
*/
final class TemplateEventExtension extends AbstractExtension
{
private TemplateEventRendererInterface $templateEventRenderer;

public function __construct(TemplateEventRendererInterface $templateEventRenderer)
public function __construct(private TemplateEventRendererInterface $templateEventRenderer)
{
$this->templateEventRenderer = $templateEventRenderer;
}

public function getFunctions(): array
Expand All @@ -39,7 +36,7 @@ public function getFunctions(): array
/**
* @param string|string[] $eventName
*/
public function render($eventName, array $context = []): string
public function render(string|array $eventName, array $context = []): string
{
return $this->templateEventRenderer->render((array) $eventName, $context);
}
Expand Down
7 changes: 2 additions & 5 deletions Twig/TestFormAttributeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@

final class TestFormAttributeExtension extends AbstractExtension
{
private string $environment;

public function __construct(string $environment)
public function __construct(private string $environment)
{
$this->environment = $environment;
}

/**
Expand All @@ -34,7 +31,7 @@ public function getFunctions(): array
new TwigFunction(
'sylius_test_form_attribute',
function (string $name, ?string $value = null): array {
if (strpos($this->environment, 'test') === 0) {
if (str_starts_with($this->environment, 'test')) {
return ['attr' => ['data-test-' . $name => (string) $value]];
}

Expand Down
7 changes: 2 additions & 5 deletions Twig/TestHtmlAttributeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@

final class TestHtmlAttributeExtension extends AbstractExtension
{
private string $env;

public function __construct(string $env)
public function __construct(private string $env)
{
$this->env = $env;
}

/**
Expand All @@ -34,7 +31,7 @@ public function getFunctions(): array
new TwigFunction(
'sylius_test_html_attribute',
function (string $name, ?string $value = null): string {
if (strpos($this->env, 'test') === 0) {
if (str_starts_with($this->env, 'test')) {
return sprintf('data-test-%s="%s"', $name, (string) $value);
}

Expand Down

0 comments on commit cc311a0

Please sign in to comment.