Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PHPDraft/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function parse(object $object): self
$struct->deps = $deps;
$struct->parse($item->content, $deps);

if (isset($item->content->content[0]->meta->id)) {
if (isset($item->content->content) && is_array($item->content->content) && isset($item->content->content[0]->meta->id)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this related to the rest of the changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because the $item->content->content is not an array when there is only one enumeration.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it an object then?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in my case it is the value of the enum. In the test you can see an example and there it is a string, see https://github.com/SMillerDev/phpdraft/pull/681/files#diff-b33b2099416ec2a729244bddbbf8f2f3125952aa5d11a6bdfb87f28eef655cbaR335-R337

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this could be a separate PR, because this change on it's own solve the issues we have right now. i also miss a test for this change

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my personal project I've done worse things for commit grouping. But whatever people do, the CI has to pass.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason i said it should be a separate PR, because then that could be merged earlier/separately

$this->structures[$item->content->content[0]->meta->id] = $struct;
} elseif (isset($item->content->meta->id->content)) {
$this->structures[$item->content->meta->id->content] = $struct;
Expand Down
15 changes: 8 additions & 7 deletions src/PHPDraft/Model/Elements/EnumStructureElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ public function parse(?object $object, array &$dependencies): self
$dependencies[] = $object->content->element;
}
$this->value = $object->content->content;
$this->deps = $dependencies;

return $this;
}

foreach ($object->attributes->enumerations->content as $sub_item) {
$element = new ElementStructureElement();
$element->parse($sub_item, $dependencies);
$this->value[] = $element;
if (isset($object->attributes->enumerations->content) && $object->attributes->enumerations->content !== []) {
$this->value = [];

foreach ($object->attributes->enumerations->content as $sub_item) {
$element = new ElementStructureElement();
$element->parse($sub_item, $dependencies);
$this->value[] = $element;
}
}

$this->deps = $dependencies;
Expand Down
51 changes: 51 additions & 0 deletions src/PHPDraft/Model/Elements/Tests/EnumStructureElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ public static function parseObjectProvider(): array
$base3->is_variable = false;
$base3->deps = [];

$base4 = new EnumStructureElement();
$base4->key = new ElementStructureElement();
$base4->value = [ $value1 ];
$base4->key->type = 'string';
$base4->key->value = 'item';
$base4->status = [];
$base4->element = 'enum';
$base4->type = 'Some simple enum';
$base4->is_variable = false;
$base4->description = null;
$base4->ref = null;
$base4->deps = ['Some simple enum'];

$return['base enum'] = [
'{
"element":"enum",
Expand Down Expand Up @@ -288,6 +301,44 @@ public static function parseObjectProvider(): array
}',
$base3,
];
$return['enum with single enumeration and content'] = [
'{
"element":"enum",
"meta":{
"id":{
"element":"string",
"content":"Some simple enum"
}
},
"attributes":{
"enumerations":{
"element":"array",
"content":[
{
"element":"string",
"attributes":{
"typeAttributes":{
"element":"array",
"content":[
{
"element":"string",
"content":"fixed"
}
]
}
},
"content":"item"
}
]
}
},
"content": {
"element": "string",
"content": "item"
}
}',
$base4,
];

return $return;
}
Expand Down