Skip to content

Commit bc569e3

Browse files
committed
* Extended type hints for properties which are composed to contain all possible types (eg. int|string|null) yad! Yet Another Decorator
* Fix SplObject access * Fix Out of memory error due to recursive logging
1 parent 3b10a5e commit bc569e3

23 files changed

+114
-53
lines changed

src/Model/Property/Property.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use PHPModelGenerator\Model\Schema;
88
use PHPModelGenerator\Model\Validator;
99
use PHPModelGenerator\Model\Validator\PropertyValidatorInterface;
10-
use PHPModelGenerator\PropertyProcessor\Decorator\PropertyDecoratorInterface;
11-
use PHPModelGenerator\PropertyProcessor\Decorator\TypeHintDecoratorInterface;
10+
use PHPModelGenerator\PropertyProcessor\Decorator\Property\PropertyDecoratorInterface;
11+
use PHPModelGenerator\PropertyProcessor\Decorator\TypeHint\TypeHintDecoratorInterface;
1212

1313
/**
1414
* Class Property
@@ -93,13 +93,13 @@ public function setType(string $type): PropertyInterface
9393
*/
9494
public function getTypeHint(): string
9595
{
96-
$input = $this->type ?: 'mixed';
96+
$input = $this->type;
9797

9898
foreach ($this->typeHintDecorators as $decorator) {
9999
$input = $decorator->decorate($input);
100100
}
101101

102-
return $input;
102+
return $input ?? 'mixed';
103103
}
104104

