Skip to content

Commit

Permalink
Merge pull request Sylius#8450 from pamil/scalar-types/theme
Browse files Browse the repository at this point in the history
[ThemeBundle] Use typehints introduced by PHP7+
  • Loading branch information
Zales0123 committed Aug 25, 2017
2 parents b6b3e22 + 015c585 commit 03c4887
Show file tree
Hide file tree
Showing 150 changed files with 663 additions and 882 deletions.
14 changes: 9 additions & 5 deletions UPGRADE.md
Expand Up @@ -86,17 +86,13 @@
* `TranslationInterface::setTranslatable`
* `Archivable::setArchivedAt`
* `SlugAwareInterface::setSlug`

### Review / ReviewBundle

* The `ReviewInterface::setAuthor` method does not longer have a default null argument and requires one to be explicitly passed.
* The `ReviewFactoryInterface::createForSubjectWithReviewer` method does not longer have a default null value for `$reviewer` argument and requires one to be explicitly passed.
* Default null value of `ReviewFactoryInterface::createForSubjectWithReviewer` was removed. To create a review without reviewer use `createForSubject` method from the same interface instead.

### Taxonomy / TaxonomyBundle

* `TaxonInterface::getParents` method was renamed to `TaxonInterface::getAncestors`.

### ShopBundle

* `ContactController` has been made final, use decoration instead of extending it.
Expand All @@ -111,6 +107,14 @@
* `ShipmentUnitInterface::setShipment`
* `ShipmentMethodInterface::setCategory`

### Taxonomy / TaxonomyBundle

* `TaxonInterface::getParents` method was renamed to `TaxonInterface::getAncestors`.

### ThemeBundle

* `ThemeHierarchyProviderInterface::getThemeHierarchy` does not longer accepts null as the passed argument.

# UPGRADE FROM 1.0.0-beta.2 to 1.0.0-beta.3

## Packages:
Expand Down
10 changes: 8 additions & 2 deletions src/Sylius/Bundle/CoreBundle/Theme/ChannelBasedThemeContext.php
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\Bundle\CoreBundle\Theme;

