Skip to content

Commit 304c90c

Browse files
committed
Remove detailed types
1 parent 25eb8be commit 304c90c

File tree

6 files changed

+34
-83
lines changed

6 files changed

+34
-83
lines changed

src/Mapping/Metadata/ClassMetadata.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,14 @@ public function __construct(
7777
*/
7878
public function getTypeStatement(Context $context, bool $read): TypeStatement
7979
{
80-
if (!$context->isDetailedTypes()) {
81-
return new NamedTypeNode($this->name);
82-
}
83-
8480
$fields = [];
8581

8682
foreach ($this->properties as $property) {
8783
$fields[] = $property->getFieldNode($context, $read);
8884
}
8985

9086
if ($fields === []) {
91-
return new NamedTypeNode($this->name);
87+
return new NamedTypeNode($this->name, fields: new FieldsListNode());
9288
}
9389

9490
return new NamedTypeNode($this->name, fields: new FieldsListNode($fields));

src/Mapping/Metadata/ClassMetadata/PropertyMetadata.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ public function getTypeStatement(Context $context, bool $read): TypeStatement
7777

7878
$statement = clone $info->statement;
7979

80-
if ($context->isDetailedTypes() || !$statement instanceof NamedTypeNode) {
81-
return $statement;
80+
if ($statement instanceof NamedTypeNode) {
81+
return new NamedTypeNode($statement->name);
8282
}
8383

84-
return new NamedTypeNode($statement->name);
84+
return $statement;
8585
}
8686

8787
/**

src/Runtime/Configuration.php

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ final class Configuration implements ConfigurationInterface
1414
*/
1515
public const OBJECTS_AS_ARRAYS_DEFAULT_VALUE = true;
1616

17-
/**
18-
* Default value for {@see $isDetailedTypes} option.
19-
*/
20-
public const DETAILED_TYPES_DEFAULT_VALUE = true;
21-
2217
/**
2318
* Default value for {@see $isStrictTypes} option.
2419
*/
@@ -30,32 +25,27 @@ public function __construct(
3025
* associative arrays, otherwise anonymous {@see object} will be
3126
* returned.
3227
*/
33-
private ?bool $isObjectsAsArrays = null,
34-
/**
35-
* If this option contains {@see true}, then all composite types will
36-
* be displayed along with detailed fields/values.
37-
*/
38-
private ?bool $isDetailedTypes = null,
28+
private readonly ?bool $isObjectsAsArrays = null,
3929
/**
4030
* If this option contains {@see true}, then strict types will
4131
* be enabled.
4232
*/
43-
private ?bool $isStrictTypes = null,
33+
private readonly ?bool $isStrictTypes = null,
4434
/**
4535
* If this option contains {@see LoggerInterface}, then logger
4636
* will be enabled.
4737
*
4838
* Logger will be disabled in case of argument contain {@see null}.
4939
*/
50-
private ?LoggerInterface $logger = null,
40+
private readonly ?LoggerInterface $logger = null,
5141
/**
5242
* If this option contains {@see TracerInterface}, then an application
5343
* tracing will be enabled using given tracer.
5444
*
5545
* An application tracing will be disabled in case of argument
5646
* contain {@see null}.
5747
*/
58-
private ?TracerInterface $tracer = null,
48+
private readonly ?TracerInterface $tracer = null,
5949
) {}
6050

6151
/**
@@ -67,10 +57,12 @@ public function __construct(
6757
*/
6858
public function withObjectsAsArrays(?bool $enabled = null): self
6959
{
70-
$self = clone $this;
71-
$self->isObjectsAsArrays = $enabled;
72-
73-
return $self;
60+
return new self(
61+
isObjectsAsArrays: $enabled,
62+
isStrictTypes: $this->isStrictTypes,
63+
logger: $this->logger,
64+
tracer: $this->tracer,
65+
);
7466
}
7567

7668
public function isObjectsAsArrays(): bool
@@ -88,36 +80,6 @@ public function isObjectsAsArraysOptionDefined(): bool
8880
return $this->isObjectsAsArrays !== null;
8981
}
9082

91-
/**
92-
* Enables or disables detailed types in exceptions.
93-
*
94-
* In case of $enabled is {@see null} a default value will be defined.
95-
*
96-
* @api
97-
*/
98-
public function withDetailedTypes(?bool $enabled = null): self
99-
{
100-
$self = clone $this;
101-
$self->isDetailedTypes = $enabled;
102-
103-
return $self;
104-
}
105-
106-
public function isDetailedTypes(): bool
107-
{
108-
return $this->isDetailedTypes ?? self::DETAILED_TYPES_DEFAULT_VALUE;
109-
}
110-
111-
/**
112-
* Returns {@see true} in case option is user-defined.
113-
*
114-
* @api
115-
*/
116-
public function isDetailedTypesOptionDefined(): bool
117-
{
118-
return $this->isDetailedTypes !== null;
119-
}
120-
12183
/**
12284
* Enables or disables strict types in casting.
12385
*
@@ -127,10 +89,12 @@ public function isDetailedTypesOptionDefined(): bool
12789
*/
12890
public function withStrictTypes(?bool $enabled = null): self
12991
{
130-
$self = clone $this;
131-
$self->isStrictTypes = $enabled;
132-
133-
return $self;
92+
return new self(
93+
isObjectsAsArrays: $this->isObjectsAsArrays,
94+
isStrictTypes: $enabled,
95+
logger: $this->logger,
96+
tracer: $this->tracer,
97+
);
13498
}
13599

136100
public function isStrictTypesEnabled(): bool
@@ -156,10 +120,12 @@ public function isStrictTypesOptionDefined(): bool
156120
*/
157121
public function withLogger(?LoggerInterface $logger = null): self
158122
{
159-
$self = clone $this;
160-
$self->logger = $logger;
161-
162-
return $self;
123+
return new self(
124+
isObjectsAsArrays: $this->isObjectsAsArrays,
125+
isStrictTypes: $this->isStrictTypes,
126+
logger: $logger,
127+
tracer: $this->tracer,
128+
);
163129
}
164130

165131
public function getLogger(): ?LoggerInterface
@@ -176,10 +142,12 @@ public function getLogger(): ?LoggerInterface
176142
*/
177143
public function withTracer(?TracerInterface $tracer = null): self
178144
{
179-
$self = clone $this;
180-
$self->tracer = $tracer;
181-
182-
return $self;
145+
return new self(
146+
isObjectsAsArrays: $this->isObjectsAsArrays,
147+
isStrictTypes: $this->isStrictTypes,
148+
logger: $this->logger,
149+
tracer: $tracer,
150+
);
183151
}
184152

185153
public function getTracer(): ?TracerInterface

src/Runtime/ConfigurationInterface.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ interface ConfigurationInterface
1717
*/
1818
public function isObjectsAsArrays(): bool;
1919

20-
/**
21-
* In case of returns {@see true}, then all composite types will
22-
* be displayed along with detailed fields/values.
23-
*
24-
* Otherwise, only a short description will be displayed.
25-
*/
26-
public function isDetailedTypes(): bool;
27-
2820
/**
2921
* In case of method returns {@see true}, all types will be checked
3022
* for compliance.

src/Runtime/Context.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ public function isObjectsAsArrays(): bool
5959
return $this->config->isObjectsAsArrays();
6060
}
6161

62-
public function isDetailedTypes(): bool
63-
{
64-
return $this->config->isDetailedTypes();
65-
}
66-
6762
public function isStrictTypesEnabled(): bool
6863
{
6964
return $this->config->isStrictTypesEnabled();

src/Runtime/Context/RootContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function forNormalization(
2929
TypeRepositoryInterface $types,
3030
): self {
3131
if ($config instanceof Configuration) {
32-
// Disable strict-types for denormalization if option is not set
32+
// Disable strict-types for normalization if option is not set
3333
if (!$config->isStrictTypesOptionDefined()) {
3434
$config = $config->withStrictTypes(false);
3535
}
@@ -55,7 +55,7 @@ public static function forDenormalization(
5555
TypeRepositoryInterface $types,
5656
): self {
5757
if ($config instanceof Configuration) {
58-
// Enable strict-types for normalization if option is not set
58+
// Enable strict-types for denormalization if option is not set
5959
if (!$config->isStrictTypesOptionDefined()) {
6060
$config = $config->withStrictTypes(true);
6161
}

0 commit comments

Comments
 (0)