Skip to content

Commit

Permalink
refactor #13562 PHP 8.0 syntax in bundles (without CoreBundle and Api…
Browse files Browse the repository at this point in the history
…Bundle) (Zales0123)

This PR was merged into the 1.11 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | 1.11
| Bug fix?        | no
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | continuation of #13502
| License         | MIT



Commits
-------

50ac49c PHP 8 syntax in bundles #1
489c163 Fix line length issues
ced91b9 Typehint templating engines properly
  • Loading branch information
lchrusciel committed Feb 4, 2022
2 parents 37dab55 + ced91b9 commit 5723c0b
Show file tree
Hide file tree
Showing 222 changed files with 432 additions and 1,502 deletions.
21 changes: 20 additions & 1 deletion UPGRADE-1.11.md
Expand Up @@ -20,7 +20,9 @@ This obvious dev dependency was part of Sylius requirements. In 1.11 we've moved

Due to the drop of support PHP `7.4` Sylius also will not support it since version `1.11`.

### Potential BC-break
### Potential BC-breaks

#### WinzouStateMachine

In Sylius we are using WinzouStateMachine where as example `sylius_order` state machine has declared 14 callbacks on one state.
If this will be customized and number of callbacks comes up to 16 and higher - the priority of callbacks will become randomized.
Expand All @@ -32,6 +34,23 @@ Please note that those priorities are being executed in ascending order. You can
Be aware that if those priorities were customized, this would lead to problems.
You should check and adjust priorities on your application.

#### Promoted properties from PHP 8.0

We've introduced promoted properties all over the code where it was possible. Please, pay attention especially to these classes:
- `Sylius\Bundle\AdminBundle\Controller\CustomerStatisticsController`
- `Sylius\Bundle\AdminBundle\Controller\Dashboard\StatisticsController`
- `Sylius\Bundle\AdminBundle\Controller\DashboardController`
- `Sylius\Bundle\ShopBundle\Controller\ContactController`
- `Sylius\Bundle\ShopBundle\Controller\CurrencySwitchController`
- `Sylius\Bundle\ShopBundle\Controller\HomepageController`
- `Sylius\Bundle\ShopBundle\Controller\LocaleSwitchController`
- `Sylius\Bundle\ShopBundle\Controller\SecurityWidgetController`
- `Sylius\Bundle\UiBundle\Controller\SecurityController`

In all of them constructor argument `$templatingEngine`, previously typed as `object` was changed to `EngineInterface|Environment`.
It should not cause any problems (only such services would work in these controllers), but is theoretically making the type
requirement stricter.

### Minimum price & Promotions

