Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ php:
- 7.3

env:
- SYMFONY_VERSION=3.4.*
- SYMFONY_VERSION=4.3.*
- SYMFONY_VERSION=4.4.*

cache:
directories:
Expand All @@ -21,6 +20,7 @@ install:
symfony/asset:${SYMFONY_VERSION} \
symfony/config:${SYMFONY_VERSION} \
symfony/console:${SYMFONY_VERSION} \
symfony/dom-crawler:${SYMFONY_VERSION} \
symfony/dependency-injection:${SYMFONY_VERSION} \
symfony/filesystem:${SYMFONY_VERSION} \
symfony/finder:${SYMFONY_VERSION} \
Expand Down
53 changes: 25 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,39 @@
"php": "^7.2",

"doctrine/common": "^2.5",
"symfony/asset": "^3.4|^4.3",
"symfony/config": "^3.4|^4.3",
"symfony/console": "^3.4|^4.3",
"symfony/translation-contracts": "^1.0",
"symfony/dependency-injection": "^3.4|^4.3",
"symfony/filesystem": "^3.4|^4.3",
"symfony/finder": "^3.4|^4.3",
"symfony/form": "^3.4|^4.3",
"symfony/framework-bundle": "^3.4|^4.3",
"symfony/http-foundation": "^3.4|^4.3",
"symfony/http-kernel": "^3.4|^4.3",
"symfony/options-resolver": "^3.4|^4.3",
"symfony/templating": "^3.4|^4.3",
"symfony/translation": "^3.4|^4.3",
"symfony/asset": "^4.4",
"symfony/config": "^4.4",
"symfony/console": "^4.4",
"symfony/dom-crawler": "^4.4",
"symfony/translation-contracts": "^1.1|^2.0",
"symfony/dependency-injection": "^4.4",
"symfony/filesystem": "^4.4",
"symfony/finder": "^4.4",
"symfony/form": "^4.4",
"symfony/framework-bundle": "^4.4",
"symfony/http-foundation": "^4.4",
"symfony/http-kernel": "^4.4",
"symfony/options-resolver": "^4.4",
"symfony/templating": "^4.4",
"symfony/translation": "^4.4",
"zendframework/zend-hydrator": "^2.2"
},
"require-dev": {
"matthiasnoback/symfony-config-test": "^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^3.0",
"matthiasnoback/symfony-config-test": "^4.1",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"mikey179/vfsstream": "^1.6",
"phpspec/phpspec": "^5.0",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-phpunit": "^0.11",
"phpstan/phpstan-webmozart-assert": "^0.11",
"phpunit/phpunit": "^7.0",
"proget-hq/phpstan-phpspec": "^0.2",
"phpspec/phpspec": "^6.1",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-webmozart-assert": "^0.12",
"phpunit/phpunit": "^8.5",
"sylius-labs/coding-standard": "^3.0",
"symfony/browser-kit": "^3.4|^4.3",
"symfony/security-csrf": "^3.4|^4.3",
"symfony/twig-bundle": "^3.4|^4.3",
"symfony/browser-kit": "^4.4",
"symfony/security-csrf": "^4.4",
"symfony/twig-bundle": "^4.4",
"twig/twig": "^2.0",
"vimeo/psalm": "^3.5"
},
"conflict": {
"twig/twig": "^1.0"
},
"autoload": {
"psr-4": {
"Sylius\\Bundle\\ThemeBundle\\": "src/"
Expand Down
21 changes: 10 additions & 11 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
includes:
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/proget-hq/phpstan-phpspec/extension.neon

- vendor/phpstan/phpstan-phpunit/rules.neon

parameters:
checkMissingIterableValueType: false
reportUnmatchedIgnoredErrors: false

specDir: 'spec/'
treatPhpDocTypesAsCertain: false

excludes_analyse:
- %currentWorkingDirectory%/tests/Application/var/*
# Test dependencies
- %currentWorkingDirectory%/spec/
- %currentWorkingDirectory%/tests/Application/var/

ignoreErrors:
# PHPStan integration
- '/Call to an undefined method Prophecy\\Prophecy\\MethodProphecy::getRealPath\(\)/'

# Symfony 3.4 support
- '/Method Symfony\\Component\\HttpKernel\\KernelInterface::getBundle\(\) invoked with 2 parameters, 1 required/'
- '/Method Symfony\\Component\\HttpKernel\\KernelInterface::getBundle\(\) invoked with 2 parameters, 0-1 required/'
- '/Call to function method_exists\(\) with .Symfony\\\\Component…. and .getRootNode. will always evaluate to false/'
- '/Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::getRootNode\(\)/'
- '/Class Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder does not have a constructor and must be instantiated without any parameters/'

# Symfony caveats
- '/Parameter \#1 \$name of method Symfony\\Component\\Config\\FileLocatorInterface::locate\(\) expects string, Symfony\\Component\\Templating\\TemplateReferenceInterface given/'
- '/Parameter \#1 \$translator of class Symfony\\Component\\Translation\\Formatter\\MessageFormatter constructor expects Symfony\\Contracts\\Translation\\TranslatorInterface|null, Symfony\\Component\\Translation\\MessageSelector given/'

# Symfony passes TemplateReference object instead of a string
- "/Casting to string something that\\'s already string./"
- '/Parameter \#1 \$name of method Twig\\Loader\\LoaderInterface::[A-Za-z]+\(\) expects string, string\|Symfony\\Component\\Templating\\TemplateReference given\./'

- '/Method Sylius\\Bundle\\ThemeBundle\\Filesystem\\FilesystemInterface::[A-Za-z]+\(\) has no return typehint specified./'
- '/Method Sylius\\Bundle\\ThemeBundle\\Translation\\ThemeAwareTranslator::__call\(\) has no return typehint specified./'
- '/Method Sylius\\Bundle\\ThemeBundle\\Translation\\ThemeAwareTranslator::trans\(\) has parameter \$[A-Za-z]+ with no typehint specified./'
- '/Method Sylius\\Bundle\\ThemeBundle\\Templating\\Locator\\TemplateFileLocator::unserialize\(\) has parameter \$serialized with no typehint specified./'
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

<InvalidArgument>
<errorLevel type="suppress">
<referencedFunction name="Symfony\Component\Config\FileLocatorInterface::locate" />
<referencedFunction name="Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch" />
</errorLevel>
</InvalidArgument>
Expand Down
35 changes: 6 additions & 29 deletions spec/Locator/BundleResourceLocatorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,13 @@ function it_implements_resource_locator_interface(): void
$this->shouldImplement(ResourceLocatorInterface::class);
}

function it_locates_bundle_resource_using_path_derived_from_bundle_notation_and_symfony3_kernel_behaviour(
Filesystem $filesystem,
KernelInterface $kernel,
ThemeInterface $theme,
BundleInterface $childBundle,
BundleInterface $parentBundle
): void {
$kernel->getBundle('ParentBundle', false)->willReturn([$childBundle, $parentBundle]);

$childBundle->getName()->willReturn('ChildBundle');
$parentBundle->getName()->willReturn('ParentBundle');

$theme->getPath()->willReturn('/theme/path');

$filesystem->exists('/theme/path/ChildBundle/views/Directory/index.html.twig')->shouldBeCalled()->willReturn(false);
$filesystem->exists('/theme/path/ParentBundle/views/Directory/index.html.twig')->shouldBeCalled()->willReturn(true);

$this->locateResource('@ParentBundle/Resources/views/Directory/index.html.twig', $theme)->shouldReturn('/theme/path/ParentBundle/views/Directory/index.html.twig');
}

function it_locates_bundle_resource_using_path_derived_from_bundle_notation_and_symfony4_kernel_behaviour(
Filesystem $filesystem,
KernelInterface $kernel,
ThemeInterface $theme,
BundleInterface $justBundle
): void {
$kernel->getBundle('JustBundle', false)->willReturn($justBundle);
$kernel->getBundle('JustBundle')->willReturn($justBundle);

$justBundle->getName()->willReturn('JustBundle');

Expand All @@ -74,21 +54,18 @@ function it_throws_an_exception_if_resource_can_not_be_located_using_path_derive
Filesystem $filesystem,
KernelInterface $kernel,
ThemeInterface $theme,
BundleInterface $childBundle,
BundleInterface $parentBundle
BundleInterface $bundle
): void {
$kernel->getBundle('ParentBundle', false)->willReturn([$childBundle, $parentBundle]);
$kernel->getBundle('Bundle')->willReturn( $bundle);

$childBundle->getName()->willReturn('ChildBundle');
$parentBundle->getName()->willReturn('ParentBundle');
$bundle->getName()->willReturn('Bundle');

$theme->getName()->willReturn('theme/name');
$theme->getPath()->willReturn('/theme/path');

$filesystem->exists('/theme/path/ChildBundle/views/Directory/index.html.twig')->shouldBeCalled()->willReturn(false);
$filesystem->exists('/theme/path/ParentBundle/views/Directory/index.html.twig')->shouldBeCalled()->willReturn(false);
$filesystem->exists('/theme/path/Bundle/views/Directory/index.html.twig')->shouldBeCalled()->willReturn(false);

$this->shouldThrow(ResourceNotFoundException::class)->during('locateResource', ['@ParentBundle/Resources/views/Directory/index.html.twig', $theme]);
$this->shouldThrow(ResourceNotFoundException::class)->during('locateResource', ['@Bundle/Resources/views/Directory/index.html.twig', $theme]);
}

function it_locates_bundle_resource_using_path_derived_from_twig_namespaces(
Expand Down
2 changes: 0 additions & 2 deletions src/Asset/Installer/AssetsInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\KernelInterface;

Expand Down Expand Up @@ -110,7 +109,6 @@ private function installThemedBundleAssets(ThemeInterface $theme, string $origin
$finder = new Finder();
$finder->sortByName()->ignoreDotFiles(false)->in($originDir);

/** @var SplFileInfo[] $finder */
foreach ($finder as $originFile) {
$targetFile = $targetDir . '/' . $originFile->getRelativePathname();
$targetFile = $this->pathResolver->resolve($targetFile, $theme);
Expand Down
3 changes: 0 additions & 3 deletions src/Asset/Package/PathPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public function __construct(
$this->pathResolver = $pathResolver;
}

/**
* {@inheritdoc}
*/
public function getUrl($path): string
{
if ($this->isAbsoluteUrl($path)) {
Expand Down
3 changes: 0 additions & 3 deletions src/Asset/Package/UrlPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ public function __construct(
$this->pathResolver = $pathResolver;
}

/**
* {@inheritdoc}
*/
public function getUrl($path): string
{
if ($this->isAbsoluteUrl($path)) {
Expand Down
35 changes: 13 additions & 22 deletions src/Configuration/ThemeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,19 @@ final class ThemeConfiguration implements ConfigurationInterface
*/
public function getConfigTreeBuilder(): TreeBuilder
{
if (method_exists(TreeBuilder::class, 'getRootNode')) {
$treeBuilder = new TreeBuilder('sylius_theme');

/** @var ArrayNodeDefinition $rootNodeDefinition */
$rootNodeDefinition = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$treeBuilder = new TreeBuilder();

/** @var ArrayNodeDefinition $rootNodeDefinition */
$rootNodeDefinition = $treeBuilder->root('sylius_theme');
}

$rootNodeDefinition->ignoreExtraKeys();

$this->addRequiredNameField($rootNodeDefinition);
$this->addOptionalTitleField($rootNodeDefinition);
$this->addOptionalDescriptionField($rootNodeDefinition);
$this->addOptionalPathField($rootNodeDefinition);
$this->addOptionalParentsList($rootNodeDefinition);
$this->addOptionalScreenshotsList($rootNodeDefinition);
$this->addOptionalAuthorsList($rootNodeDefinition);
$treeBuilder = new TreeBuilder('sylius_theme');
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();

$rootNode->ignoreExtraKeys();

$this->addRequiredNameField($rootNode);
$this->addOptionalTitleField($rootNode);
$this->addOptionalDescriptionField($rootNode);
$this->addOptionalPathField($rootNode);
$this->addOptionalParentsList($rootNode);
$this->addOptionalScreenshotsList($rootNode);
$this->addOptionalAuthorsList($rootNode);

return $treeBuilder;
}
Expand Down
25 changes: 8 additions & 17 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,16 @@ public function __construct(array $configurationSourceFactories = [])
*/
public function getConfigTreeBuilder(): TreeBuilder
{
if (method_exists(TreeBuilder::class, 'getRootNode')) {
$treeBuilder = new TreeBuilder('sylius_theme');
$treeBuilder = new TreeBuilder('sylius_theme');
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();

/** @var ArrayNodeDefinition $rootNodeDefinition */
$rootNodeDefinition = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$treeBuilder = new TreeBuilder();
$this->addSourcesConfiguration($rootNode);

/** @var ArrayNodeDefinition $rootNodeDefinition */
$rootNodeDefinition = $treeBuilder->root('sylius_theme');
}

$this->addSourcesConfiguration($rootNodeDefinition);

$rootNodeDefinition->children()->arrayNode('assets')->canBeDisabled();
$rootNodeDefinition->children()->arrayNode('templating')->canBeDisabled();
$rootNodeDefinition->children()->arrayNode('translations')->canBeDisabled();
$rootNodeDefinition->children()->scalarNode('context')->defaultValue('sylius.theme.context.settable')->cannotBeEmpty();
$rootNode->children()->arrayNode('assets')->canBeDisabled();
$rootNode->children()->arrayNode('templating')->canBeDisabled();
$rootNode->children()->arrayNode('translations')->canBeDisabled();
$rootNode->children()->scalarNode('context')->defaultValue('sylius.theme.context.settable')->cannotBeEmpty();

return $treeBuilder;
}
Expand Down
1 change: 0 additions & 1 deletion src/Loader/ThemeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ private function initializeThemes(array $configurations): array
{
$themes = [];
foreach ($configurations as $configuration) {
/** @var ThemeInterface $theme */
$themes[$configuration['name']] = $this->themeFactory->create($configuration['name'], $configuration['path']);
}

Expand Down
21 changes: 5 additions & 16 deletions src/Locator/BundleResourceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public function __construct(Filesystem $filesystem, KernelInterface $kernel)
$this->kernel = $kernel;
}

/**
* {@inheritdoc}
*/
public function locateResource(string $resourcePath, ThemeInterface $theme): string
{
$this->assertResourcePathIsValid($resourcePath);
Expand Down Expand Up @@ -64,21 +61,13 @@ private function locateResourceBasedOnBundleNotation(string $resourcePath, Theme
$bundleName = substr($resourcePath, 1, (int) strpos($resourcePath, '/') - 1);
$resourceName = substr($resourcePath, (int) strpos($resourcePath, 'Resources/') + strlen('Resources/'));

// Symfony 4.0+ always returns a single bundle
/** @var BundleInterface|BundleInterface[] $bundles */
$bundles = $this->kernel->getBundle($bundleName, false);
/** @var BundleInterface $bundle */
$bundle = $this->kernel->getBundle($bundleName);

// So we need to hack it to support both Symfony 3.4 and Symfony 4.0+
if (!is_array($bundles)) {
$bundles = [$bundles];
}

foreach ($bundles as $bundle) {
$path = sprintf('%s/%s/%s', $theme->getPath(), $bundle->getName(), $resourceName);
$path = sprintf('%s/%s/%s', $theme->getPath(), $bundle->getName(), $resourceName);

if ($this->filesystem->exists($path)) {
return $path;
}
if ($this->filesystem->exists($path)) {
return $path;
}

throw new ResourceNotFoundException($resourcePath, $theme);
Expand Down
1 change: 1 addition & 0 deletions src/Twig/ThemeFilesystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function getCacheKey($name): string

/**
* @param string|TemplateReference $name
* @param int $time
*/
public function isFresh($name, $time): bool
{
Expand Down
8 changes: 1 addition & 7 deletions tests/Application/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

final class Kernel extends HttpKernel
{
/**
* {@inheritdoc}
*/
public function registerBundles()
{
return [
Expand All @@ -31,10 +28,7 @@ public function registerBundles()
];
}

/**
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader)
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__ . '/config/config.yml');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@

final class TestExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
Expand Down
Loading