1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SchemaGenerate\StructureGenerate\Generators; |
4
|
|
|
|
5
|
|
|
use SchemaGenerate\StructureGenerate\Data\Data; |
6
|
|
|
use SchemaGenerate\StructureGenerate\Data\GenerateData; |
7
|
|
|
use SchemaGenerate\StructureGenerate\Outputs\Output; |
8
|
|
|
use SchemaGenerate\StructureGenerate\Outputs\OutputRaw; |
9
|
|
|
use SchemaGenerate\StructureGenerate\Parsers\ParserStructure; |
10
|
|
|
use SchemaGenerate\StructureGenerate\Schemes\Schema; |
11
|
|
|
|
12
|
|
|
class GeneratorService implements Generator |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var ParserStructure |
16
|
|
|
*/ |
17
|
|
|
private $parserStructure; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Output |
21
|
|
|
*/ |
22
|
|
|
private $output; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var GenerateData |
26
|
|
|
*/ |
27
|
|
|
private $generateData; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
private $keysIndex = []; |
33
|
|
|
|
34
|
|
|
public function __construct(ParserStructure $generateObject, Output $output = null, Data $generateData = null) |
35
|
|
|
{ |
36
|
|
|
$this->setParserStructure($generateObject); |
37
|
|
|
$this->setOutput($output ?? new OutputRaw()); |
38
|
|
|
$this->setGenerateData($generateData ?? new GenerateData()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function setParserStructure(ParserStructure $parserStructure): Generator |
42
|
|
|
{ |
43
|
|
|
$this->parserStructure = $parserStructure; |
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function setOutput(Output $output): Generator |
48
|
|
|
{ |
49
|
|
|
$this->output = $output; |
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function setGenerateData(Data $generateData): Generator |
54
|
|
|
{ |
55
|
|
|
$this->generateData = $generateData; |
|
|
|
|
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function process(Schema $schemaStructure): array |
60
|
|
|
{ |
61
|
|
|
foreach ($schemaStructure->getSchema() as $keySchema => $schema) { |
62
|
|
|
$this->parserStructure->setSchema($schema); |
63
|
|
|
for ($i = 0; $i < $schemaStructure->getSettingCount($keySchema); $i++) { |
64
|
|
|
$this->generateData->set( |
65
|
|
|
$keySchema, |
66
|
|
|
$this->parserStructure->process($this->keysIndex) |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if ($schemaStructure->isKey($keySchema)) { |
71
|
|
|
$this->keysIndex[$keySchema] = array_column( |
72
|
|
|
$this->generateData->get($keySchema), |
73
|
|
|
$schemaStructure->getKey($keySchema) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $this->output->setData($this->generateData) |
79
|
|
|
->setSettings($schemaStructure->getSettingOutput()) |
80
|
|
|
->process(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.