105105
/**

src/Model/Property/PropertyInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use PHPModelGenerator\Model\Schema;
88
use PHPModelGenerator\Model\Validator;
99
use PHPModelGenerator\Model\Validator\PropertyValidatorInterface;
10-
use PHPModelGenerator\PropertyProcessor\Decorator\PropertyDecoratorInterface;
11-
use PHPModelGenerator\PropertyProcessor\Decorator\TypeHintDecoratorInterface;
10+
use PHPModelGenerator\PropertyProcessor\Decorator\Property\PropertyDecoratorInterface;
11+
use PHPModelGenerator\PropertyProcessor\Decorator\TypeHint\TypeHintDecoratorInterface;
1212

1313
/**
1414
* Interface PropertyInterface

src/Model/Property/PropertyProxy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use PHPModelGenerator\Model\SchemaDefinition\ResolvedDefinitionsCollection;
88
use PHPModelGenerator\Model\Schema;
99
use PHPModelGenerator\Model\Validator\PropertyValidatorInterface;
10-
use PHPModelGenerator\PropertyProcessor\Decorator\PropertyDecoratorInterface;
11-
use PHPModelGenerator\PropertyProcessor\Decorator\TypeHintDecoratorInterface;
10+
use PHPModelGenerator\PropertyProcessor\Decorator\Property\PropertyDecoratorInterface;
11+
use PHPModelGenerator\PropertyProcessor\Decorator\TypeHint\TypeHintDecoratorInterface;
1212

1313
/**
1414
* Class PropertyProxy

src/Model/Validator/PropertyTemplateValidator.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,7 @@ public function getCheck(): string
6060
try {
6161
return static::$renderer->renderTemplate($this->template, $this->templateValues);
6262
} catch (PHPMicroTemplateException $exception) {
63-
throw new RenderException(
64-
"Can't render property validation template {$this->template} with values " .
65-
print_r($this->templateValues, true),
66-
0,
67-
$exception
68-
);
63+
throw new RenderException("Can't render property validation template {$this->template}", 0, $exception);
6964
}
7065
}
7166
}

src/ModelGenerator.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ public function generateModelDirectory(string $modelPath, int $directoryMode = 0
5252
}
5353

5454
$di = new RecursiveDirectoryIterator($modelPath, FilesystemIterator::SKIP_DOTS);
55-
5655
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
5756

58-
foreach ($ri as $file ) {
59-
$file->isDir() ? rmdir($file) : unlink($file);
57+
foreach ($ri as $file) {
58+
$file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath());
6059
}
6160

6261
return $this;

src/PropertyProcessor/ComposedValue/AbstractComposedValueProcessor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPModelGenerator\Model\Validator;
1010
use PHPModelGenerator\Model\Validator\ComposedPropertyValidator;
1111
use PHPModelGenerator\Model\Validator\RequiredPropertyValidator;
12+
use PHPModelGenerator\PropertyProcessor\Decorator\TypeHint\CompositionTypeHintDecorator;
1213
use PHPModelGenerator\PropertyProcessor\Property\AbstractValueProcessor;
1314
use PHPModelGenerator\PropertyProcessor\PropertyCollectionProcessor;
1415
use PHPModelGenerator\PropertyProcessor\PropertyFactory;
@@ -48,6 +49,8 @@ protected function generateValidators(PropertyInterface $property, array $proper
4849
!is_a($validator->getValidator(), ComposedPropertyValidator::class);
4950
});
5051

52+
$property->addTypeHintDecorator(new CompositionTypeHintDecorator($compositionProperty));
53+
5154
$properties[] = $compositionProperty;
5255
}
5356

src/PropertyProcessor/Decorator/IntToFloatCastDecorator.php renamed to src/PropertyProcessor/Decorator/Property/IntToFloatCastDecorator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
declare(strict_types = 1);
44

5-
namespace PHPModelGenerator\PropertyProcessor\Decorator;
5+
namespace PHPModelGenerator\PropertyProcessor\Decorator\Property;
66

77
use PHPModelGenerator\Model\Property\PropertyInterface;
88

99
/**
1010
* Class IntToFloatCastDecorator
1111
*
12-
* @package PHPModelGenerator\PropertyProcessor\Decorator
12+
* @package PHPModelGenerator\PropertyProcessor\Decorator\Property
1313
*/
1414
class IntToFloatCastDecorator implements PropertyDecoratorInterface
1515
{

src/PropertyProcessor/Decorator/ObjectInstantiationDecorator.php renamed to src/PropertyProcessor/Decorator/Property/ObjectInstantiationDecorator.php

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

33
declare(strict_types = 1);
44

5-
namespace PHPModelGenerator\PropertyProcessor\Decorator;
5+
namespace PHPModelGenerator\PropertyProcessor\Decorator\Property;
66

77
use PHPMicroTemplate\Render;
88
use PHPModelGenerator\Exception\InvalidArgumentException;
@@ -11,7 +11,7 @@
1111
/**
1212
* Class ObjectInstantiationDecorator
1313
*
14-
* @package PHPModelGenerator\PropertyProcessor\Decorator
14+
* @package PHPModelGenerator\PropertyProcessor\Decorator\Property
1515
*/
1616
class ObjectInstantiationDecorator implements PropertyDecoratorInterface
1717
{
@@ -31,7 +31,7 @@ public function __construct(string $className)
3131

3232
if (!static::$renderer) {
3333
static::$renderer = new Render(
34-
join(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', 'Templates']) . DIRECTORY_SEPARATOR
34+
join(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', '..', 'Templates']) . DIRECTORY_SEPARATOR
3535
);
3636
}
3737
}

src/PropertyProcessor/Decorator/PropertyDecoratorInterface.php renamed to src/PropertyProcessor/Decorator/Property/PropertyDecoratorInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
declare(strict_types = 1);
44

5-
namespace PHPModelGenerator\PropertyProcessor\Decorator;
5+
namespace PHPModelGenerator\PropertyProcessor\Decorator\Property;
66

77
use PHPModelGenerator\Model\Property\PropertyInterface;
88

99
/**
1010
* Interface PropertyDecoratorInterface
1111
*
12-
* @package PHPModelGenerator\PropertyProcessor\Decorator
12+
* @package PHPModelGenerator\PropertyProcessor\Decorator\Property
1313
*/
1414
interface PropertyDecoratorInterface
1515
{

src/PropertyProcessor/Decorator/PropertyTransferDecorator.php renamed to src/PropertyProcessor/Decorator/Property/PropertyTransferDecorator.php

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

33
declare(strict_types = 1);
44

5-
namespace PHPModelGenerator\PropertyProcessor\Decorator;
5+
namespace PHPModelGenerator\PropertyProcessor\Decorator\Property;
66

77
use PHPModelGenerator\Model\Property\Property;
88
use PHPModelGenerator\Model\Property\PropertyInterface;
@@ -12,7 +12,7 @@
1212
*
1313
* Can be used to transfer the decorators of one property to another
1414
*
15-
* @package PHPModelGenerator\PropertyProcessor\Decorator
15+
* @package PHPModelGenerator\PropertyProcessor\Decorator\Property
1616
*/
1717
class PropertyTransferDecorator implements PropertyDecoratorInterface
1818
{

0 commit comments

Comments
 (0)