Skip to content

Commit

Permalink
modernize
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Feb 19, 2024
1 parent d997f63 commit 921c713
Show file tree
Hide file tree
Showing 34 changed files with 337 additions and 824 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
-----

* Support Symfony 6
* Use DateTimeInterface instead of DateTime.
* Adjust to doctrine and twig BC breaks. If you extended classes or customized services, check for old `Twig_*` classes or `Doctrine\Common\Persistence` namespace.
* Drop support for old Symfony versions
* Drop support for old PHP versions
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"symfony/security-core": "^6.4"
},
"require-dev": {
"ext-dom": "*",
"jackalope/jackalope-doctrine-dbal": "^1.3 || ^2.0",
"mockery/mockery": "^1.4.1",
"symfony-cmf/routing-bundle": "dev-sf7 as 3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/CmfCoreBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class CmfCoreBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new AddPublishedVotersPass());
}
Expand Down
21 changes: 6 additions & 15 deletions src/DependencyInjection/CmfCoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CmfCoreExtension extends Extension implements PrependExtensionInterface
*
* {@inheritdoc}
*/
public function prepend(ContainerBuilder $container)
public function prepend(ContainerBuilder $container): void
{
// process the configuration of CmfCoreExtension
$configs = $container->getExtensionConfig($this->getAlias());
Expand Down Expand Up @@ -243,10 +243,7 @@ public function prepend(ContainerBuilder $container)
}
}

/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$config = $this->processConfiguration(new Configuration(), $configs);

