Skip to content

Commit 4444edc

Browse files
committed
added normalization classes.
1 parent 4297baf commit 4444edc

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/Service/Generator/Normalization/Processors/ConstraintProcessor.php

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

33
namespace N3XT0R\MigrationGenerator\Service\Generator\Normalization\Processors;
44

5+
use N3XT0R\MigrationGenerator\Service\Generator\Definition\Entity\ResultEntity;
6+
57
class ConstraintProcessor implements ProcessorInterface
68
{
9+
public function __invoke(ResultEntity $result): ResultEntity
10+
{
11+
return $result;
12+
}
713

814
}

src/Service/Generator/Normalization/Processors/PivotProcessor.php

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

33
namespace N3XT0R\MigrationGenerator\Service\Generator\Normalization\Processors;
44

5+
use N3XT0R\MigrationGenerator\Service\Generator\Definition\Entity\ResultEntity;
6+
57
class PivotProcessor implements ProcessorInterface
68
{
9+
public function __invoke(ResultEntity $result): ResultEntity
10+
{
11+
return $result;
12+
}
713

814
}

src/Service/Generator/Normalization/Processors/ProcessorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
interface ProcessorInterface
88
{
9-
public function process(ResultEntity $result): ResultEntity;
9+
public function __invoke(ResultEntity $result): ResultEntity;
1010
}

src/Service/Generator/Normalization/SchemaNormalizationManager.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
class SchemaNormalizationManager implements SchemaNormalizationManagerInterface
1818
{
1919
/**
20-
* @var ProcessorInterface[]
20+
* @var ProcessorInterface|\Closure[]
2121
*/
22-
protected iterable $processors = [];
22+
protected array $processors = [];
2323

2424
/**
2525
* SchemaNormalizationManager constructor.
@@ -36,7 +36,7 @@ public function __construct(iterable $processors = [])
3636
/**
3737
* Adds a new processor to the normalization chain.
3838
*/
39-
public function addProcessor(ProcessorInterface|iterable $processor): void
39+
public function addProcessor(ProcessorInterface|\Closure $processor): void
4040
{
4141
$this->processors[] = $processor;
4242
}
@@ -61,7 +61,10 @@ public function normalize(ResultEntity $result): ResultEntity
6161
{
6262
$processors = $this->getProcessors();
6363
foreach ($processors as $processor) {
64-
$result = $processor->process($result);
64+
if (!is_callable($processor)) {
65+
throw new \LogicException('Processor is not callable.');
66+
}
67+
$result = $processor($result);
6568
}
6669

6770
return $result;

0 commit comments

Comments
 (0)