We added MinimumPrice to channelPricings entity, this price should be taken into account when customizing any promotions in Sylius.
Expand Down
18 changes: 18 additions & 0 deletions phpstan.neon.dist
Expand Up @@ -36,3 +36,21 @@ parameters:
- 'src/Sylius/Bundle/CoreBundle/Tests/Listener/CircularDependencyBreakingExceptionListenerTest.php'
ignoreErrors:
- '/Access to an undefined property Doctrine\\Common\\Collections\\ArrayCollection/'
- '/Parameter \$templatingEngine of method Sylius\\Bundle\\AdminBundle\\Controller\\CustomerStatisticsController\:\:\_\_construct\(\) has invalid typehint type Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface\./'
- '/Parameter \$templatingEngine of method Sylius\\Bundle\\AdminBundle\\Controller\\Dashboard\\StatisticsController\:\:\_\_construct\(\) has invalid typehint type Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface\./'
- '/Parameter \$templatingEngine of method Sylius\\Bundle\\AdminBundle\\Controller\\DashboardController\:\:\_\_construct\(\) has invalid typehint type Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface\./'
- '/Parameter \$templatingEngine of method Sylius\\Bundle\\ShopBundle\\Controller\\ContactController\:\:\_\_construct\(\) has invalid typehint type Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface\./'
- '/Parameter \$templatingEngine of method Sylius\\Bundle\\ShopBundle\\Controller\\CurrencySwitchController\:\:\_\_construct\(\) has invalid typehint type Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface\./'
- '/Parameter \$templatingEngine of method Sylius\\Bundle\\ShopBundle\\Controller\\HomepageController\:\:\_\_construct\(\) has invalid typehint type Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface\./'
- '/Parameter \$templatingEngine of method Sylius\\Bundle\\ShopBundle\\Controller\\LocaleSwitchController\:\:\_\_construct\(\) has invalid typehint type Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface\./'
- '/Parameter \$templatingEngine of method Sylius\\Bundle\\ShopBundle\\Controller\\SecurityWidgetController\:\:\_\_construct\(\) has invalid typehint type Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface\./'
- '/Parameter \$templatingEngine of method Sylius\\Bundle\\UiBundle\\Controller\\SecurityController\:\:\_\_construct\(\) has invalid typehint type Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface\./'
- '/Property Sylius\\Bundle\\AdminBundle\\Controller\\CustomerStatisticsController\:\:\$templatingEngine has unknown class Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface as its type\./'
- '/Property Sylius\\Bundle\\AdminBundle\\Controller\\Dashboard\\StatisticsController\:\:\$templatingEngine has unknown class Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface as its type\./'
- '/Property Sylius\\Bundle\\AdminBundle\\Controller\\DashboardController\:\:\$templatingEngine has unknown class Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface as its type\./'
- '/Property Sylius\\Bundle\\ShopBundle\\Controller\\ContactController\:\:\$templatingEngine has unknown class Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface as its type\./'
- '/Property Sylius\\Bundle\\ShopBundle\\Controller\\CurrencySwitchController\:\:\$templatingEngine has unknown class Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface as its type\./'
- '/Property Sylius\\Bundle\\ShopBundle\\Controller\\HomepageController\:\:\$templatingEngine has unknown class Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface as its type\./'
- '/Property Sylius\\Bundle\\ShopBundle\\Controller\\LocaleSwitchController\:\:\$templatingEngine has unknown class Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface as its type\./'
- '/Property Sylius\\Bundle\\ShopBundle\\Controller\\SecurityWidgetController\:\:\$templatingEngine has unknown class Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface as its type\./'
- '/Property Sylius\\Bundle\\UiBundle\\Controller\\SecurityController\:\:\$templatingEngine has unknown class Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface as its type\./'
14 changes: 14 additions & 0 deletions psalm.xml
Expand Up @@ -154,6 +154,20 @@

<RedundantConditionGivenDocblockType errorLevel="info" />

<UndefinedClass>
<errorLevel type="info">
<file name="src/Sylius/Bundle/AdminBundle/Controller/CustomerStatisticsController.php" />
<file name="src/Sylius/Bundle/AdminBundle/Controller/Dashboard/StatisticsController.php" />
<file name="src/Sylius/Bundle/AdminBundle/Controller/DashboardController.php" />
<file name="src/Sylius/Bundle/ShopBundle/Controller/ContactController.php" />
<file name="src/Sylius/Bundle/ShopBundle/Controller/CurrencySwitchController.php" />
<file name="src/Sylius/Bundle/ShopBundle/Controller/HomepageController.php" />
<file name="src/Sylius/Bundle/ShopBundle/Controller/LocaleSwitchController.php" />
<file name="src/Sylius/Bundle/ShopBundle/Controller/SecurityWidgetController.php" />
<file name="src/Sylius/Bundle/UiBundle/Controller/SecurityController.php" />
</errorLevel>
</UndefinedClass>

<!-- level 4 issues - points to possible deficiencies in logic, higher false-positives -->

<MoreSpecificReturnType errorLevel="info" />
Expand Down
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
15 changes: 3 additions & 12 deletions src/Sylius/Bundle/AdminBundle/Action/RemoveAvatarAction.php
Expand Up @@ -25,20 +25,11 @@

final class RemoveAvatarAction
{
private AvatarImageRepositoryInterface $avatarRepository;

private RouterInterface $router;

private CsrfTokenManagerInterface $csrfTokenManager;

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

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

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
private OrderRepositoryInterface $orderRepository,
private OrderEmailManagerInterface $orderEmailManager,
private CsrfTokenManagerInterface $csrfTokenManager,
private Session $session
) {
$this->orderRepository = $orderRepository;
$this->orderEmailManager = $orderEmailManager;
$this->csrfTokenManager = $csrfTokenManager;
$this->session = $session;
}

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

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
private ShipmentRepositoryInterface $shipmentRepository,
private ShipmentEmailManagerInterface $shipmentEmailManager,
private CsrfTokenManagerInterface $csrfTokenManager,
private Session $session
) {
$this->shipmentRepository = $shipmentRepository;
$this->shipmentEmailManager = $shipmentEmailManager;
$this->csrfTokenManager = $csrfTokenManager;
$this->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

0 comments on commit 5723c0b

Please sign in to comment.