Expand Down Expand Up @@ -283,7 +280,7 @@ public function load(array $configs, ContainerBuilder $container)
/**
* Setup the cmf_core_checkbox_url_label form type if the routing bundle is there.
*/
public function setupFormTypes(ContainerBuilder $container, LoaderInterface $loader)
public function setupFormTypes(ContainerBuilder $container, LoaderInterface $loader): void
{
$bundles = $container->getParameter('kernel.bundles');
if (isset($bundles['CmfRoutingBundle'])) {
Expand All @@ -302,7 +299,7 @@ public function setupFormTypes(ContainerBuilder $container, LoaderInterface $loa
*
* @throws InvalidConfigurationException
*/
private function loadPublishWorkflow($config, XmlFileLoader $loader, ContainerBuilder $container)
private function loadPublishWorkflow($config, XmlFileLoader $loader, ContainerBuilder $container): void
{
$bundles = $container->getParameter('kernel.bundles');

Expand Down Expand Up @@ -336,18 +333,12 @@ private function loadPublishWorkflow($config, XmlFileLoader $loader, ContainerBu
}
}

/**
* {@inheritdoc}
*/
public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): bool|string
{
return __DIR__.'/../Resources/config/schema';
}

/**
* {@inheritdoc}
*/
public function getNamespace()
public function getNamespace(): string
{
return 'http://cmf.symfony.com/schema/dic/core';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AddPublishedVotersPass implements CompilerPassInterface
*
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('cmf_core.publish_workflow.access_decision_manager')) {
return;
Expand Down
5 changes: 1 addition & 4 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('cmf_core');
$rootNode = $treeBuilder->getRootNode();
Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/Phpcr/NonTranslatableMetadataListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class NonTranslatableMetadataListener implements EventSubscriber
/**
* @return array
*/
public function getSubscribedEvents()
public function getSubscribedEvents(): array
{
return [
'loadClassMetadata',
Expand All @@ -37,7 +37,7 @@ public function getSubscribedEvents()
* Handle the load class metadata event: remove translated attribute from
* fields and remove the locale mapping if present.
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
{
/** @var ClassMetadata $meta */
$meta = $eventArgs->getClassMetadata();
Expand Down
18 changes: 5 additions & 13 deletions src/Doctrine/Phpcr/TranslatableMetadataListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,15 @@
*/
class TranslatableMetadataListener implements EventSubscriber
{
/**
* @var string
*/
private $translationStrategy;

/**
* @param string $translationStrategy
*/
public function __construct($translationStrategy)
{
$this->translationStrategy = $translationStrategy;
public function __construct(
private string $translationStrategy
) {
}

/**
* @return array
*/
public function getSubscribedEvents()
public function getSubscribedEvents(): array
{
return [
'loadClassMetadata',
Expand All @@ -49,7 +41,7 @@ public function getSubscribedEvents()
/**
* Handle the load class metadata event: set the translation strategy.
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
{
/** @var ClassMetadata $meta */
$meta = $eventArgs->getClassMetadata();
Expand Down
40 changes: 10 additions & 30 deletions src/EventListener/PublishWorkflowListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,29 @@
*/
class PublishWorkflowListener implements EventSubscriberInterface
{
/**
* @var PublishWorkflowChecker
*/
protected $publishWorkflowChecker;

/**
* The attribute to check with the workflow checker, typically VIEW or VIEW_ANONYMOUS.
*
* @var string
*/
private $publishWorkflowPermission;

/**
* @param string $attribute the attribute name to check
*/
public function __construct(PublishWorkflowChecker $publishWorkflowChecker, $attribute = PublishWorkflowChecker::VIEW_ATTRIBUTE)
public function __construct(
private PublishWorkflowChecker $publishWorkflowChecker,
/**
* The attribute to check with the workflow checker, typically VIEW or VIEW_ANONYMOUS.
*/
private string $publishWorkflowPermission = PublishWorkflowChecker::VIEW_ATTRIBUTE)
{
$this->publishWorkflowChecker = $publishWorkflowChecker;
$this->publishWorkflowPermission = $attribute;
}

/**
* @return string
*/
public function getPublishWorkflowPermission()
public function getPublishWorkflowPermission(): string
{
return $this->publishWorkflowPermission;
}

/**
* @param string $attribute specify what permission to check, typically VIEW or VIEW_ANONYMOUS
*/
public function setPublishWorkflowPermission($attribute)
public function setPublishWorkflowPermission(string $attribute): void
{
$this->publishWorkflowPermission = $attribute;
}

/**
* Handling the request event.
*/
public function onKernelRequest(RequestEvent $event)
public function onKernelRequest(RequestEvent $event): void
{
$request = $event->getRequest();

Expand All @@ -83,10 +65,8 @@ public function onKernelRequest(RequestEvent $event)

/**
* We are only interested in request events.
*
* @return array
*/
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => [['onKernelRequest', 1]],
Expand Down
36 changes: 11 additions & 25 deletions src/Form/Type/CheckboxUrlLabelFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,60 +34,46 @@
*/
class CheckboxUrlLabelFormType extends AbstractType
{
/**
* @var RouterInterface
*/
protected $router;

public function __construct(RouterInterface $router)
{
$this->router = $router;
public function __construct(
private RouterInterface $router
) {
}

/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
public function buildView(FormView $view, FormInterface $form, array $options): void
{
$routes = $options['routes'];
$paths = [];
foreach ($routes as $key => $route) {
$name = isset($route['name']) ? $route['name'] : '';
$parameters = isset($route['parameters']) ? $route['parameters'] : [];
$referenceType = isset($route['referenceType']) ? $route['referenceType'] : UrlGeneratorInterface::ABSOLUTE_PATH;
$name = $route['name'] ?? '';
$parameters = $route['parameters'] ?? [];
$referenceType = $route['referenceType'] ?? UrlGeneratorInterface::ABSOLUTE_PATH;
$paths[$key] = $this->router->generate($name, $parameters, $referenceType);
}
$view->vars['paths'] = $paths;
parent::buildView($view, $form, $options);
}

public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'routes' => [],
]);
}

/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return $this->getBlockPrefix();
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'cmf_core_checkbox_url_label';
}

/**
* {@inheritdoc}
*/
public function getParent()
public function getParent(): ?string
{
return CheckboxType::class;
}
Expand Down
10 changes: 2 additions & 8 deletions src/Model/ChildInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@
*/
interface ChildInterface
{
/**
* @param $parent object
*/
public function setParentObject($parent);
public function setParentObject(object $parent);

/**
* @return object
*/
public function getParentObject();
public function getParentObject(): object;
}
2 changes: 1 addition & 1 deletion src/PublishWorkflow/AlwaysPublishedWorkflowChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AlwaysPublishedWorkflowChecker implements AuthorizationCheckerInterface
/**
* {@inheritdoc}
*/
public function isGranted($attributes, $object = null)
public function isGranted(mixed $attribute, mixed $subject = null): bool
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/PublishWorkflow/PublishTimePeriodInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface PublishTimePeriodInterface extends PublishTimePeriodReadInterface
* Setting a NULL value asserts that the content
* has always been publishable.
*/
public function setPublishStartDate(\DateTime $publishDate = null);
public function setPublishStartDate(\DateTimeInterface $publishDate = null): void;

/**
* Set the date at which the content should
Expand All @@ -32,5 +32,5 @@ public function setPublishStartDate(\DateTime $publishDate = null);
* Setting a NULL value asserts that the
* content will always be publishable.
*/
public function setPublishEndDate(\DateTime $publishDate = null);
public function setPublishEndDate(\DateTimeInterface $publishDate = null): void;
}
8 changes: 2 additions & 6 deletions src/PublishWorkflow/PublishTimePeriodReadInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@ interface PublishTimePeriodReadInterface
*
* A NULL value is interpreted as a date in the past, meaning the content
* is publishable unless publish end date is set and in the past.
*
* @return \DateTime|null
*/
public function getPublishStartDate();
public function getPublishStartDate(): ?\DateTimeInterface;

/**
* Return the date at which the content should stop being published.
*
* A NULL value is interpreted as saying that the document will
* never end being publishable.
*
* @return \DateTime|null
*/
public function getPublishEndDate();
public function getPublishEndDate(): ?\DateTimeInterface;
}
Loading

0 comments on commit 921c713

Please sign in to comment.