use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface;
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Channel\Context\ChannelNotFoundException;
Expand Down Expand Up @@ -47,13 +48,18 @@ public function __construct(ChannelContextInterface $channelContext, ThemeReposi
/**
* {@inheritdoc}
*/
public function getTheme()
public function getTheme(): ?ThemeInterface
{
try {
/** @var ChannelInterface $channel */
$channel = $this->channelContext->getChannel();
$themeName = $channel->getThemeName();

return $this->themeRepository->findOneByName($channel->getThemeName());
if (null === $themeName) {
return null;
}

return $this->themeRepository->findOneByName($themeName);
} catch (ChannelNotFoundException $exception) {
return null;
} catch (\Exception $exception) {
Expand Down
20 changes: 10 additions & 10 deletions src/Sylius/Bundle/ThemeBundle/Asset/Installer/AssetsInstaller.php
Expand Up @@ -78,7 +78,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function installAssets($targetDir, $symlinkMask)
public function installAssets(string $targetDir, int $symlinkMask): int
{
// Create the bundles directory otherwise symlink will fail.
$targetDir = rtrim($targetDir, '/').'/bundles/';
Expand All @@ -95,7 +95,7 @@ public function installAssets($targetDir, $symlinkMask)
/**
* {@inheritdoc}
*/
public function installBundleAssets(BundleInterface $bundle, $targetDir, $symlinkMask)
public function installBundleAssets(BundleInterface $bundle, string $targetDir, int $symlinkMask): int
{
$targetDir .= preg_replace('/bundle$/', '', strtolower($bundle->getName()));

Expand Down Expand Up @@ -131,7 +131,7 @@ public function installBundleAssets(BundleInterface $bundle, $targetDir, $symlin
*
* @return int
*/
private function installThemedBundleAssets(ThemeInterface $theme, $originDir, $targetDir, $symlinkMask)
private function installThemedBundleAssets(ThemeInterface $theme, string $originDir, string $targetDir, int $symlinkMask): int
{
$effectiveSymlinkMask = $symlinkMask;

Expand Down Expand Up @@ -165,7 +165,7 @@ private function installThemedBundleAssets(ThemeInterface $theme, $originDir, $t
*
* @return int
*/
private function installVanillaBundleAssets($originDir, $targetDir, $symlinkMask)
private function installVanillaBundleAssets(string $originDir, string $targetDir, int $symlinkMask): int
{
return $this->installAsset($originDir, $targetDir, $symlinkMask);
}
Expand All @@ -177,7 +177,7 @@ private function installVanillaBundleAssets($originDir, $targetDir, $symlinkMask
*
* @return int
*/
private function installAsset($origin, $target, $symlinkMask)
private function installAsset(string $origin, string $target, int $symlinkMask): int
{
if (AssetsInstallerInterface::RELATIVE_SYMLINK === $symlinkMask) {
try {
Expand Down Expand Up @@ -214,7 +214,7 @@ private function installAsset($origin, $target, $symlinkMask)
*
* @throws IOException When failed to make symbolic link, if requested.
*/
private function doInstallAsset($origin, $target, $symlink)
private function doInstallAsset(string $origin, string $target, bool $symlink): void
{
if ($symlink) {
$this->doSymlinkAsset($origin, $target);
Expand All @@ -227,11 +227,11 @@ private function doInstallAsset($origin, $target, $symlink)

/**
* @param BundleInterface $bundle
* @param ThemeInterface[] $themes
* @param array|ThemeInterface[] $themes
*
* @return array
*/
private function findAssetsPaths(BundleInterface $bundle, array $themes = [])
private function findAssetsPaths(BundleInterface $bundle, array $themes = []): array
{
$sources = [];

Expand All @@ -256,7 +256,7 @@ private function findAssetsPaths(BundleInterface $bundle, array $themes = [])
*
* @throws IOException If symbolic link is broken
*/
private function doSymlinkAsset($origin, $target)
private function doSymlinkAsset(string $origin, string $target): void
{
$this->filesystem->symlink($origin, $target);

Expand All @@ -269,7 +269,7 @@ private function doSymlinkAsset($origin, $target)
* @param string $origin
* @param string $target
*/
private function doCopyAsset($origin, $target)
private function doCopyAsset(string $origin, string $target): void
{
if (is_dir($origin)) {
$this->filesystem->mkdir($target, 0777);
Expand Down
Expand Up @@ -53,7 +53,7 @@ interface AssetsInstallerInterface
*
* @return int Effective symlink mask (lowest value received from installBundleAssets() method)
*/
public function installAssets($targetDir, $symlinkMask);
public function installAssets(string $targetDir, int $symlinkMask);

/**
* @param BundleInterface $bundle
Expand All @@ -62,5 +62,5 @@ public function installAssets($targetDir, $symlinkMask);
*
* @return int Effective symlink mask (lowest value received from installDirAssets() method)
*/
public function installBundleAssets(BundleInterface $bundle, $targetDir, $symlinkMask);
public function installBundleAssets(BundleInterface $bundle, string $targetDir, int $symlinkMask);
}
Expand Up @@ -44,15 +44,15 @@ public function __construct(AssetsInstallerInterface $assetsInstaller)
/**
* {@inheritdoc}
*/
public function setOutput(OutputInterface $output)
public function setOutput(OutputInterface $output): void
{
$this->output = $output;
}

/**
* {@inheritdoc}
*/
public function installAssets($targetDir, $symlinkMask)
public function installAssets(string $targetDir, int $symlinkMask): int
{
$this->output->writeln($this->provideExpectationComment($symlinkMask));

Expand All @@ -62,7 +62,7 @@ public function installAssets($targetDir, $symlinkMask)
/**
* {@inheritdoc}
*/
public function installBundleAssets(BundleInterface $bundle, $targetDir, $symlinkMask)
public function installBundleAssets(BundleInterface $bundle, string $targetDir, int $symlinkMask): int
{
$this->output->writeln(sprintf('Installing assets for <comment>%s</comment>', $bundle->getNamespace(), $targetDir));

Expand All @@ -79,7 +79,7 @@ public function installBundleAssets(BundleInterface $bundle, $targetDir, $symlin
*
* @return string
*/
private function provideResultComment($symlinkMask, $effectiveSymlinkMask)
private function provideResultComment(int $symlinkMask, int $effectiveSymlinkMask): string
{
if ($effectiveSymlinkMask === $symlinkMask) {
switch ($symlinkMask) {
Expand Down Expand Up @@ -108,7 +108,7 @@ private function provideResultComment($symlinkMask, $effectiveSymlinkMask)
*
* @return string
*/
private function provideExpectationComment($symlinkMask)
private function provideExpectationComment(int $symlinkMask): string
{
if (AssetsInstallerInterface::HARD_COPY === $symlinkMask) {
return 'Installing assets as <comment>hard copies</comment>.';
Expand Down
Expand Up @@ -23,5 +23,5 @@ interface OutputAwareInterface
/**
* @param OutputInterface $output
*/
public function setOutput(OutputInterface $output);
public function setOutput(OutputInterface $output): void;
}
6 changes: 3 additions & 3 deletions src/Sylius/Bundle/ThemeBundle/Asset/Package/PathPackage.php
Expand Up @@ -44,11 +44,11 @@ class PathPackage extends BasePathPackage
* @param ContextInterface|null $context
*/
public function __construct(
$basePath,
string $basePath,
VersionStrategyInterface $versionStrategy,
ThemeContextInterface $themeContext,
PathResolverInterface $pathResolver,
ContextInterface $context = null
?ContextInterface $context = null
) {
parent::__construct($basePath, $versionStrategy, $context);

Expand All @@ -59,7 +59,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function getUrl($path)
public function getUrl($path): string
{
if ($this->isAbsoluteUrl($path)) {
return $path;
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ThemeBundle/Asset/PathResolver.php
Expand Up @@ -23,7 +23,7 @@ final class PathResolver implements PathResolverInterface
/**
* {@inheritdoc}
*/
public function resolve($path, ThemeInterface $theme)
public function resolve(string $path, ThemeInterface $theme): string
{
return str_replace('bundles/', 'bundles/_themes/' . $theme->getName() . '/', $path);
}
Expand Down
Expand Up @@ -29,5 +29,5 @@ interface PathResolverInterface
*
* @return string
*/
public function resolve($path, ThemeInterface $theme);
public function resolve(string $path, ThemeInterface $theme): string;
}
20 changes: 13 additions & 7 deletions src/Sylius/Bundle/ThemeBundle/Collector/ThemeCollector.php
Expand Up @@ -54,36 +54,42 @@ public function __construct(
$this->themeRepository = $themeRepository;
$this->themeContext = $themeContext;
$this->themeHierarchyProvider = $themeHierarchyProvider;

$this->data = [
'used_theme' => null,
'used_themes' => [],
'themes' => [],
];
}

/**
* @return ThemeInterface
* @return ThemeInterface|null
*/
public function getUsedTheme()
public function getUsedTheme(): ?ThemeInterface
{
return $this->data['used_theme'];
}

/**
* @return ThemeInterface[]
* @return array|ThemeInterface[]
*/
public function getUsedThemes()
public function getUsedThemes(): array
{
return $this->data['used_themes'];
}

/**
* @return ThemeInterface[]
*/
public function getThemes()
public function getThemes(): array
{
return $this->data['themes'];
}

/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, ?\Exception $exception = null): void
{
$this->data['used_theme'] = $this->themeContext->getTheme();
$this->data['used_themes'] = $this->themeHierarchyProvider->getThemeHierarchy($this->themeContext->getTheme());
Expand All @@ -93,7 +99,7 @@ public function collect(Request $request, Response $response, \Exception $except
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return 'sylius_theme';
}
Expand Down
Expand Up @@ -32,7 +32,7 @@ final class AssetsInstallCommand extends ContainerAwareCommand
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName('sylius:theme:assets:install')
Expand All @@ -51,7 +51,7 @@ protected function configure()
*
* @throws \InvalidArgumentException When the target directory does not exist or symlink cannot be used
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
$assetsInstaller = $this->getContainer()->get('sylius.theme.asset.assets_installer');
if ($assetsInstaller instanceof OutputAwareInterface) {
Expand All @@ -74,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
/**
* @return string
*/
private function getHelpMessage()
private function getHelpMessage(): string
{
return <<<EOT
The <info>%command.name%</info> command installs theme assets into a given
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Bundle/ThemeBundle/Command/ListCommand.php
Expand Up @@ -27,7 +27,7 @@ final class ListCommand extends ContainerAwareCommand
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName('sylius:theme:list')
Expand All @@ -38,7 +38,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
/** @var ThemeInterface[] $themes */
$themes = $this->getContainer()->get('sylius.repository.theme')->findAll();
Expand Down
Expand Up @@ -34,7 +34,7 @@ public function __construct(array $configurationProviders)
/**
* {@inheritdoc}
*/
public function getConfigurations()
public function getConfigurations(): array
{
$configurations = [];
foreach ($this->configurationProviders as $configurationProvider) {
Expand Down
Expand Up @@ -23,5 +23,5 @@ interface ConfigurationProcessorInterface
*
* @return array The processed configuration array
*/
public function process(array $configs);
public function process(array $configs): array;
}
Expand Up @@ -21,5 +21,5 @@ interface ConfigurationProviderInterface
/**
* @return array
*/
public function getConfigurations();
public function getConfigurations(): array;
}
Expand Up @@ -26,7 +26,7 @@ interface ConfigurationSourceFactoryInterface
/**
* @param ArrayNodeDefinition $node
*/
public function buildConfiguration(ArrayNodeDefinition $node);
public function buildConfiguration(ArrayNodeDefinition $node): void;

/**
* @see ConfigurationProviderInterface
Expand All @@ -41,5 +41,5 @@ public function initializeSource(ContainerBuilder $container, array $config);
/**
* @return string
*/
public function getName();
public function getName(): string;
}

0 comments on commit 03c4887

Please sign in to comment.