Skip to content

Commit

Permalink
refactor: rewrote package to be more configurable and flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp committed Jun 18, 2024
1 parent ea21156 commit 32c3ceb
Show file tree
Hide file tree
Showing 58 changed files with 1,336 additions and 1,397 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"wayofdev/cs-fixer-config": "^1.5"
},
"suggest": {
"symfony/yaml": "For using the YamlEncoder."
"symfony/yaml": "Required only if YamlEncoder support is needed."
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -118,7 +118,7 @@
"stan:ci": "phpstan analyse --memory-limit=2G --error-format=github",
"test": [
"@putenv XDEBUG_MODE=coverage",
"pest --color=always"
"pest --color=always -v"
],
"test:arch": [
"@putenv XDEBUG_MODE=coverage",
Expand Down
132 changes: 68 additions & 64 deletions composer.lock

Large diffs are not rendered by default.

66 changes: 43 additions & 23 deletions config/serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,63 @@

declare(strict_types=1);

use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface;

/**
* @return array{
* default: string,
* debug: bool,
* normalizerRegistrationStrategy: class-string<WayOfDev\Serializer\Contracts\NormalizerRegistrationStrategy>,
* encoderRegistrationStrategy: class-string<WayOfDev\Serializer\Contracts\EncoderRegistrationStrategy>,
* metadataLoader: class-string<LoaderInterface>|null,
* }
*/
return [
/*
* The 'default' key specifies the name (format) of the default serializer
* that will be registered in SerializerManager. This can be overridden
* by setting the SERIALIZER_DEFAULT_FORMAT environment variable.
*/
'default' => env('SERIALIZER_DEFAULT_FORMAT', 'json'),
'default' => env('SERIALIZER_DEFAULT_FORMAT', 'symfony-json'),

/*
* The 'serializers' key lists the supported serializers: json, csv, xml, yaml.
* Set a serializer to "false" to disable it. This can be overridden by setting
* the corresponding SERIALIZER_USE_* environment variable.
* Specifies whether to enable debug mode for ProblemNormalizer.
*/
'serializers' => [
'json' => env('SERIALIZER_USE_JSON', true),
'csv' => env('SERIALIZER_USE_CSV', false),
'xml' => env('SERIALIZER_USE_XML', false),
'yaml' => env('SERIALIZER_USE_YAML', false),
],
'debug' => env('SERIALIZER_DEBUG_MODE', env('APP_DEBUG', false)),

/*
* The 'normalizers' key allows you to register your custom normalizers.
* Default normalizers are registered in src/NormalizersRegistry.php.
* Uncomment the line below and replace with your custom normalizer if needed
* to merge with default ones.
* Allows to specify additional, custom serializers that will be registered in SerializerManager.
*/
'normalizers' => [
// Symfony\Component\Messenger\Transport\Serialization\Normalizer\FlattenExceptionNormalizer
'manager' => [
'serializers' => [
'json' => '',
'php' => '',
],
],

/*
* The 'encoders' key allows you to register your custom encoders.
* Default encoders are registered in src/EncodersRegistry.php.
* Default encoders include JsonEncoder, CsvEncoder, XmlEncoder, and YamlEncoder.
* Uncomment the line below and replace with your custom encoder if needed.
* Allows you to specify the strategy class for registering your normalizers.
* Default is 'WayOfDev\Serializer\DefaultNormalizerRegistrationStrategy'.
*/
'encoders' => [
// Symfony\Component\Serializer\Encoder\JsonEncoder
],
'normalizerRegistrationStrategy' => WayOfDev\Serializer\DefaultNormalizerRegistrationStrategy::class,

/*
* Allows you to register your custom encoders.
* Default encoders are registered in src/DefaultEncoderRegistrationStrategy.php.
*
* Default encoders include:
* JsonEncoder,
* CsvEncoder,
* XmlEncoder,
* YamlEncoder.
*
* You can replace the default encoders with your custom ones by implementing
* your own registration strategy.
*/
'encoderRegistrationStrategy' => WayOfDev\Serializer\DefaultEncoderRegistrationStrategy::class,

/*
* Allows you to register your custom metadata loader.
*/
'metadataLoader' => null,
];
225 changes: 0 additions & 225 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,75 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Access to an undefined property WayOfDev\\\\Serializer\\\\Config\\:\\:\\$config\\.$#"
count: 1
path: src/Config.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
path: src/Config.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Config\\:\\:__construct\\(\\) has parameter \\$encoders with no value type specified in iterable type array\\.$#"
count: 1
path: src/Config.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Config\\:\\:__construct\\(\\) has parameter \\$normalizers with no value type specified in iterable type array\\.$#"
count: 1
path: src/Config.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Config\\:\\:encoders\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Config.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Config\\:\\:fromArray\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#"
count: 1
path: src/Config.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Config\\:\\:normalizers\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Config.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Contracts\\\\ConfigRepository\\:\\:encoders\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Contracts/ConfigRepository.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Contracts\\\\ConfigRepository\\:\\:normalizers\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Contracts/ConfigRepository.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Contracts\\\\NormalizersRegistryInterface\\:\\:all\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Contracts/NormalizersRegistryInterface.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Contracts\\\\SerializerInterface\\:\\:normalize\\(\\) has no return type specified\\.$#"
count: 1
path: src/Contracts/SerializerInterface.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Contracts\\\\SerializerInterface\\:\\:normalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Contracts/SerializerInterface.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:denormalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Normalizers/RamseyUuidNormalizer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:normalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Normalizers/RamseyUuidNormalizer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:normalize\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -80,162 +10,7 @@ parameters:
count: 1
path: src/Normalizers/RamseyUuidNormalizer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:supportsDenormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Normalizers/RamseyUuidNormalizer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:supportsNormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Normalizers/RamseyUuidNormalizer.php

-
message: "#^Parameter \\#1 \\$object \\(Ramsey\\\\Uuid\\\\UuidInterface\\) of method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:normalize\\(\\) should be contravariant with parameter \\$object \\(mixed\\) of method Symfony\\\\Component\\\\Serializer\\\\Normalizer\\\\NormalizerInterface\\:\\:normalize\\(\\)$#"
count: 1
path: src/Normalizers/RamseyUuidNormalizer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\NormalizersRegistry\\:\\:__construct\\(\\) has parameter \\$normalizers with no value type specified in iterable type array\\.$#"
count: 1
path: src/NormalizersRegistry.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\ResponseFactory\\:\\:fromArray\\(\\) has parameter \\$response with no value type specified in iterable type array\\.$#"
count: 1
path: src/ResponseFactory.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\ResponseFactory\\:\\:serializeResponse\\(\\) has parameter \\$response with no value type specified in iterable type array\\.$#"
count: 1
path: src/ResponseFactory.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\ResponseFactory\\:\\:withContext\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/ResponseFactory.php

-
message: "#^Property WayOfDev\\\\Serializer\\\\ResponseFactory\\:\\:\\$context type has no value type specified in iterable type array\\.$#"
count: 1
path: src/ResponseFactory.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:decode\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Serializer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:denormalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Serializer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:encode\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Serializer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:normalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Serializer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:normalize\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Serializer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:normalize\\(\\) return type with generic class ArrayObject does not specify its types\\: TKey, TValue$#"
count: 1
path: src/Serializer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:serialize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Serializer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:supportsDecoding\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Serializer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:supportsDenormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Serializer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:supportsEncoding\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Serializer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:supportsNormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Serializer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:unserialize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Serializer.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\SerializerManager\\:\\:normalize\\(\\) has no return type specified\\.$#"
count: 1
path: src/SerializerManager.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\SerializerManager\\:\\:normalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/SerializerManager.php

-
message: "#^Method WayOfDev\\\\Serializer\\\\SerializerRegistry\\:\\:__construct\\(\\) has parameter \\$serializers with no value type specified in iterable type array\\.$#"
count: 1
path: src/SerializerRegistry.php

-
message: "#^Method WayOfDev\\\\App\\\\NestedObjects\\\\City\\:\\:jsonSerialize\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/app/NestedObjects/City.php

-
message: "#^Class WayOfDev\\\\App\\\\Response extends generic class ArrayIterator but does not specify its types\\: TKey, TValue$#"
count: 1
path: tests/app/Response.php

-
message: "#^Method WayOfDev\\\\App\\\\Response\\:\\:__construct\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
count: 1
path: tests/app/Response.php

-
message: "#^Method WayOfDev\\\\App\\\\Response\\:\\:create\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
count: 1
path: tests/app/Response.php

-
message: "#^Method WayOfDev\\\\Tests\\\\Functional\\\\Normalizers\\\\RamseyUuidNormalizerTest\\:\\:serializeDataProvider\\(\\) return type has no value type specified in iterable type Traversable\\.$#"
count: 1
path: tests/src/Functional/Normalizers/RamseyUuidNormalizerTest.php

-
message: "#^Method WayOfDev\\\\Tests\\\\Functional\\\\NormalizersRegistryTest\\:\\:assertContainsInstanceOf\\(\\) has parameter \\$array with no value type specified in iterable type array\\.$#"
count: 1
path: tests/src/Functional/NormalizersRegistryTest.php

-
message: "#^Method WayOfDev\\\\Tests\\\\Functional\\\\SerializerManagerTest\\:\\:serializeDataProvider\\(\\) return type has no value type specified in iterable type Traversable\\.$#"
count: 1
path: tests/src/Functional/SerializerManagerTest.php

-
message: "#^Method WayOfDev\\\\Tests\\\\Functional\\\\SerializerManagerTest\\:\\:unserializeDataProvider\\(\\) return type has no value type specified in iterable type Traversable\\.$#"
count: 1
path: tests/src/Functional/SerializerManagerTest.php

-
message: "#^Method WayOfDev\\\\Tests\\\\Functional\\\\SerializerTest\\:\\:serializeDataProvider\\(\\) return type has no value type specified in iterable type Traversable\\.$#"
count: 1
path: tests/src/Functional/SerializerTest.php
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
- phpstan-baseline.neon

parameters:
level: 6
level: 8
paths:
- config/
- src/
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<testsuite name="Functional Tests">
<directory>tests/src/Functional</directory>
</testsuite>
<testsuite name="Unit Tests">
<directory>tests/src/Unit</directory>
</testsuite>
</testsuites>
<coverage>
<report>
Expand Down
Loading

0 comments on commit 32c3ceb

Please sign in to comment.