Skip to content

Commit 32c3ceb

Browse files
committed
refactor: rewrote package to be more configurable and flexible
1 parent ea21156 commit 32c3ceb

Some content is hidden

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

58 files changed

+1336
-1397
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"wayofdev/cs-fixer-config": "^1.5"
5959
},
6060
"suggest": {
61-
"symfony/yaml": "For using the YamlEncoder."
61+
"symfony/yaml": "Required only if YamlEncoder support is needed."
6262
},
6363
"autoload": {
6464
"psr-4": {
@@ -118,7 +118,7 @@
118118
"stan:ci": "phpstan analyse --memory-limit=2G --error-format=github",
119119
"test": [
120120
"@putenv XDEBUG_MODE=coverage",
121-
"pest --color=always"
121+
"pest --color=always -v"
122122
],
123123
"test:arch": [
124124
"@putenv XDEBUG_MODE=coverage",

composer.lock

+68-64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/serializer.php

+43-23
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,63 @@
22

33
declare(strict_types=1);
44

5+
use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface;
6+
7+
/**
8+
* @return array{
9+
* default: string,
10+
* debug: bool,
11+
* normalizerRegistrationStrategy: class-string<WayOfDev\Serializer\Contracts\NormalizerRegistrationStrategy>,
12+
* encoderRegistrationStrategy: class-string<WayOfDev\Serializer\Contracts\EncoderRegistrationStrategy>,
13+
* metadataLoader: class-string<LoaderInterface>|null,
14+
* }
15+
*/
516
return [
617
/*
718
* The 'default' key specifies the name (format) of the default serializer
819
* that will be registered in SerializerManager. This can be overridden
920
* by setting the SERIALIZER_DEFAULT_FORMAT environment variable.
1021
*/
11-
'default' => env('SERIALIZER_DEFAULT_FORMAT', 'json'),
22+
'default' => env('SERIALIZER_DEFAULT_FORMAT', 'symfony-json'),
1223

1324
/*
14-
* The 'serializers' key lists the supported serializers: json, csv, xml, yaml.
15-
* Set a serializer to "false" to disable it. This can be overridden by setting
16-
* the corresponding SERIALIZER_USE_* environment variable.
25+
* Specifies whether to enable debug mode for ProblemNormalizer.
1726
*/
18-
'serializers' => [
19-
'json' => env('SERIALIZER_USE_JSON', true),
20-
'csv' => env('SERIALIZER_USE_CSV', false),
21-
'xml' => env('SERIALIZER_USE_XML', false),
22-
'yaml' => env('SERIALIZER_USE_YAML', false),
23-
],
27+
'debug' => env('SERIALIZER_DEBUG_MODE', env('APP_DEBUG', false)),
2428

2529
/*
26-
* The 'normalizers' key allows you to register your custom normalizers.
27-
* Default normalizers are registered in src/NormalizersRegistry.php.
28-
* Uncomment the line below and replace with your custom normalizer if needed
29-
* to merge with default ones.
30+
* Allows to specify additional, custom serializers that will be registered in SerializerManager.
3031
*/
31-
'normalizers' => [
32-
// Symfony\Component\Messenger\Transport\Serialization\Normalizer\FlattenExceptionNormalizer
32+
'manager' => [
33+
'serializers' => [
34+
'json' => '',
35+
'php' => '',
36+
],
3337
],
3438

3539
/*
36-
* The 'encoders' key allows you to register your custom encoders.
37-
* Default encoders are registered in src/EncodersRegistry.php.
38-
* Default encoders include JsonEncoder, CsvEncoder, XmlEncoder, and YamlEncoder.
39-
* Uncomment the line below and replace with your custom encoder if needed.
40+
* Allows you to specify the strategy class for registering your normalizers.
41+
* Default is 'WayOfDev\Serializer\DefaultNormalizerRegistrationStrategy'.
4042
*/
41-
'encoders' => [
42-
// Symfony\Component\Serializer\Encoder\JsonEncoder
43-
],
43+
'normalizerRegistrationStrategy' => WayOfDev\Serializer\DefaultNormalizerRegistrationStrategy::class,
44+
45+
/*
46+
* Allows you to register your custom encoders.
47+
* Default encoders are registered in src/DefaultEncoderRegistrationStrategy.php.
48+
*
49+
* Default encoders include:
50+
* JsonEncoder,
51+
* CsvEncoder,
52+
* XmlEncoder,
53+
* YamlEncoder.
54+
*
55+
* You can replace the default encoders with your custom ones by implementing
56+
* your own registration strategy.
57+
*/
58+
'encoderRegistrationStrategy' => WayOfDev\Serializer\DefaultEncoderRegistrationStrategy::class,
59+
60+
/*
61+
* Allows you to register your custom metadata loader.
62+
*/
63+
'metadataLoader' => null,
4464
];

phpstan-baseline.neon

-225
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Access to an undefined property WayOfDev\\\\Serializer\\\\Config\\:\\:\\$config\\.$#"
5-
count: 1
6-
path: src/Config.php
7-
8-
-
9-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
10-
count: 1
11-
path: src/Config.php
12-
13-
-
14-
message: "#^Method WayOfDev\\\\Serializer\\\\Config\\:\\:__construct\\(\\) has parameter \\$encoders with no value type specified in iterable type array\\.$#"
15-
count: 1
16-
path: src/Config.php
17-
18-
-
19-
message: "#^Method WayOfDev\\\\Serializer\\\\Config\\:\\:__construct\\(\\) has parameter \\$normalizers with no value type specified in iterable type array\\.$#"
20-
count: 1
21-
path: src/Config.php
22-
23-
-
24-
message: "#^Method WayOfDev\\\\Serializer\\\\Config\\:\\:encoders\\(\\) return type has no value type specified in iterable type array\\.$#"
25-
count: 1
26-
path: src/Config.php
27-
28-
-
29-
message: "#^Method WayOfDev\\\\Serializer\\\\Config\\:\\:fromArray\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#"
30-
count: 1
31-
path: src/Config.php
32-
33-
-
34-
message: "#^Method WayOfDev\\\\Serializer\\\\Config\\:\\:normalizers\\(\\) return type has no value type specified in iterable type array\\.$#"
35-
count: 1
36-
path: src/Config.php
37-
38-
-
39-
message: "#^Method WayOfDev\\\\Serializer\\\\Contracts\\\\ConfigRepository\\:\\:encoders\\(\\) return type has no value type specified in iterable type array\\.$#"
40-
count: 1
41-
path: src/Contracts/ConfigRepository.php
42-
43-
-
44-
message: "#^Method WayOfDev\\\\Serializer\\\\Contracts\\\\ConfigRepository\\:\\:normalizers\\(\\) return type has no value type specified in iterable type array\\.$#"
45-
count: 1
46-
path: src/Contracts/ConfigRepository.php
47-
48-
-
49-
message: "#^Method WayOfDev\\\\Serializer\\\\Contracts\\\\NormalizersRegistryInterface\\:\\:all\\(\\) return type has no value type specified in iterable type array\\.$#"
50-
count: 1
51-
path: src/Contracts/NormalizersRegistryInterface.php
52-
53-
-
54-
message: "#^Method WayOfDev\\\\Serializer\\\\Contracts\\\\SerializerInterface\\:\\:normalize\\(\\) has no return type specified\\.$#"
55-
count: 1
56-
path: src/Contracts/SerializerInterface.php
57-
58-
-
59-
message: "#^Method WayOfDev\\\\Serializer\\\\Contracts\\\\SerializerInterface\\:\\:normalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
60-
count: 1
61-
path: src/Contracts/SerializerInterface.php
62-
63-
-
64-
message: "#^Method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:denormalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
65-
count: 1
66-
path: src/Normalizers/RamseyUuidNormalizer.php
67-
68-
-
69-
message: "#^Method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:normalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
70-
count: 1
71-
path: src/Normalizers/RamseyUuidNormalizer.php
72-
733
-
744
message: "#^Method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:normalize\\(\\) return type has no value type specified in iterable type array\\.$#"
755
count: 1
@@ -80,162 +10,7 @@ parameters:
8010
count: 1
8111
path: src/Normalizers/RamseyUuidNormalizer.php
8212

83-
-
84-
message: "#^Method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:supportsDenormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
85-
count: 1
86-
path: src/Normalizers/RamseyUuidNormalizer.php
87-
88-
-
89-
message: "#^Method WayOfDev\\\\Serializer\\\\Normalizers\\\\RamseyUuidNormalizer\\:\\:supportsNormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
90-
count: 1
91-
path: src/Normalizers/RamseyUuidNormalizer.php
92-
9313
-
9414
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\\(\\)$#"
9515
count: 1
9616
path: src/Normalizers/RamseyUuidNormalizer.php
97-
98-
-
99-
message: "#^Method WayOfDev\\\\Serializer\\\\NormalizersRegistry\\:\\:__construct\\(\\) has parameter \\$normalizers with no value type specified in iterable type array\\.$#"
100-
count: 1
101-
path: src/NormalizersRegistry.php
102-
103-
-
104-
message: "#^Method WayOfDev\\\\Serializer\\\\ResponseFactory\\:\\:fromArray\\(\\) has parameter \\$response with no value type specified in iterable type array\\.$#"
105-
count: 1
106-
path: src/ResponseFactory.php
107-
108-
-
109-
message: "#^Method WayOfDev\\\\Serializer\\\\ResponseFactory\\:\\:serializeResponse\\(\\) has parameter \\$response with no value type specified in iterable type array\\.$#"
110-
count: 1
111-
path: src/ResponseFactory.php
112-
113-
-
114-
message: "#^Method WayOfDev\\\\Serializer\\\\ResponseFactory\\:\\:withContext\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
115-
count: 1
116-
path: src/ResponseFactory.php
117-
118-
-
119-
message: "#^Property WayOfDev\\\\Serializer\\\\ResponseFactory\\:\\:\\$context type has no value type specified in iterable type array\\.$#"
120-
count: 1
121-
path: src/ResponseFactory.php
122-
123-
-
124-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:decode\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
125-
count: 1
126-
path: src/Serializer.php
127-
128-
-
129-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:denormalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
130-
count: 1
131-
path: src/Serializer.php
132-
133-
-
134-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:encode\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
135-
count: 1
136-
path: src/Serializer.php
137-
138-
-
139-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:normalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
140-
count: 1
141-
path: src/Serializer.php
142-
143-
-
144-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:normalize\\(\\) return type has no value type specified in iterable type array\\.$#"
145-
count: 1
146-
path: src/Serializer.php
147-
148-
-
149-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:normalize\\(\\) return type with generic class ArrayObject does not specify its types\\: TKey, TValue$#"
150-
count: 1
151-
path: src/Serializer.php
152-
153-
-
154-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:serialize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
155-
count: 1
156-
path: src/Serializer.php
157-
158-
-
159-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:supportsDecoding\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
160-
count: 1
161-
path: src/Serializer.php
162-
163-
-
164-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:supportsDenormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
165-
count: 1
166-
path: src/Serializer.php
167-
168-
-
169-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:supportsEncoding\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
170-
count: 1
171-
path: src/Serializer.php
172-
173-
-
174-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:supportsNormalization\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
175-
count: 1
176-
path: src/Serializer.php
177-
178-
-
179-
message: "#^Method WayOfDev\\\\Serializer\\\\Serializer\\:\\:unserialize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
180-
count: 1
181-
path: src/Serializer.php
182-
183-
-
184-
message: "#^Method WayOfDev\\\\Serializer\\\\SerializerManager\\:\\:normalize\\(\\) has no return type specified\\.$#"
185-
count: 1
186-
path: src/SerializerManager.php
187-
188-
-
189-
message: "#^Method WayOfDev\\\\Serializer\\\\SerializerManager\\:\\:normalize\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
190-
count: 1
191-
path: src/SerializerManager.php
192-
193-
-
194-
message: "#^Method WayOfDev\\\\Serializer\\\\SerializerRegistry\\:\\:__construct\\(\\) has parameter \\$serializers with no value type specified in iterable type array\\.$#"
195-
count: 1
196-
path: src/SerializerRegistry.php
197-
198-
-
199-
message: "#^Method WayOfDev\\\\App\\\\NestedObjects\\\\City\\:\\:jsonSerialize\\(\\) return type has no value type specified in iterable type array\\.$#"
200-
count: 1
201-
path: tests/app/NestedObjects/City.php
202-
203-
-
204-
message: "#^Class WayOfDev\\\\App\\\\Response extends generic class ArrayIterator but does not specify its types\\: TKey, TValue$#"
205-
count: 1
206-
path: tests/app/Response.php
207-
208-
-
209-
message: "#^Method WayOfDev\\\\App\\\\Response\\:\\:__construct\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
210-
count: 1
211-
path: tests/app/Response.php
212-
213-
-
214-
message: "#^Method WayOfDev\\\\App\\\\Response\\:\\:create\\(\\) has parameter \\$items with no value type specified in iterable type array\\.$#"
215-
count: 1
216-
path: tests/app/Response.php
217-
218-
-
219-
message: "#^Method WayOfDev\\\\Tests\\\\Functional\\\\Normalizers\\\\RamseyUuidNormalizerTest\\:\\:serializeDataProvider\\(\\) return type has no value type specified in iterable type Traversable\\.$#"
220-
count: 1
221-
path: tests/src/Functional/Normalizers/RamseyUuidNormalizerTest.php
222-
223-
-
224-
message: "#^Method WayOfDev\\\\Tests\\\\Functional\\\\NormalizersRegistryTest\\:\\:assertContainsInstanceOf\\(\\) has parameter \\$array with no value type specified in iterable type array\\.$#"
225-
count: 1
226-
path: tests/src/Functional/NormalizersRegistryTest.php
227-
228-
-
229-
message: "#^Method WayOfDev\\\\Tests\\\\Functional\\\\SerializerManagerTest\\:\\:serializeDataProvider\\(\\) return type has no value type specified in iterable type Traversable\\.$#"
230-
count: 1
231-
path: tests/src/Functional/SerializerManagerTest.php
232-
233-
-
234-
message: "#^Method WayOfDev\\\\Tests\\\\Functional\\\\SerializerManagerTest\\:\\:unserializeDataProvider\\(\\) return type has no value type specified in iterable type Traversable\\.$#"
235-
count: 1
236-
path: tests/src/Functional/SerializerManagerTest.php
237-
238-
-
239-
message: "#^Method WayOfDev\\\\Tests\\\\Functional\\\\SerializerTest\\:\\:serializeDataProvider\\(\\) return type has no value type specified in iterable type Traversable\\.$#"
240-
count: 1
241-
path: tests/src/Functional/SerializerTest.php

phpstan.neon.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ includes:
22
- phpstan-baseline.neon
33

44
parameters:
5-
level: 6
5+
level: 8
66
paths:
77
- config/
88
- src/

phpunit.xml.dist

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<testsuite name="Functional Tests">
1818
<directory>tests/src/Functional</directory>
1919
</testsuite>
20+
<testsuite name="Unit Tests">
21+
<directory>tests/src/Unit</directory>
22+
</testsuite>
2023
</testsuites>
2124
<coverage>
2225
<report>

0 commit comments

Comments
 (0)