From 93d05471dca88ad29e2405d44771f1b2b1dcfe76 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Fri, 6 May 2022 11:50:19 +0000 Subject: [PATCH] A bit of spring cleaning --- .editorconfig | 16 ----------- .gitignore | 8 ------ .php_cs.dist | 27 +++++++++++++++++++ README.md | 10 +++---- composer.json | 2 +- src/Command/ListSynchronizersCommand.php | 11 +------- src/Command/SynchronizeCommand.php | 23 +++++----------- .../Compiler/RegisterSynchronizerPass.php | 9 +++---- .../WebfactoryContentMappingExtension.php | 16 ++++------- src/Synchronizer/Registry.php | 24 +++++------------ src/WebfactoryContentMappingBundle.php | 11 ++------ 11 files changed, 58 insertions(+), 99 deletions(-) delete mode 100644 .editorconfig create mode 100644 .php_cs.dist diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index c6584db..0000000 --- a/.editorconfig +++ /dev/null @@ -1,16 +0,0 @@ -# http://editorconfig.org -# -# This plugin actives .editorconfig support in PHPStorm: -# https://plugins.jetbrains.com/plugin/7294 -# The plugin simplifies the management of different formatting rules per project and file type. -root = true - -[*] -indent_style = space -indent_size = 4 -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.md] -trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore index ff87182..d8a7996 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,2 @@ -### Composer -composer.phar composer.lock vendor/ - -### Node -node_modules/ - -### PHPStorm -.idea/ diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..014cbc3 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,27 @@ +setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + 'array_syntax' => array('syntax' => 'short'), + 'no_unreachable_default_argument_value' => false, + 'braces' => array('allow_single_line_closure' => true), + 'heredoc_to_nowdoc' => false, + 'phpdoc_annotation_without_dot' => false, + 'php_unit_test_annotation' => ['style' => 'annotation'], + 'php_unit_method_casing' => false, + 'psr_autoloading' => false, + ]) + ->setRiskyAllowed(true) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__) + ->notPath('conf/') + ->notPath('tmp/') + ->notPath('node_modules/') + ->notPath('var/cache') + ->notPath('vendor/') + ->notPath('www') + ) +; diff --git a/README.md b/README.md index 8b93a13..790442b 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# content-mapping-bundle # +# content-mapping-bundle Symfony bundle for [webfactory/content-mapping](https://github.com/webfactory/content-mapping). If you configure your Synchronizers as services, you can use the provided console commands to list and start them. This is useful e.g. for cronjobs. -## Installation ## +## Installation Install the package via composer @@ -26,7 +26,7 @@ public function registerBundles() ``` -## Usage ## +## Usage First, register your Synchronizers as a service, e.g. in your services.xml: @@ -79,11 +79,11 @@ the destination systems even if no changes are detected. Be aware that `objectcl you'd like to synchronize, but the value you defined in the service definition (see above). -## Credits, Copyright and License ## +## Credits, Copyright and License This project was started at webfactory GmbH, Bonn. - - -Copyright 2015-2018 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE). +Copyright 2015-2022 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE). diff --git a/composer.json b/composer.json index 6a277be..2b213b3 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { - "php": "7.2.*|7.4.*", + "php": "7.2.*|7.4.*|8.0.*|8.1.*", "symfony/config": "^2.4|^3.0|^4.0|^5.0", "symfony/console": "^2.4|^3.0|^4.0|^5.0", "symfony/dependency-injection": "^2.4|^3.0|^4.0|^5.0", diff --git a/src/Command/ListSynchronizersCommand.php b/src/Command/ListSynchronizersCommand.php index cc4f131..172c2e6 100644 --- a/src/Command/ListSynchronizersCommand.php +++ b/src/Command/ListSynchronizersCommand.php @@ -17,27 +17,18 @@ class ListSynchronizersCommand extends Command */ private $synchronizerRegistry; - /** - * @param Registry $synchronizerRegistry - */ public function __construct(Registry $synchronizerRegistry) { parent::__construct(); $this->synchronizerRegistry = $synchronizerRegistry; } - /** - * {@inheritDoc} - */ - protected function configure() + protected function configure(): void { $this->setName('content-mapping:list-synchronizers') ->setDescription('Lists the available synchronizers'); } - /** - * {@inheritDoc} - */ protected function execute(InputInterface $input, OutputInterface $output): int { foreach ($this->synchronizerRegistry->getObjectclasses() as $objectclass) { diff --git a/src/Command/SynchronizeCommand.php b/src/Command/SynchronizeCommand.php index 1712d48..c1b43bc 100644 --- a/src/Command/SynchronizeCommand.php +++ b/src/Command/SynchronizeCommand.php @@ -3,10 +3,11 @@ namespace Webfactory\ContentMappingBundle\Command; use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; use Webfactory\ContentMappingBundle\Synchronizer\Registry; /** @@ -24,21 +25,14 @@ final class SynchronizeCommand extends Command */ private $logger; - /** - * @param Registry $synchronizerRegistry - * @param LoggerInterface $logger - */ - public function __construct(Registry $synchronizerRegistry, LoggerInterface $logger) + public function __construct(Registry $synchronizerRegistry, LoggerInterface $logger = null) { parent::__construct(); $this->synchronizerRegistry = $synchronizerRegistry; - $this->logger = $logger; + $this->logger = $logger ?? new NullLogger(); } - /** - * {@inheritDoc} - */ - protected function configure() + protected function configure(): void { $this->setName('content-mapping:synchronize') ->setDescription('Starts the synchronizer(s).'); @@ -56,21 +50,18 @@ protected function configure() ); } - /** - * {@inheritDoc} - */ protected function execute(InputInterface $input, OutputInterface $output): int { $force = $input->getOption('force'); $only = $input->getOption('only'); foreach ($this->synchronizerRegistry->getObjectclasses() as $objectclass) { - if ($only && !in_array($objectclass, $only)) { + if ($only && !\in_array($objectclass, $only)) { $this->logger->debug("Skipping Synchronizer for object class $objectclass"); continue; } - $this->logger->debug('Use Synchronizer for object class ' . $objectclass); + $this->logger->debug('Use Synchronizer for object class '.$objectclass); $this->synchronizerRegistry->getSynchronizer($objectclass) ->synchronize($objectclass, $force); diff --git a/src/DependencyInjection/Compiler/RegisterSynchronizerPass.php b/src/DependencyInjection/Compiler/RegisterSynchronizerPass.php index bb918af..f6efe8b 100644 --- a/src/DependencyInjection/Compiler/RegisterSynchronizerPass.php +++ b/src/DependencyInjection/Compiler/RegisterSynchronizerPass.php @@ -8,18 +8,15 @@ namespace Webfactory\ContentMappingBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; /** * Fills the Synchronizer\Registry with services tagged as "contentmapping.synchronizer". */ final class RegisterSynchronizerPass implements CompilerPassInterface { - /** - * {@inheritDoc} - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $definition = $container->getDefinition('contentmapping.synchronizer_registry'); @@ -29,7 +26,7 @@ public function process(ContainerBuilder $container) throw new \Exception('The contentmapping.synchronizer tag requires the objectclass attribute.'); } - $definition->addMethodCall('addSynchronizer', array($tag['objectclass'], $id)); + $definition->addMethodCall('addSynchronizer', [$tag['objectclass'], $id]); // Prevents Symfony from optimizing these services away if they're anonymous $container->getDefinition($id)->setPublic(true); diff --git a/src/DependencyInjection/WebfactoryContentMappingExtension.php b/src/DependencyInjection/WebfactoryContentMappingExtension.php index 41aa803..90f15af 100644 --- a/src/DependencyInjection/WebfactoryContentMappingExtension.php +++ b/src/DependencyInjection/WebfactoryContentMappingExtension.php @@ -8,22 +8,16 @@ namespace Webfactory\ContentMappingBundle\DependencyInjection; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\Extension; +use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -/** - * Symfony dependency injection extension. - */ class WebfactoryContentMappingExtension 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 = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.xml'); } } diff --git a/src/Synchronizer/Registry.php b/src/Synchronizer/Registry.php index dc6af04..c29e9b2 100644 --- a/src/Synchronizer/Registry.php +++ b/src/Synchronizer/Registry.php @@ -27,21 +27,14 @@ final class Registry /** * @var array(string objectClass => string serviceId) */ - private $services = array(); + private $services = []; - /** - * @param ContainerInterface $container - */ public function __construct(ContainerInterface $container) { $this->container = $container; } - /** - * @param string $objectclass - * @param string $serviceId - */ - public function addSynchronizer($objectclass, $serviceId) + public function addSynchronizer(string $objectclass, string $serviceId) { $this->services[$objectclass] = $serviceId; } @@ -49,22 +42,19 @@ public function addSynchronizer($objectclass, $serviceId) /** * @return string[] */ - public function getObjectclasses() + public function getObjectclasses(): array { return array_keys($this->services); } - /** - * @param string $objectclass The objectclass to retrieve the Synchronizer for. - * @return Synchronizer - */ - public function getSynchronizer($objectclass) + public function getSynchronizer(string $objectclass): Synchronizer { - if (array_key_exists($objectclass, $this->services) === false) { - throw new \RuntimeException('No Synchronizer for objectclass "' . $objectclass . '" configured.'); + if (false === \array_key_exists($objectclass, $this->services)) { + throw new \RuntimeException('No Synchronizer for objectclass "'.$objectclass.'" configured.'); } $serviceId = $this->services[$objectclass]; + return $this->container->get($serviceId); } } diff --git a/src/WebfactoryContentMappingBundle.php b/src/WebfactoryContentMappingBundle.php index 7327ce4..a40707e 100644 --- a/src/WebfactoryContentMappingBundle.php +++ b/src/WebfactoryContentMappingBundle.php @@ -8,21 +8,14 @@ namespace Webfactory\ContentMappingBundle; -use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\Bundle\Bundle; use Webfactory\ContentMappingBundle\DependencyInjection\Compiler\RegisterSynchronizerPass; -/** - * Symfony Bundle class. - */ class WebfactoryContentMappingBundle extends Bundle { - /** - * {@inheritDoc} - */ - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { - parent::build($container); $container->addCompilerPass(new RegisterSynchronizerPass()); } }