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 aa970f5 commit 50ac49c
Show file tree
Hide file tree
Showing 220 changed files with 299 additions and 1,530 deletions.
Expand Up @@ -29,14 +29,8 @@
*/
final class BuildAddressFormSubscriber implements EventSubscriberInterface
{
private ObjectRepository $countryRepository;

private FormFactoryInterface $formFactory;

public function __construct(ObjectRepository $countryRepository, FormFactoryInterface $factory)
public function __construct(private ObjectRepository $countryRepository, private FormFactoryInterface $formFactory)
{
$this->countryRepository = $countryRepository;
$this->formFactory = $factory;
}

public static function getSubscribedEvents(): array
Expand Down
6 changes: 1 addition & 5 deletions src/Sylius/Bundle/AddressingBundle/Form/Type/AddressType.php
Expand Up @@ -22,16 +22,12 @@

final class AddressType extends AbstractResourceType
{
private EventSubscriberInterface $buildAddressFormSubscriber;

/**
* @param string[] $validationGroups
*/
public function __construct(string $dataClass, array $validationGroups, EventSubscriberInterface $buildAddressFormSubscriber)
public function __construct(string $dataClass, array $validationGroups, private EventSubscriberInterface $buildAddressFormSubscriber)
{
parent::__construct($dataClass, $validationGroups);

$this->buildAddressFormSubscriber = $buildAddressFormSubscriber;
}

public function buildForm(FormBuilderInterface $builder, array $options): void
Expand Down
Expand Up @@ -24,11 +24,8 @@

final class CountryChoiceType extends AbstractType
{
private RepositoryInterface $countryRepository;

public function __construct(RepositoryInterface $countryRepository)
public function __construct(private RepositoryInterface $countryRepository)
{
$this->countryRepository = $countryRepository;
}

public function buildForm(FormBuilderInterface $builder, array $options): void
Expand Down
Expand Up @@ -21,11 +21,8 @@

final class CountryCodeChoiceType extends AbstractType
{
private RepositoryInterface $countryRepository;

public function __construct(RepositoryInterface $countryRepository)
public function __construct(private RepositoryInterface $countryRepository)
{
$this->countryRepository = $countryRepository;
}

public function buildForm(FormBuilderInterface $builder, array $options): void
Expand Down
Expand Up @@ -22,11 +22,8 @@

final class ProvinceChoiceType extends AbstractType
{
private RepositoryInterface $provinceRepository;

public function __construct(RepositoryInterface $provinceRepository)
public function __construct(private RepositoryInterface $provinceRepository)
{
$this->provinceRepository = $provinceRepository;
}

public function configureOptions(OptionsResolver $resolver): void
Expand Down
Expand Up @@ -21,11 +21,8 @@

final class ProvinceCodeChoiceType extends AbstractType
{
private RepositoryInterface $provinceRepository;

public function __construct(RepositoryInterface $provinceRepository)
public function __construct(private RepositoryInterface $provinceRepository)
{
$this->provinceRepository = $provinceRepository;
}

public function buildForm(FormBuilderInterface $builder, array $options): void
Expand Down
10 changes: 1 addition & 9 deletions src/Sylius/Bundle/AddressingBundle/Form/Type/ZoneChoiceType.php
Expand Up @@ -22,16 +22,8 @@

final class ZoneChoiceType extends AbstractType
{
private RepositoryInterface $zoneRepository;

/** @var string[] */
private array $scopeTypes;

public function __construct(RepositoryInterface $zoneRepository, array $scopeTypes = [])
public function __construct(private RepositoryInterface $zoneRepository, private array $scopeTypes = [])
{
$this->zoneRepository = $zoneRepository;
$this->scopeTypes = $scopeTypes;

if (count($scopeTypes) === 0) {
@trigger_error('Not passing scopeTypes thru constructor is deprecated in Sylius 1.5 and it will be removed in Sylius 2.0');
}
Expand Down
Expand Up @@ -24,11 +24,8 @@

final class ZoneCodeChoiceType extends AbstractType
{
private RepositoryInterface $zoneRepository;

public function __construct(RepositoryInterface $zoneRepository)
public function __construct(private RepositoryInterface $zoneRepository)
{
$this->zoneRepository = $zoneRepository;
}

public function buildForm(FormBuilderInterface $builder, array $options): void
Expand Down
6 changes: 1 addition & 5 deletions src/Sylius/Bundle/AddressingBundle/Form/Type/ZoneType.php
Expand Up @@ -25,17 +25,13 @@

final class ZoneType extends AbstractResourceType
{
private array $scopeChoices;

/**
* @param string[] $validationGroups
* @param string[] $scopeChoices
*/
public function __construct(string $dataClass, array $validationGroups, array $scopeChoices = [])
public function __construct(string $dataClass, array $validationGroups, private array $scopeChoices = [])
{
parent::__construct($dataClass, $validationGroups);

$this->scopeChoices = $scopeChoices;
}

public function buildForm(FormBuilderInterface $builder, array $options): void
Expand Down
Expand Up @@ -38,7 +38,7 @@ public function translateCountryIsoCode($country, ?string $locale = null): strin

try {
$countryName = Countries::getName($countryCode, $locale);
} catch (MissingResourceException $exception) {
} catch (MissingResourceException) {
return $countryCode;
}

Expand Down
Expand Up @@ -19,12 +19,8 @@

class ProvinceNamingExtension extends AbstractExtension
{
/** @var ProvinceNamingProviderInterface */
private $provinceNamingProvider;

public function __construct(ProvinceNamingProviderInterface $provinceNamingProvider)
public function __construct(private ProvinceNamingProviderInterface $provinceNamingProvider)
{
$this->provinceNamingProvider = $provinceNamingProvider;
}

public function getFilters(): array
Expand Down
Expand Up @@ -23,14 +23,8 @@

class ProvinceAddressConstraintValidator extends ConstraintValidator
{
private RepositoryInterface $countryRepository;

private RepositoryInterface $provinceRepository;

public function __construct(RepositoryInterface $countryRepository, RepositoryInterface $provinceRepository)
public function __construct(private RepositoryInterface $countryRepository, private RepositoryInterface $provinceRepository)
{
$this->countryRepository = $countryRepository;
$this->provinceRepository = $provinceRepository;
}

public function validate($value, Constraint $constraint): void
Expand All @@ -47,7 +41,7 @@ public function validate($value, Constraint $constraint): void
$propertyPath = $this->context->getPropertyPath();

foreach (iterator_to_array($this->context->getViolations()) as $violation) {
if (0 === strpos($violation->getPropertyPath(), $propertyPath)) {
if (str_starts_with($violation->getPropertyPath(), $propertyPath)) {
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/AddressingBundle/test/app/AppKernel.php
Expand Up @@ -39,7 +39,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)

protected function getContainerBaseClass()
{
if (0 === strpos($this->environment, 'test')) {
if (str_starts_with($this->environment, 'test')) {
return MockerContainer::class;
}

Expand Down
Expand Up @@ -30,7 +30,7 @@ public function its_services_are_initializable(): void

$services = $container->getServiceIds();

$services = array_filter($services, fn(string $serviceId): bool => 0 === strpos($serviceId, 'sylius.'));
$services = array_filter($services, fn(string $serviceId): bool => str_starts_with($serviceId, 'sylius.'));

foreach ($services as $id) {
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));
Expand Down
16 changes: 2 additions & 14 deletions src/Sylius/Bundle/AdminBundle/Action/RemoveAvatarAction.php
Expand Up @@ -25,20 +25,8 @@

final class RemoveAvatarAction
{
private AvatarImageRepositoryInterface $avatarRepository;

private RouterInterface $router;

private CsrfTokenManagerInterface $csrfTokenManager;

public function __construct(
AvatarImageRepositoryInterface $avatarRepository,
RouterInterface $router,
CsrfTokenManagerInterface $csrfTokenManager
) {
$this->avatarRepository = $avatarRepository;
$this->router = $router;
$this->csrfTokenManager = $csrfTokenManager;
public function __construct(private AvatarImageRepositoryInterface $avatarRepository, private RouterInterface $router, private CsrfTokenManagerInterface $csrfTokenManager)
{
}

public function __invoke(Request $request): Response
Expand Down
Expand Up @@ -27,24 +27,8 @@

final class ResendOrderConfirmationEmailAction
{
private OrderRepositoryInterface $orderRepository;

private OrderEmailManagerInterface $orderEmailManager;

private CsrfTokenManagerInterface $csrfTokenManager;

private Session $session;

public function __construct(
OrderRepositoryInterface $orderRepository,
OrderEmailManagerInterface $orderEmailManager,
CsrfTokenManagerInterface $csrfTokenManager,
Session $session
) {
$this->orderRepository = $orderRepository;
$this->orderEmailManager = $orderEmailManager;
$this->csrfTokenManager = $csrfTokenManager;
$this->session = $session;
public function __construct(private OrderRepositoryInterface $orderRepository, private OrderEmailManagerInterface $orderEmailManager, private CsrfTokenManagerInterface $csrfTokenManager, private Session $session)
{
}

public function __invoke(Request $request): Response
Expand Down
Expand Up @@ -27,24 +27,8 @@

final class ResendShipmentConfirmationEmailAction
{
private ShipmentRepositoryInterface $shipmentRepository;

private ShipmentEmailManagerInterface $shipmentEmailManager;

private CsrfTokenManagerInterface $csrfTokenManager;

private Session $session;

public function __construct(
ShipmentRepositoryInterface $shipmentRepository,
ShipmentEmailManagerInterface $shipmentEmailManager,
CsrfTokenManagerInterface $csrfTokenManager,
Session $session
) {
$this->shipmentRepository = $shipmentRepository;
$this->shipmentEmailManager = $shipmentEmailManager;
$this->csrfTokenManager = $csrfTokenManager;
$this->session = $session;
public function __construct(private ShipmentRepositoryInterface $shipmentRepository, private ShipmentEmailManagerInterface $shipmentEmailManager, private CsrfTokenManagerInterface $csrfTokenManager, private Session $session)
{
}

public function __invoke(Request $request): Response
Expand Down
Expand Up @@ -20,11 +20,8 @@

final class AdminBasedLocaleContext implements LocaleContextInterface
{
private TokenStorageInterface $tokenStorage;

public function __construct(TokenStorageInterface $tokenStorage)
public function __construct(private TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}

public function getLocaleCode(): string
Expand Down
Expand Up @@ -24,24 +24,11 @@

final class CustomerStatisticsController
{
private CustomerStatisticsProviderInterface $statisticsProvider;

private RepositoryInterface $customerRepository;

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

/**
* @param EngineInterface|Environment $templatingEngine
*/
public function __construct(
CustomerStatisticsProviderInterface $statisticsProvider,
RepositoryInterface $customerRepository,
object $templatingEngine
) {
$this->statisticsProvider = $statisticsProvider;
$this->customerRepository = $customerRepository;
$this->templatingEngine = $templatingEngine;
public function __construct(private CustomerStatisticsProviderInterface $statisticsProvider, private RepositoryInterface $customerRepository, private object $templatingEngine)
{
}

/**
Expand Down
Expand Up @@ -21,20 +21,11 @@

final class StatisticsController
{
/** @var EngineInterface|Environment */
private $templatingEngine;

private StatisticsDataProviderInterface $statisticsDataProvider;

/**
* @param EngineInterface|Environment $templatingEngine
*/
public function __construct(
object $templatingEngine,
StatisticsDataProviderInterface $statisticsDataProvider
) {
$this->templatingEngine = $templatingEngine;
$this->statisticsDataProvider = $statisticsDataProvider;
public function __construct(private object $templatingEngine, private StatisticsDataProviderInterface $statisticsDataProvider)
{
}

public function renderStatistics(ChannelInterface $channel): Response
Expand Down
25 changes: 2 additions & 23 deletions src/Sylius/Bundle/AdminBundle/Controller/DashboardController.php
Expand Up @@ -27,32 +27,11 @@

final class DashboardController
{
private ChannelRepositoryInterface $channelRepository;

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

private RouterInterface $router;

private ?SalesDataProviderInterface $salesDataProvider;

private ?StatisticsDataProviderInterface $statisticsDataProvider;

/**
* @param EngineInterface|Environment $templatingEngine
*/
public function __construct(
ChannelRepositoryInterface $channelRepository,
object $templatingEngine,
RouterInterface $router,
?SalesDataProviderInterface $salesDataProvider = null,
?StatisticsDataProviderInterface $statisticsDataProvider = null
) {
$this->channelRepository = $channelRepository;
$this->templatingEngine = $templatingEngine;
$this->router = $router;
$this->salesDataProvider = $salesDataProvider;
$this->statisticsDataProvider = $statisticsDataProvider;
public function __construct(private ChannelRepositoryInterface $channelRepository, private object $templatingEngine, private RouterInterface $router, private ?\Sylius\Component\Core\Dashboard\SalesDataProviderInterface $salesDataProvider = null, private ?\Sylius\Bundle\AdminBundle\Provider\StatisticsDataProviderInterface $statisticsDataProvider = null)
{
}

public function indexAction(Request $request): Response
Expand Down

0 comments on commit 50ac49c

Please sign in to comment.