Skip to content

Commit 39ffca6

Browse files
[Maintenance] Cleanup and usable string extraction to consts
1 parent af9f8d1 commit 39ffca6

File tree

8 files changed

+63
-10
lines changed

8 files changed

+63
-10
lines changed

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ parameters:
1010

1111
excludePaths:
1212
- '%currentWorkingDirectory%/src/DependencyInjection/Configuration.php'
13+
- '%currentWorkingDirectory%/src/Serializer/ExportAwareItemNormalizer.php'

src/Controller/ExportAction.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace Sylius\ImportExport\Controller;
1515

16-
use Sylius\Bundle\ResourceBundle\Controller\ParametersParserInterface;
17-
use Sylius\Component\Grid\Provider\GridProviderInterface;
1816
use Sylius\ImportExport\Messenger\Command\CreateExportProcess;
1917
use Sylius\ImportExport\Provider\Parameters\GridExportParametersProviderInterface;
2018
use Sylius\ImportExport\Provider\ResourceIds\ResourcesIdsProviderInterface;

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Sylius\ImportExport\DependencyInjection;
1515

16+
use Sylius\ImportExport\Serializer\DefaultSerializationGroups;
1617
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1718
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1819
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -59,7 +60,7 @@ private function addExportConfiguration(ArrayNodeDefinition $node): void
5960
->children()
6061
->scalarNode('serialization_group')
6162
->isRequired()
62-
->defaultValue('sylius_import_export.export')
63+
->defaultValue(DefaultSerializationGroups::EXPORT_GROUP)
6364
->end()
6465
->scalarNode('provider')
6566
->defaultNull()

src/Provider/Parameters/GridExportParametersProvider.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
<?php
22

3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
declare(strict_types=1);
413

514
namespace Sylius\ImportExport\Provider\Parameters;
615

716
use Sylius\Bundle\ResourceBundle\Controller\ParametersParserInterface;
817
use Sylius\Component\Grid\Provider\GridProviderInterface;
18+
use Sylius\ImportExport\Serializer\DefaultSerializationGroups;
919
use Sylius\Resource\Metadata\MetadataInterface;
1020
use Symfony\Component\HttpFoundation\Request;
1121

@@ -24,7 +34,7 @@ public function getParameters(MetadataInterface $metadata, string $gridName, Req
2434
$gridConfiguration = $this->gridProvider->get($gridName);
2535

2636
$resourceExportConfiguration = $this->resourceExportConfiguration[$metadata->getAlias()] ?? [];
27-
$serializationGroup = $resourceExportConfiguration['serialization_group'] ?? 'sylius_import_export.export';
37+
$serializationGroup = $resourceExportConfiguration['serialization_group'] ?? DefaultSerializationGroups::EXPORT_GROUP;
2838

2939
$parameters = $this->parametersParser->parseRequestValues(
3040
$gridConfiguration->getDriverConfiguration(),

src/Provider/Parameters/GridExportParametersProviderInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
declare(strict_types=1);
413

514
namespace Sylius\ImportExport\Provider\Parameters;

src/Provider/ResourceData/GridResourceDataProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use Sylius\Component\Grid\Provider\GridProviderInterface;
2121
use Sylius\ImportExport\Exception\ProviderException;
2222
use Sylius\ImportExport\Provider\ResourceIdentifierProviderInterface;
23+
use Sylius\ImportExport\Serializer\DefaultSerializationGroups;
24+
use Sylius\ImportExport\Serializer\ExportAwareItemNormalizer;
2325
use Sylius\Resource\Metadata\MetadataInterface;
2426
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2527

@@ -55,9 +57,10 @@ public function getData(MetadataInterface $resource, string $gridCode, array $re
5557

5658
$rawData = $dataSource->getQueryBuilder()->getQuery()->getResult();
5759

60+
/** @phpstan-ignore-next-line */
5861
return $this->serializer->normalize($rawData, context: [
59-
'sylius_import_export.export' => true,
60-
'groups' => array_merge($parameters['serialization_groups'] ?? [], ['sylius_import_export:export']),
62+
ExportAwareItemNormalizer::EXPORT_CONTEXT_KEY => true,
63+
'groups' => $parameters['serialization_groups'], [DefaultSerializationGroups::EXPORT_GROUP],
6164
]);
6265
}
6366
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\ImportExport\Serializer;
15+
16+
final class DefaultSerializationGroups
17+
{
18+
public const EXPORT_GROUP = 'sylius_import_export:export';
19+
}

src/Serializer/ExportAwareItemNormalizer.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
declare(strict_types=1);
413

514
namespace Sylius\ImportExport\Serializer;
@@ -19,11 +28,14 @@
1928
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
2029

2130
/**
22-
* @internal Decorates the original to prevent generating iris for exportable items.
2331
* @see ItemNormalizer
32+
*
33+
* @internal Decorates the original to prevent generating iris for exportable items.
2434
*/
2535
class ExportAwareItemNormalizer extends ItemNormalizer
2636
{
37+
public const EXPORT_CONTEXT_KEY = 'sylius_import_export.export';
38+
2739
public function __construct(
2840
PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory,
2941
PropertyMetadataFactoryInterface $propertyMetadataFactory,
@@ -57,7 +69,7 @@ public function __construct(
5769

5870
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
5971
{
60-
if (isset($context['sylius_import_export.export'])) {
72+
if (isset($context[self::EXPORT_CONTEXT_KEY])) {
6173
return false;
6274
}
6375

@@ -73,9 +85,9 @@ public function supportsDenormalization(
7385
mixed $data,
7486
string $type,
7587
?string $format = null,
76-
array $context = []
88+
array $context = [],
7789
): bool {
78-
if (isset($context['sylius_import_export.export'])) {
90+
if (isset($context[self::EXPORT_CONTEXT_KEY])) {
7991
return false;
8092
}
8193

0 commit comments

Comments
 (0)