Skip to content

Commit 277e7b3

Browse files
committed
Object: Fix inheritance view
1 parent ce973b1 commit 277e7b3

File tree

7 files changed

+83
-11
lines changed

7 files changed

+83
-11
lines changed

src/PHPDraft/Model/Elements/BasicStructureElement.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ abstract class BasicStructureElement implements StructureElement
6868
/**
6969
* Parse a JSON object to a structure.
7070
*
71-
* @param object $object An object to parse
72-
* @param array $dependencies Dependencies of this object
71+
* @param object|null $object An object to parse
72+
* @param array $dependencies Dependencies of this object
7373
*
7474
* @return StructureElement self reference
7575
*/
@@ -150,7 +150,7 @@ protected function parse_common(object $object, array &$dependencies): void
150150
*
151151
* @return string HTML string
152152
*/
153-
protected function get_element_as_html($element): string
153+
protected function get_element_as_html(string $element): string
154154
{
155155
if (in_array($element, self::DEFAULTS)) {
156156
return '<code>' . $element . '</code>';
@@ -167,7 +167,7 @@ protected function get_element_as_html($element): string
167167
*
168168
* @return string
169169
*/
170-
public function string_value($flat = false)
170+
public function string_value(bool $flat = false)
171171
{
172172
if (is_array($this->value)) {
173173
$value_key = rand(0, count($this->value));

src/PHPDraft/Model/Elements/ObjectStructureElement.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ protected function parse_array_content(object $object, array &$dependencies): vo
136136
*/
137137
public function __toString(): string
138138
{
139-
$options = array_merge(self::DEFAULTS, ['member', 'select', 'option', 'ref', 'T', 'hrefVariables']);
140-
if (!is_null($this->element) && !in_array($this->element, $options)) {
141-
$this->description = '<p>Inherits from <a href="#object-' . strtolower($this->element) . '">' . $this->element . '</a></p>' . $this->description;
142-
}
143-
144139
if (is_array($this->value)) {
145140
$return = '';
146141
foreach ($this->value as $object) {
@@ -203,7 +198,7 @@ protected function construct_string_return(string $value): string
203198

204199
$type = $this->get_element_as_html($this->type);
205200
$variable = '';
206-
if ($this->is_variable) {
201+
if ($this->is_variable === TRUE) {
207202
$link_name = str_replace(' ', '-', strtolower($this->key->type));
208203
$tooltip = 'This is a variable key of type &quot;' . $this->key->type . '&quot;';
209204
$variable = '<a class="variable-key" title="' . $this->key->type . '" href="#object-' . $link_name . '"><span class="fas fa-info variable-info" data-toggle="tooltip" data-placement="top" data-tooltip="' . $tooltip . '" title="' . $tooltip . '"></span></a>';

src/PHPDraft/Model/Elements/StructureElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ public function __toString(): string;
4646
*
4747
* @return string
4848
*/
49-
public function string_value($flat = false);
49+
public function string_value(bool $flat = false);
5050
}

src/PHPDraft/Out/HTML/default/structure.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
{% if structure.ref %}
99
<p>Inherits from <a href="#object-{{ structure.ref|lower }}">{{ structure.ref }}</a></p>
1010
{% endif %}
11+
{% if structure is inheriting %}<p>Inherits from <a href="#object-{{ structure.element|lower }}">{{ structure.element }}</a></p>{% endif %}
1112
{% if structure.description %}{{ structure.description|markdown_to_html }}{% endif %}
1213
<div class="row">
1314
{% if structure.value is iterable %}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{% if value is bool %}
2+
<span class="example-value pull-right">{% if value %}true{% else %}false{% endif %}</span>
3+
{% elseif value is array_type %}
4+
<div class="array-struct">
5+
{% if value.value is iterable %}
6+
<ul class="list-group mdl-list">
7+
{% for value in value.value %}
8+
{% include 'value.twig' %}
9+
{% endfor %}
10+
</ul>
11+
{% elseif value.value is string %}
12+
<tr><td>{{ value.key }}</td><td>{{ value.get_element_as_html(value.type) }}</td><td>{{ value.description }}</td></tr>
13+
{% endif %}
14+
</div>
15+
{% elseif value is enum_type %}
16+
<div class="enum-struct">
17+
{% if value.value is iterable %}
18+
<ul class="list-group mdl-list">
19+
{% for value in value.value %}
20+
{% include 'value.twig' %}
21+
{% endfor %}
22+
</ul>
23+
{% elseif value.value is string %}
24+
<tr><td>{{ value.key.value }}</td><td>{{ value.get_element_as_html(value.type) }}</td><td>{{ value.description }}</td></tr>
25+
{% endif %}
26+
</div>
27+
{% elseif value is string %}
28+
<span class="example-value pull-right">{{ value }}</span>
29+
{% else %}
30+
{{ value|raw }}
31+
{% endif %}

src/PHPDraft/Out/TwigFactory.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use MatthiasMullie\Minify\CSS;
99
use MatthiasMullie\Minify\JS;
1010
use PHPDraft\Model\Elements\ArrayStructureElement;
11+
use PHPDraft\Model\Elements\BasicStructureElement;
1112
use PHPDraft\Model\Elements\EnumStructureElement;
1213
use PHPDraft\Model\Elements\ObjectStructureElement;
1314
use Twig\Environment;
@@ -55,6 +56,21 @@ public static function get(LoaderInterface $loader): Environment {
5556
$twig->addTest(new TwigTest('array_type', function ($object) {
5657
return $object instanceof ArrayStructureElement;
5758
}));
59+
$twig->addTest(new TwigTest('bool', function ($object) {
60+
return is_bool($object);
61+
}));
62+
$twig->addTest(new TwigTest('string', function ($object) {
63+
return is_string($object);
64+
}));
65+
66+
$twig->addTest(new TwigTest('inheriting', function (BasicStructureElement $object) {
67+
$options = array_merge(ObjectStructureElement::DEFAULTS, ['member', 'select', 'option', 'ref', 'T', 'hrefVariables']);
68+
return !(is_null($object->element) || in_array($object->element, $options));
69+
}));
70+
$twig->addTest(new TwigTest('variable_type', function (BasicStructureElement $object) {
71+
return $object->is_variable;
72+
}));
73+
5874
$twig->addRuntimeLoader(new class implements RuntimeLoaderInterface {
5975
public function load($class) {
6076
if (MarkdownRuntime::class === $class) {

tests/statics/full_test.apib

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,30 @@ containing a question and a collection of answers in the form of choices.
410410

411411
[My Resource][]
412412

413+
+ Response 400
414+
415+
[My Resource][]
416+
417+
+ Response 401
418+
419+
[My Resource][]
420+
421+
+ Response 403
422+
423+
[My Resource][]
424+
425+
+ Response 500
426+
427+
[My Resource][]
428+
429+
+ Response 501
430+
431+
[My Resource][]
432+
433+
+ Response 502
434+
435+
[My Resource][]
436+
413437
# Data Structures
414438

415439

@@ -516,3 +540,8 @@ User of the application
516540
+ string1_l4 (string) - String in L4
517541
+ string2_l4 (string) - String in L4
518542
+ string3_l4 (string) - String in L4
543+
544+
545+
## Description only (object)
546+
+ Object (object) - Main
547+
+ test

0 commit comments

Comments
 (0)