Skip to content

Commit 470d2b7

Browse files
committed
Remove unused code, add recursive tuple test
1 parent 6e9e9a4 commit 470d2b7

File tree

9 files changed

+79
-39
lines changed

9 files changed

+79
-39
lines changed

src/Model/Property/Property.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,6 @@ public function addTypeHintDecorator(TypeHintDecoratorInterface $typeHintDecorat
153153
return $this;
154154
}
155155

156-
/**
157-
* @inheritdoc
158-
*/
159-
public function getTypeHintDecorators(): array
160-
{
161-
return $this->typeHintDecorators;
162-
}
163-
164156
/**
165157
* @inheritdoc
166158
*/

src/Model/Property/PropertyInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public function getTypeHint(bool $outputType = false, array $skipDecorators = []
6363
*/
6464
public function addTypeHintDecorator(TypeHintDecoratorInterface $typeHintDecorator): PropertyInterface;
6565

66-
public function getTypeHintDecorators(): array;
6766
/**
6867
* Get a description for the property. If no description is available an empty string will be returned
6968
*

src/Model/Property/PropertyProxy.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ public function addTypeHintDecorator(TypeHintDecoratorInterface $typeHintDecorat
8989
{
9090
return $this->getProperty()->addTypeHintDecorator($typeHintDecorator);
9191
}
92-
/**
93-
* @inheritdoc
94-
*/
95-
public function getTypeHintDecorators(): array
96-
{
97-
return $this->getProperty()->getTypeHintDecorators();
98-
}
9992

10093
/**
10194
* @inheritdoc
@@ -257,11 +250,4 @@ public function isInternal(): bool
257250
{
258251
return $this->getProperty()->isInternal();
259252
}
260-
261-
public function __clone()
262-
{
263-
$cloneKey = $this->key . uniqid();
264-
$this->definitionsCollection->offsetSet($cloneKey, clone $this->definitionsCollection->offsetGet($this->key));
265-
$this->key = $cloneKey;
266-
}
267253
}

src/Model/Validator/ArrayTupleValidator.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public function __construct(
4646

4747
$this->tupleProperties = [];
4848

49-
$pendingTuples = 0;
5049
foreach ($propertiesStructure->getJson() as $tupleIndex => $tupleItem) {
5150
$tupleItemName = "tuple item #$tupleIndex of array $propertyName";
5251

@@ -59,21 +58,10 @@ public function __construct(
5958
$propertiesStructure->withJson($tupleItem)
6059
);
6160

62-
if (!$tupleProperty->isResolved()) {
63-
$pendingTuples++;
64-
$tupleProperty->onResolve(function () use (&$pendingTuples): void {
65-
if (--$pendingTuples === 0) {
66-
$this->resolve();
67-
}
68-
});
69-
}
70-
7161
$this->tupleProperties[] = $tupleProperty;
7262
}
7363

74-
if ($pendingTuples === 0) {
75-
$this->resolve();
76-
}
64+
$this->resolve();
7765

7866
parent::__construct(
7967
new Property($propertyName, null, $propertiesStructure),

tests/AbstractPHPModelGeneratorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ protected function assertErrorRegistryContainsException(
417417
$this->fail("Error exception $expectedException not found in error registry exception");
418418
}
419419

420-
public function validationMethodDataProvider(): array {
420+
public function validationMethodDataProvider(): array
421+
{
421422
return [
422423
'Error Collection' => [new GeneratorConfiguration()],
423424
'Direct Exception' => [(new GeneratorConfiguration())->setCollectErrors(false)],

tests/Basic/IdenticalNestedSchemaTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function testIdenticalReferencedSchemaInMultipleFilesAreMappedToOneClass(
9797
$this->assertSame(get_class($object1->getMember()), get_class($object2->getMember()));
9898
}
9999

100-
public function identicalReferencedSchemaDataProvider()
100+
public function identicalReferencedSchemaDataProvider(): array
101101
{
102102
return [
103103
'In same namespace' => [

tests/Objects/MultiTypePropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function testInvalidProvidedValueThrowsAnException($propertyValue, string
120120
new $className(['property' => $propertyValue]);
121121
}
122122

123-
public function invalidValueDataProvider()
123+
public function invalidValueDataProvider(): array
124124
{
125125
return [
126126
'Bool' => [true, 'Invalid type for property. Requires [float, string, array], got boolean'],

tests/Objects/TupleArrayPropertyTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPModelGenerator\Tests\Objects;
44

5+
use PHPModelGenerator\Exception\Arrays\InvalidTupleException;
56
use PHPModelGenerator\Exception\FileSystemException;
67
use PHPModelGenerator\Exception\RenderException;
78
use PHPModelGenerator\Exception\SchemaException;
@@ -418,4 +419,48 @@ public function invalidObjectAdditionalItemsDataProvider(): array
418419
]
419420
);
420421
}
422+
423+
/**
424+
* @dataProvider validRecursiveTupleDataProvider
425+
*/
426+
public function testValidRecursiveTuple(array $input): void
427+
{
428+
$className = $this->generateClassFromFile('RecursiveTupleArray.json');
429+
430+
$object = new $className(['property' => $input]);
431+
432+
$this->assertSame($input, $object->getProperty());
433+
}
434+
435+
public function validRecursiveTupleDataProvider(): array
436+
{
437+
return [
438+
'string' => [['abc', 'def']],
439+
'one level nested' => [['abc', ['abc', 'def']]],
440+
'two level nested' => [['abc', ['abc', ['abc', 'def']]]],
441+
];
442+
}
443+
444+
/**
445+
* @dataProvider invalidRecursiveTupleDataProvider
446+
*/
447+
public function testInvalidRecursiveTuple(array $input): void
448+
{
449+
$this->expectException(InvalidTupleException::class);
450+
451+
$className = $this->generateClassFromFile('RecursiveTupleArray.json');
452+
453+
new $className(['property' => $input]);
454+
}
455+
456+
public function invalidRecursiveTupleDataProvider(): array
457+
{
458+
return [
459+
'invalid first tuple' => [[1, 'def']],
460+
'invalid second tuple' => [['abc', 1]],
461+
'one level nested - invalid first tuple' => [[1, ['abc', 'def']]],
462+
'one level nested - invalid nested first tuple' => [['abc', [1, 'def']]],
463+
'one level nested - invalid nested second tuple' => [['abc', ['abc', 1]]],
464+
];
465+
}
421466
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"definitions": {
3+
"list": {
4+
"type": "array",
5+
"items": [
6+
{
7+
"type": "string"
8+
},
9+
{
10+
"oneOf": [
11+
{
12+
"$ref": "#/definitions/list"
13+
},
14+
{
15+
"type": "string"
16+
}
17+
]
18+
}
19+
],
20+
"minItems": 1
21+
}
22+
},
23+
"type": "object",
24+
"properties": {
25+
"property": {
26+
"$ref": "#/definitions/list"
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)