Skip to content

Commit

Permalink
Typehint templating engines properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Feb 3, 2022
1 parent 489c163 commit ced91b9
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 44 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 @@ -24,13 +24,10 @@

final class CustomerStatisticsController
{
/**
* @param EngineInterface|Environment $templatingEngine
*/
public function __construct(
private CustomerStatisticsProviderInterface $statisticsProvider,
private RepositoryInterface $customerRepository,
private object $templatingEngine
private EngineInterface|Environment $templatingEngine
) {
}

Expand Down
Expand Up @@ -21,11 +21,10 @@

final class StatisticsController
{
/**
* @param EngineInterface|Environment $templatingEngine
*/
public function __construct(private object $templatingEngine, private StatisticsDataProviderInterface $statisticsDataProvider)
{
public function __construct(
private EngineInterface|Environment $templatingEngine,
private StatisticsDataProviderInterface $statisticsDataProvider
) {
}

public function renderStatistics(ChannelInterface $channel): Response
Expand Down
Expand Up @@ -27,12 +27,9 @@

final class DashboardController
{
/**
* @param EngineInterface|Environment $templatingEngine
*/
public function __construct(
private ChannelRepositoryInterface $channelRepository,
private object $templatingEngine,
private EngineInterface|Environment $templatingEngine,
private RouterInterface $router,
private ?SalesDataProviderInterface $salesDataProvider = null,
private ?StatisticsDataProviderInterface $statisticsDataProvider = null
Expand Down
Expand Up @@ -20,14 +20,13 @@

final class LocaleHelper extends Helper implements LocaleHelperInterface
{
private ?LocaleContextInterface $localeContext;

public function __construct(private LocaleConverterInterface $localeConverter, ?LocaleContextInterface $localeContext = null)
{
public function __construct(
private LocaleConverterInterface $localeConverter,
private ?LocaleContextInterface $localeContext = null
) {
if (null === $localeContext) {
@trigger_error('Not passing LocaleContextInterface explicitly as the second argument is deprecated since 1.4 and will be prohibited in 2.0', \E_USER_DEPRECATED);
}
$this->localeContext = $localeContext;
}

public function convertCodeToName(string $code, ?string $localeCode = null): ?string
Expand Down
Expand Up @@ -20,7 +20,7 @@
final class ShippingDateAssigner implements ShippingDateAssignerInterface
{
public function __construct(private DateTimeProvider|DateTimeProviderInterface $calendar)
{g
{
if ($calendar instanceof DateTimeProvider) {
@trigger_error(
sprintf('Passing a "Sylius\Bundle\ShippingBundle\Provider\DateTimeProvider" to "%s" constructor is deprecated since Sylius 1.11 and will be prohibited in 2.0. Use "Sylius\Calendar\Provider\DateTimeProviderInterface" instead.', self::class),
Expand Down
Expand Up @@ -31,13 +31,10 @@

final class ContactController
{
/**
* @param EngineInterface|Environment $templatingEngine
*/
public function __construct(
private RouterInterface $router,
private FormFactoryInterface $formFactory,
private object $templatingEngine,
private EngineInterface|Environment $templatingEngine,
private ChannelContextInterface $channelContext,
private CustomerContextInterface $customerContext,
private LocaleContextInterface $localeContext,
Expand Down
Expand Up @@ -26,11 +26,8 @@

final class CurrencySwitchController
{
/**
* @param EngineInterface|Environment $templatingEngine
*/
public function __construct(
private object $templatingEngine,
private EngineInterface|Environment $templatingEngine,
private CurrencyContextInterface $currencyContext,
private CurrencyStorageInterface $currencyStorage,
private ChannelContextInterface $channelContext
Expand Down
Expand Up @@ -20,10 +20,7 @@

final class HomepageController
{
/**
* @param EngineInterface|Environment $templatingEngine
*/
public function __construct(private object $templatingEngine)
public function __construct(private EngineInterface|Environment $templatingEngine)
{
}

Expand Down
Expand Up @@ -24,11 +24,8 @@

final class LocaleSwitchController
{
/**
* @param EngineInterface|Environment $templatingEngine
*/
public function __construct(
private object $templatingEngine,
private EngineInterface|Environment $templatingEngine,
private LocaleContextInterface $localeContext,
private LocaleProviderInterface $localeProvider,
private LocaleSwitcherInterface $localeSwitcher
Expand Down
Expand Up @@ -19,10 +19,7 @@

final class SecurityWidgetController
{
/**
* @param EngineInterface|Environment $templatingEngine
*/
public function __construct(private object $templatingEngine)
public function __construct(private EngineInterface|Environment $templatingEngine)
{
}

Expand Down
5 changes: 1 addition & 4 deletions src/Sylius/Bundle/UiBundle/Controller/SecurityController.php
Expand Up @@ -26,13 +26,10 @@

final class SecurityController
{
/**
* @param EngineInterface|Environment $templatingEngine
*/
public function __construct(
private AuthenticationUtils $authenticationUtils,
private FormFactoryInterface $formFactory,
private object $templatingEngine,
private EngineInterface|Environment $templatingEngine,
private AuthorizationCheckerInterface $authorizationChecker,
private RouterInterface $router
) {
Expand Down

0 comments on commit ced91b9

Please sign in to comment.