Skip to content

Commit 9a7e6f7

Browse files
committed
Fix deprecations, update to PHP 8.1 and supported deprecations versions
1 parent 3c4c3fe commit 9a7e6f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+525
-937
lines changed

AdmingeneratorFormExtensionsBundle.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
class AdmingeneratorFormExtensionsBundle extends Bundle
1515
{
16-
public function build(ContainerBuilder $container)
16+
public function build(ContainerBuilder $container): void
1717
{
1818
parent::build($container);
1919

DependencyInjection/AdmingeneratorFormExtensionsExtension.php

+9-19
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AdmingeneratorFormExtensionsExtension extends Extension
3030
/**
3131
* {@inheritDoc}
3232
*/
33-
public function load(array $configs, ContainerBuilder $container)
33+
public function load(array $configs, ContainerBuilder $container): void
3434
{
3535
$configuration = new Configuration();
3636
$config = $this->processConfiguration($configuration, $configs);
@@ -58,11 +58,9 @@ public function load(array $configs, ContainerBuilder $container)
5858

5959
/**
6060
* Register the form extensions if required
61-
*
62-
* @param array $config
63-
* @param ContainerBuilder $container
6461
*/
65-
private function configureFormExtensions(array $config, ContainerBuilder $container) {
62+
private function configureFormExtensions(array $config, ContainerBuilder $container): void
63+
{
6664
if ($config['autocomplete']) {
6765
$this->registerExtension($container, 'form.type_extension.autocomplete', AutocompleteExtension::class);
6866
}
@@ -82,12 +80,8 @@ private function configureFormExtensions(array $config, ContainerBuilder $contai
8280

8381
/**
8482
* Add the collection upload listener if required
85-
*
86-
* @param array $config
87-
* @param ContainerBuilder $container
88-
* @throws \LogicException
8983
*/
90-
private function loadUploadCollectionListener(array $config, ContainerBuilder $container)
84+
private function loadUploadCollectionListener(array $config, ContainerBuilder $container): void
9185
{
9286
if ($config['async_listener_enabled']) {
9387
if (!(array_key_exists('async_route_name', $config) && $routeName = $config['async_route_name'])) {
@@ -107,12 +101,6 @@ private function loadUploadCollectionListener(array $config, ContainerBuilder $c
107101
}
108102
}
109103

110-
/**
111-
* @param ContainerBuilder $container
112-
* @param string $serviceId
113-
* @param string $extensionClass
114-
* @param string $extendedTypeClass
115-
*/
116104
private function registerExtension(ContainerBuilder $container, string $serviceId, string $extensionClass, string $extendedTypeClass = FormType::class): void
117105
{
118106
$extensionDefinition = new Definition($extensionClass);
@@ -122,7 +110,8 @@ private function registerExtension(ContainerBuilder $container, string $serviceI
122110
$container->setDefinition($serviceId, $extensionDefinition);
123111
}
124112

125-
private function configureAssetsExtension(ContainerBuilder $container, string $uploadManager, string $imageManipulator) {
113+
private function configureAssetsExtension(ContainerBuilder $container, string $uploadManager, string $imageManipulator): void
114+
{
126115
$uploaderHelperDefinition = null;
127116
$imageExtensionDefinition = null;
128117
if ('vich_uploader' === $uploadManager) {
@@ -149,8 +138,9 @@ private function configureAssetsExtension(ContainerBuilder $container, string $u
149138
$container->setDefinition('admingenerator.twig.extension.image_assets', $assetsExtensionDefinition);
150139
}
151140

152-
private function loadGlobalsExtension(ContainerBuilder $container) {
153-
$globalsExtensionDefinition = Environment::MAJOR_VERSION > 2 ? new Definition(IncludeGlobalsExtension::class) : new Definition(LegacyIncludeGlobalsExtension::class);
141+
private function loadGlobalsExtension(ContainerBuilder $container): void
142+
{
143+
$globalsExtensionDefinition = new Definition(IncludeGlobalsExtension::class);
154144
$globalsExtensionDefinition->setArgument('$container', new Reference('service_container'));
155145
$globalsExtensionDefinition->addTag('twig.extension');
156146
$container->setDefinition('admingenerator.twig.extension.include_globals', $globalsExtensionDefinition);

DependencyInjection/Compiler/FormCompilerPass.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
*/
1414
class FormCompilerPass implements CompilerPassInterface
1515
{
16-
/**
17-
* {@inheritdoc}
18-
*/
19-
public function process(ContainerBuilder $container)
16+
public function process(ContainerBuilder $container): void
2017
{
2118
// Used templates
2219
$templates = ['@AdmingeneratorFormExtensions/Form/form_html.html.twig',

DependencyInjection/Configuration.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,11 @@
1212
*/
1313
class Configuration implements ConfigurationInterface
1414
{
15-
/**
16-
* {@inheritDoc}
17-
*/
18-
public function getConfigTreeBuilder()
15+
public function getConfigTreeBuilder(): TreeBuilder
1916
{
2017
$treeBuilder = new TreeBuilder('admingenerator_form_extensions');
21-
$rootNode = method_exists(TreeBuilder::class, 'getRootNode')
22-
? $treeBuilder->getRootNode()
23-
: $treeBuilder->root('admingenerator_form_extensions');
2418

25-
$rootNode
19+
$treeBuilder->getRootNode()
2620
->children()
2721
->scalarNode('upload_manager')->defaultNull()->end()
2822
->scalarNode('image_manipulator')->defaultNull()->end()

EventListener/UploadCollectionListener.php

+14-48
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use Admingenerator\FormExtensionsBundle\Storage\FileStorageInterface;
55
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6+
use Symfony\Component\HttpKernel\Event\RequestEvent;
67
use Symfony\Component\HttpKernel\KernelEvents;
78
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
89
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -11,47 +12,20 @@
1112

1213
class UploadCollectionListener implements EventSubscriberInterface
1314
{
14-
/**
15-
* (non-PHPdoc)
16-
* @see \Symfony\Component\EventDispatcher\EventSubscriberInterface::getSubscribedEvents()
17-
*/
18-
public static function getSubscribedEvents()
15+
public static function getSubscribedEvents(): array
1916
{
20-
return array(KernelEvents::REQUEST => 'onRequestHandler');
17+
return [KernelEvents::REQUEST => 'onRequestHandler'];
2118
}
2219

23-
/**
24-
* @var FileStorageInterface
25-
*/
26-
protected $storage;
27-
28-
/**
29-
* @var string
30-
*/
31-
protected $routeName;
32-
33-
/**
34-
* @var PropertyAccessorInterface
35-
*/
36-
protected $propertyAccessor;
37-
38-
/**
39-
* @param FileStorageInterface $storage
40-
* @param string $routeName
41-
* @param PropertyAccessorInterface $propertyAccessor
42-
*/
43-
public function __construct(FileStorageInterface $storage, $routeName, PropertyAccessorInterface $propertyAccessor)
20+
public function __construct(
21+
protected readonly FileStorageInterface $storage,
22+
protected readonly string $routeName,
23+
protected readonly PropertyAccessorInterface $propertyAccessor
24+
)
4425
{
45-
$this->storage = $storage;
46-
$this->routeName = $routeName;
47-
$this->propertyAccessor = $propertyAccessor;
4826
}
4927

50-
/**
51-
* @param GetResponseEvent $event
52-
* @return GetResponseEvent
53-
*/
54-
public function onRequestHandler(GetResponseEvent $event)
28+
public function onRequestHandler(RequestEvent $event): RequestEvent
5529
{
5630
$request = $event->getRequest();
5731

@@ -73,11 +47,7 @@ public function onRequestHandler(GetResponseEvent $event)
7347
return $event;
7448
}
7549

76-
/**
77-
* @param string $propertyPath
78-
* @return string
79-
*/
80-
private function fixPropertyPath($propertyPath)
50+
private function fixPropertyPath(string $propertyPath): string
8151
{
8252
if ($propertyPath[0] != '[') {
8353
$propertyPath = '[' . substr_replace($propertyPath, ']', strpos($propertyPath, '[')?:strlen($propertyPath), 0);
@@ -86,15 +56,11 @@ private function fixPropertyPath($propertyPath)
8656
return str_replace('[]', '', $propertyPath);
8757
}
8858

89-
/**
90-
* @param array $files
91-
* @return \stdClass
92-
*/
93-
private function formatResponse(array $files)
59+
private function formatResponse(array $files): \stdClass
9460
{
95-
$formatedResponse = new \stdClass();
96-
$formatedResponse->files = $files;
61+
$formattedResponse = new \stdClass();
62+
$formattedResponse->files = $files;
9763

98-
return $formatedResponse;
64+
return $formattedResponse;
9965
}
10066
}

Form/DataTransformer/ArrayToStringTransformer.php

+14-33
Original file line numberDiff line numberDiff line change
@@ -13,64 +13,45 @@
1313
*/
1414
class ArrayToStringTransformer implements DataTransformerInterface
1515
{
16-
/**
17-
* @var string
18-
*/
19-
private $separator;
20-
21-
/**
22-
* @var array
23-
*/
24-
private $keys;
25-
26-
/**
27-
* Default constructor
28-
*
29-
* @param string $separator
30-
* @param array $keys
31-
*/
32-
public function __construct($separator = ',', array $keys = array())
16+
public function __construct(
17+
private readonly string $separator = ',',
18+
private readonly array $keys = []
19+
)
3320
{
34-
$this->separator = $separator;
35-
$this->keys = $keys;
3621
}
3722

3823
/**
3924
* Transforms an array to a string
40-
*
41-
* {@inheritdoc}
4225
*/
43-
public function transform($array)
26+
public function transform(mixed $value): string
4427
{
45-
if (null === $array) {
28+
if (null === $value) {
4629
return '';
4730
}
4831

49-
if (!is_array($array)) {
32+
if (!is_array($value)) {
5033
throw new TransformationFailedException('Expected an array');
5134
}
5235

53-
$array = array_filter(array_values($array), 'strlen');
36+
$value = array_filter(array_values($value), 'strlen');
5437

55-
return empty($array) ? '' : implode($this->separator, $array);
38+
return empty($value) ? '' : implode($this->separator, $value);
5639
}
5740

5841
/**
5942
* Transforms a string to an array
60-
*
61-
* {@inheritdoc}
6243
*/
63-
public function reverseTransform($string)
44+
public function reverseTransform(mixed $value): array
6445
{
65-
if (!is_string($string)) {
46+
if (!is_string($value)) {
6647
throw new TransformationFailedException('Expected a string');
6748
}
6849

69-
if ( 0 === strlen($string)) {
70-
return array();
50+
if ( 0 === strlen($value)) {
51+
return [];
7152
}
7253

73-
$transformedString = explode($this->separator, $string);
54+
$transformedString = explode($this->separator, $value);
7455

7556
if (!empty($this->keys)) {
7657
if (count($this->keys) != count($transformedString)) {

Form/EventListener/ReorderCollectionSubscriber.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@
1111
*/
1212
class ReorderCollectionSubscriber implements EventSubscriberInterface
1313
{
14-
public static function getSubscribedEvents()
14+
public static function getSubscribedEvents(): array
1515
{
16-
return array(
17-
FormEvents::PRE_SUBMIT => array('preSubmit', 140),
18-
);
16+
return [
17+
FormEvents::PRE_SUBMIT => ['preSubmit', 140],
18+
];
1919
}
2020

21-
/**
22-
* @param FormEvent $event
23-
*/
24-
public function preSubmit(FormEvent $event)
21+
public function preSubmit(FormEvent $event): void
2522
{
2623
$data = $event->getData();
2724

0 commit comments

Comments
 (0)