Skip to content

Commit 9c91ab2

Browse files
committed
Code cleanup and modernization
1 parent 6d0668b commit 9c91ab2

9 files changed

Lines changed: 17 additions & 67 deletions

File tree

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ jobs:
5252
-
5353
name: Remove analyse dependencies
5454
run: |
55-
composer remove vimeo/psalm --dev --no-update
5655
composer remove sylius-labs/coding-standard --dev --no-update
5756
composer remove rector/rector --dev --no-update
5857

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2011-2021 Paweł Jędrzejewski
1+
Copyright (c) 2011 Sylius Sp. z o.o.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
},
6161
"extra": {
6262
"branch-alias": {
63-
"dev-master": "2.2-dev"
63+
"dev-master": "2.5-dev"
6464
}
6565
},
6666
"autoload": {

src/Command/AssetsInstallCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Sylius\Bundle\ThemeBundle\Asset\Installer\AssetsInstallerInterface;
1717
use Sylius\Bundle\ThemeBundle\Asset\Installer\OutputAwareInterface;
18+
use Symfony\Component\Console\Attribute\AsCommand;
1819
use Symfony\Component\Console\Command\Command;
1920
use Symfony\Component\Console\Exception\InvalidArgumentException;
2021
use Symfony\Component\Console\Input\InputArgument;
@@ -25,6 +26,7 @@
2526
/**
2627
* Command that places themes web assets into a given directory.
2728
*/
29+
#[AsCommand(name: 'sylius:theme:assets:install', description: 'Installs themes web assets under a public web directory')]
2830
final class AssetsInstallCommand extends Command
2931
{
3032
private AssetsInstallerInterface $assetsInstaller;
@@ -33,7 +35,7 @@ final class AssetsInstallCommand extends Command
3335

3436
public function __construct(AssetsInstallerInterface $assetsInstaller, string $projectDir)
3537
{
36-
parent::__construct(null);
38+
parent::__construct();
3739

3840
$this->assetsInstaller = $assetsInstaller;
3941
$this->projectDir = $projectDir;
@@ -42,13 +44,11 @@ public function __construct(AssetsInstallerInterface $assetsInstaller, string $p
4244
protected function configure(): void
4345
{
4446
$this
45-
->setName('sylius:theme:assets:install')
4647
->setDefinition([
4748
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory'),
4849
])
4950
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it')
5051
->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks')
51-
->setDescription('Installs themes web assets under a public web directory')
5252
->setHelp($this->getHelpMessage())
5353
;
5454
}

src/Command/ListCommand.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,24 @@
1414
namespace Sylius\Bundle\ThemeBundle\Command;
1515

1616
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
17+
use Symfony\Component\Console\Attribute\AsCommand;
1718
use Symfony\Component\Console\Command\Command;
1819
use Symfony\Component\Console\Helper\Table;
1920
use Symfony\Component\Console\Input\InputInterface;
2021
use Symfony\Component\Console\Output\OutputInterface;
2122

23+
#[AsCommand(name: 'sylius:theme:list', description: 'Shows list of detected themes.')]
2224
final class ListCommand extends Command
2325
{
2426
private ThemeRepositoryInterface $themeRepository;
2527

2628
public function __construct(ThemeRepositoryInterface $themeRepository)
2729
{
28-
parent::__construct(null);
30+
parent::__construct();
2931

3032
$this->themeRepository = $themeRepository;
3133
}
3234

33-
protected function configure(): void
34-
{
35-
$this
36-
->setName('sylius:theme:list')
37-
->setDescription('Shows list of detected themes.')
38-
;
39-
}
40-
4135
protected function execute(InputInterface $input, OutputInterface $output): int
4236
{
4337
$themes = $this->themeRepository->findAll();

src/Loader/CircularDependencyFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class CircularDependencyFoundException extends \DomainException
2020
/**
2121
* @param ThemeInterface[] $themes
2222
*/
23-
public function __construct(array $themes, ?\Exception $previous = null)
23+
public function __construct(array $themes, ?\Throwable $previous = null)
2424
{
2525
$cycle = $this->getCycleFromArray($themes);
2626

src/Translation/ThemeAwareTranslator.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,15 @@ final class ThemeAwareTranslator implements TranslatorInterface, TranslatorBagIn
3333
public function __construct(TranslatorInterface $translator, ThemeContextInterface $themeContext)
3434
{
3535
foreach ([LocaleAwareInterface::class, TranslatorBagInterface::class] as $interface) {
36-
/** @psalm-suppress DocblockTypeContradiction Better safe than sorry */
3736
if (!$translator instanceof $interface) {
38-
/** @psalm-suppress NoValue Better safe than sorry */
3937
throw new \InvalidArgumentException(sprintf(
4038
'The translator "%s" must implement %s.',
41-
get_class($translator),
39+
$translator::class,
4240
$interface,
4341
));
4442
}
4543
}
4644

47-
/** @psalm-suppress InvalidPropertyAssignmentValue */
4845
$this->translator = $translator;
4946
$this->themeContext = $themeContext;
5047
}
@@ -60,9 +57,6 @@ public function __call(string $method, array $arguments)
6057
return $translator->$method(...$arguments);
6158
}
6259

63-
/**
64-
* @psalm-suppress MissingParamType Two interfaces defining the same method
65-
*/
6660
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
6761
{
6862
return $this->translator->trans($id, $parameters, $domain, $this->transformLocale($locale));
@@ -101,10 +95,6 @@ public function getCatalogue($locale = null): MessageCatalogueInterface
10195
return $this->translator->getCatalogue($locale);
10296
}
10397

104-
/**
105-
* @psalm-suppress MissingParamType
106-
* @psalm-suppress MissingReturnType
107-
*/
10898
public function warmUp($cacheDir, ?string $buildDir = null): array
10999
{
110100
if ($this->translator instanceof WarmableInterface) {

src/Translation/Translator.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ final class Translator extends BaseTranslator implements WarmableInterface
2828
'debug' => false,
2929
];
3030

31-
/** @psalm-suppress PropertyNotSetInConstructor It is set in the constructor though */
3231
private TranslatorLoaderProviderInterface $loaderProvider;
3332

34-
/** @psalm-suppress PropertyNotSetInConstructor It is set in the constructor though */
3533
private TranslatorResourceProviderInterface $resourceProvider;
3634

3735
private bool $resourcesLoaded = false;
@@ -59,18 +57,13 @@ public function __construct(
5957
parent::__construct($locale, $this->provideMessageFormatter($messageFormatterOrSelector), $this->options['cache_dir'], $this->options['debug']);
6058
}
6159

62-
/**
63-
* @psalm-suppress MissingParamType
64-
* @psalm-suppress MissingReturnType
65-
*/
6660
public function warmUp($cacheDir, ?string $buildDir = null): array
6761
{
6862
// skip warmUp when translator doesn't use cache
6963
if (null === $this->options['cache_dir']) {
7064
return [];
7165
}
7266

73-
/** @psalm-suppress InternalMethod */
7467
$locales = array_merge(
7568
$this->getFallbackLocales(),
7669
[$this->getLocale()],
@@ -182,7 +175,6 @@ private function provideMessageFormatter($messageFormatterOrSelector): MessageFo
182175
if ($messageFormatterOrSelector instanceof MessageSelector) {
183176
@trigger_error(sprintf('Passing a "%s" instance into the "%s" as a third argument is deprecated since Sylius 1.2 and will be removed in 2.0. Inject a "%s" implementation instead.', MessageSelector::class, __METHOD__, MessageFormatterInterface::class), \E_USER_DEPRECATED);
184177

185-
/** @psalm-suppress InvalidArgument */
186178
return new MessageFormatter($this, $messageFormatterOrSelector);
187179
}
188180

@@ -194,7 +186,7 @@ private function provideMessageFormatter($messageFormatterOrSelector): MessageFo
194186
'Expected an instance of "%s" or "%s", got "%s"!',
195187
MessageFormatterInterface::class,
196188
MessageSelector::class,
197-
is_object($messageFormatterOrSelector) ? get_class($messageFormatterOrSelector) : gettype($messageFormatterOrSelector),
189+
is_object($messageFormatterOrSelector) ? $messageFormatterOrSelector::class : gettype($messageFormatterOrSelector),
198190
));
199191
}
200192
}

src/Twig/Loader/ThemedTemplateLoader.php

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface;
1717
use Sylius\Bundle\ThemeBundle\Twig\Locator\TemplateLocatorInterface;
1818
use Sylius\Bundle\ThemeBundle\Twig\Locator\TemplateNotFoundException;
19-
use Symfony\Component\Templating\TemplateReferenceInterface;
2019
use Twig\Loader\LoaderInterface as TwigLoaderInterface;
2120
use Twig\Source;
2221

@@ -38,76 +37,52 @@ public function __construct(
3837
$this->themeContext = $themeContext;
3938
}
4039

41-
/**
42-
* @param string|TemplateReferenceInterface $name
43-
*/
4440
public function getSourceContext($name): Source
4541
{
4642
try {
4743
$path = $this->locateTemplate($name);
4844

49-
/** @psalm-suppress RedundantCastGivenDocblockType */
5045
return new Source((string) file_get_contents($path), (string) $name, $path);
51-
} catch (TemplateNotFoundException | \InvalidArgumentException $exception) {
52-
/** @psalm-suppress PossiblyInvalidArgument */
46+
} catch (TemplateNotFoundException $exception) {
5347
return $this->decoratedLoader->getSourceContext($name);
5448
}
5549
}
5650

57-
/**
58-
* @param string|TemplateReferenceInterface $name
59-
*/
6051
public function getCacheKey($name): string
6152
{
6253
try {
6354
return $this->locateTemplate($name);
64-
} catch (TemplateNotFoundException | \InvalidArgumentException $exception) {
65-
/** @psalm-suppress PossiblyInvalidArgument */
55+
} catch (TemplateNotFoundException $exception) {
6656
return $this->decoratedLoader->getCacheKey($name);
6757
}
6858
}
6959

7060
/**
71-
* @param string|TemplateReferenceInterface $name
7261
* @param int $time
7362
*/
7463
public function isFresh($name, $time): bool
7564
{
7665
try {
7766
return filemtime($this->locateTemplate($name)) <= $time;
78-
} catch (TemplateNotFoundException | \InvalidArgumentException $exception) {
79-
/** @psalm-suppress PossiblyInvalidArgument */
67+
} catch (TemplateNotFoundException $exception) {
8068
return $this->decoratedLoader->isFresh($name, $time);
8169
}
8270
}
8371

84-
/**
85-
* @param string|TemplateReferenceInterface $name
86-
*/
8772
public function exists($name): bool
8873
{
8974
try {
9075
return stat($this->locateTemplate($name)) !== false;
91-
} catch (TemplateNotFoundException | \InvalidArgumentException $exception) {
92-
/** @psalm-suppress PossiblyInvalidArgument */
76+
} catch (TemplateNotFoundException $exception) {
9377
return $this->decoratedLoader->exists($name);
9478
}
9579
}
9680

9781
/**
98-
* @psalm-assert string $template
99-
*
100-
* @param string|TemplateReferenceInterface $template
101-
*
102-
* @throws TemplateNotFoundException|\InvalidArgumentException
82+
* @throws TemplateNotFoundException
10383
*/
104-
private function locateTemplate($template): string
84+
private function locateTemplate(string $template): string
10585
{
106-
if ($template instanceof TemplateReferenceInterface) {
107-
// Symfony 4.x still pushes TemplateReferenceInterface to Twig loader (especially when warming up cache)
108-
throw new \InvalidArgumentException(sprintf('Instances of "%s" are not supported.', TemplateReferenceInterface::class));
109-
}
110-
11186
$theme = $this->themeContext->getTheme();
11287

11388
if ($theme === null) {

0 commit comments

Comments
 (0)