Skip to content

Commit e6ba581

Browse files
committed
Fix #124 and improve build
1 parent 23ca47c commit e6ba581

File tree

8 files changed

+42
-35
lines changed

8 files changed

+42
-35
lines changed

build.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
</fileset>
1616
</delete>
1717

18+
<mkdir dir="${project.basedir}/build/coverage"/>
19+
<mkdir dir="${project.basedir}/build/logs"/>
20+
<mkdir dir="${project.basedir}/build/phar"/>
21+
<mkdir dir="${project.basedir}/build/out"/>
22+
<mkdir dir="${project.basedir}/build/tmp"/>
23+
1824
<property name="clean.done" value="true"/>
1925
</target>
2026

src/PHPDraft/Model/Elements/ElementStructureElement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function __toString(): string
4747
{
4848
$type = $this->get_element_as_html($this->type);
4949

50-
$desc = empty($this->description) ? '' : " - <span class=\"description\">{$this->description}</span>";
51-
$value = empty($this->value) ? '' : " - <span class=\"example-value pull-right\">{$this->value}</span>";
50+
$desc = is_null($this->description) ? '' : " - <span class=\"description\">{$this->description}</span>";
51+
$value = is_null($this->value) ? '' : " - <span class=\"example-value pull-right\">{$this->value}</span>";
5252
return '<li class="list-group-item mdl-list__item">' . $type . $desc . $value . '</li>';
5353
}
5454

src/PHPDraft/Model/Elements/ObjectStructureElement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __clearForTest()
4040
public function parse(?object $object, array &$dependencies): StructureElement
4141
{
4242
$this->object = $object;
43-
if (empty($object) || !isset($object->element) || !(isset($object->content) || isset($object->meta) )) {
43+
if (is_null($object) || !isset($object->element) || !(isset($object->content) || isset($object->meta) )) {
4444
return $this;
4545
}
4646

@@ -137,7 +137,7 @@ protected function parse_array_content(object $object, array &$dependencies): vo
137137
public function __toString(): string
138138
{
139139
$options = array_merge(self::DEFAULTS, ['member', 'select', 'option', 'ref', 'T', 'hrefVariables']);
140-
if (!empty($this->element) && !in_array($this->element, $options)) {
140+
if (!is_null($this->element) && !in_array($this->element, $options)) {
141141
$this->description = '<p>Inherits from <a href="#object-' . strtolower($this->element) . '">' . $this->element . '</a></p>' . $this->description;
142142
}
143143

src/PHPDraft/Model/HTTPRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function parse(object $object): self
104104
$this->method = $object->attributes->method->content ?? $object->attributes->method;
105105
$this->title = $object->meta->title->content ?? $object->meta->title ?? null;
106106

107-
if (!empty($object->content)) {
107+
if (isset($object->content) && $object->content !== NULL) {
108108
foreach ($object->content as $value) {
109109
if ($value->element === 'dataStructure') {
110110
$this->parse_structure($value);
@@ -192,15 +192,15 @@ public function get_curl_command(string $base_url, array $additional = []): stri
192192
$type = $this->headers['Content-Type'] ?? null;
193193

194194
$options[] = '-X' . $this->method;
195-
if (empty($this->body)) {
195+
if (is_null($this->body) || $this->body === []) {
196196
//NO-OP
197197
} elseif (is_string($this->body)) {
198198
$options[] = '--data-binary ' . escapeshellarg($this->body);
199199
} elseif (is_array($this->body)) {
200200
$options[] = '--data-binary ' . escapeshellarg(join('', $this->body));
201201
} elseif (is_subclass_of($this->struct, StructureElement::class)) {
202202
foreach ($this->struct->value as $body) {
203-
if (empty($body)) {
203+
if (is_null($body) || $body === []) {
204204
continue;
205205
}
206206
$options[] = '--data-binary ' . escapeshellarg(strip_tags($body->print_request($type)));

src/PHPDraft/Model/Transition.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public function parse(stdClass $object): self
112112
if (!isset($transition_item->content)) {
113113
continue;
114114
}
115+
$list = [];
115116
foreach ($transition_item->content as $item) {
116117
$value = null;
117118
if (!in_array($item->element, ['httpRequest', 'httpResponse'])) {
@@ -131,7 +132,7 @@ public function parse(stdClass $object): self
131132
}
132133
$value->parse($item);
133134

134-
if (empty($list)) {
135+
if ($list === []) {
135136
$list[] = $value;
136137
continue;
137138
}

src/PHPDraft/Out/HTML/default.phtml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use PHPDraft\Out\Minifier;
3737
<p class="lead"><?= $this->base_data['DESC']; ?></p>
3838
<?php endif;?>
3939
</div>
40-
<?php if (!empty($this->image)): ?>
40+
<?php if (!is_null($this->image)): ?>
4141
<div class="media-right">
4242
<a href="#">
4343
<img class="media-object" src="<?= $this->image ?>" alt="Image">
@@ -67,7 +67,7 @@ use PHPDraft\Out\Minifier;
6767
</nav>
6868
<?php endif; ?>
6969
<?php endforeach; ?>
70-
<?php if (!empty($this->base_structures)): ?>
70+
<?php if ($this->base_structures !== []): ?>
7171
<nav id="nav-datastructures" class="navbar navbar-light structures" aria-label="Data structures">
7272
<a class="navbar-brand" href="#<?= $category->get_href(); ?>">Data Structures</a>
7373
<?php foreach ($this->base_structures as $key => $structure): ?>
@@ -81,12 +81,12 @@ use PHPDraft\Out\Minifier;
8181
</nav>
8282
<div class="col-md-10 main-content">
8383
<?php foreach ($this->categories as &$category): ?>
84-
<?php if (!empty($category->title)): ?>
84+
<?php if (!is_null($category->title)): ?>
8585
<h2>
8686
<a id="<?= $category->get_href(); ?>" data-anchor-id="<?= $category->get_href(); ?>"><?= $category->title; ?></a>
8787
</h2>
8888
<?php endif; ?>
89-
<?php if (!empty($category->description)): ?>
89+
<?php if (!is_null($category->description)): ?>
9090
<p><?= $category->description; ?></p>
9191
<?php endif; ?>
9292
<?php foreach ($category->children as $resource): ?>
@@ -98,7 +98,7 @@ use PHPDraft\Out\Minifier;
9898
</a>
9999
<small><?= $resource->href; ?></small>
100100
</h3>
101-
<?php if (!empty($resource->description)): ?>
101+
<?php if (!is_null($resource->description)): ?>
102102
<p><?= $resource->description; ?></p>
103103
<?php endif; ?>
104104
<?php if ($resource->url_variables !== null): ?>
@@ -123,14 +123,14 @@ use PHPDraft\Out\Minifier;
123123
</div>
124124
<div class="card-body">
125125
<p class="lead"><?= $transition->description; ?></p>
126-
<?php if (!empty($transition->requests)): ?>
126+
<?php if ($transition->requests !== []): ?>
127127
<?php foreach ($transition->requests as $key => $request): ?>
128128
<div class="card">
129129
<div class="card-header">
130130
<h6 class="request card-title"
131131
data-toggle="collapse"
132132
data-target="#request-coll-<?= $request->get_id(); ?>">Request
133-
<?php if (!empty($request->title)): ?>
133+
<?php if (!is_null($request->title)): ?>
134134
<var><?= $request->title;?></var>
135135
<?php endif;?>
136136
<span class="fas indicator fa-angle-down float-right"></span>
@@ -168,7 +168,7 @@ use PHPDraft\Out\Minifier;
168168
<?php endforeach; ?>
169169
</ul>
170170
<?php endif; ?>
171-
<?php if (!empty($request->body)): ?>
171+
<?php if ($request->body !== []): ?>
172172
<h5>Body</h5>
173173
<?php foreach ($request->body as $value): ?>
174174
<?php if (is_string($value)): ?>
@@ -181,7 +181,7 @@ use PHPDraft\Out\Minifier;
181181
<?php endif; ?>
182182
<?php endforeach; ?>
183183
<?php endif; ?>
184-
<?php if (!empty($request->struct)): ?>
184+
<?php if ($request->struct !== []): ?>
185185
<h5>Structure</h5>
186186
<div class="row">
187187
<?= $request->struct ?>
@@ -294,7 +294,7 @@ use PHPDraft\Out\Minifier;
294294
<?php $extras = array_filter($this->base_data, function ($value) {
295295
return !in_array($value, ['HOST', 'TITLE', 'ALT_HOST', 'FORMAT', 'DESC', 'COLOR_1', 'COLOR_2']);
296296
}, ARRAY_FILTER_USE_KEY);
297-
if (!empty($extras)):
297+
if ($extras !== []):
298298
$extras['host'] = $this->base_data['HOST']; ?>
299299
<button
300300
type="button"

src/PHPDraft/Out/HTML/material.phtml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
5353
<?php endforeach; ?>
5454
<?php endif; ?>
5555
<?php endforeach; ?>
56-
<?php if (!empty($this->base_structures)): ?>
56+
<?php if ($this->base_structures !== []): ?>
5757
<a class="mdl-navigation__link" href="#"><strong>Objects</strong></a>
5858
<?php foreach ($this->base_structures as $key => $structure): ?>
5959
<a class="mdl-navigation__link"
@@ -65,18 +65,18 @@ use Enjoy\HttpStatusCode\Statuscodes;
6565
<main class="mdl-layout__content main-content">
6666
<div class="page-content">
6767
<?php foreach ($this->categories as $category): ?>
68-
<?php if (!empty($category->title)): ?>
68+
<?php if (!is_null($category->title)): ?>
6969
<h3><a id="<?= $category->get_href(); ?>"><?= $category->title; ?></a></h3>
7070
<?php endif; ?>
71-
<?php if (!empty($category->description)): ?>
71+
<?php if (!is_null($category->description)): ?>
7272
<p><?= $category->description; ?></p>
7373
<?php endif; ?>
7474
<?php foreach ($category->children as $resource): ?>
7575
<h4>
7676
<a id="<?= str_replace('-', '/', $resource->get_href()); ?>"><?= $resource->title; ?></a>
7777
<small><?= $resource->href; ?></small>
7878
</h4>
79-
<?php if (!empty($resource->description)): ?>
79+
<?php if (!is_null($resource->description)): ?>
8080
<p><?= $resource->description; ?></p>
8181
<?php endif; ?>
8282
<?php foreach ($resource->children as $transition): ?>
@@ -90,26 +90,26 @@ use Enjoy\HttpStatusCode\Statuscodes;
9090
</div>
9191
<div class="mdl-card__supporting-text">
9292
<?= $transition->description; ?>
93-
<?php if (!empty($transition->requests) || !empty($transition->responses)): $i = 0;?>
93+
<?php if (!is_null($transition->requests) || !is_null($transition->responses)): $i = 0;?>
9494
<div class="mdl-tabs mdl-js-tabs mdl-js-ripple-effect">
9595
<div class="mdl-tabs__tab-bar">
96-
<?php if (!empty($transition->requests)): ?>
96+
<?php if ($transition->requests !== []): ?>
9797
<?php foreach ($transition->requests as $request): ?>
9898
<a href="#request-panel-<?= $request->get_id(); ?>"
9999
class="mdl-tabs__tab<?= ($i < 1) ? ' is-active' : '' ?>">
100-
<strong>Request</strong> <?= (empty($request->title) ? '' : ' ' . $request->title) ?>
100+
<strong>Request</strong> <?= is_null($request->title ? '' : ' ' . $request->title) ?>
101101
</a>
102102
<?php $i++; endforeach; ?>
103103
<?php endif; ?>
104-
<?php if (!empty($transition->responses)): ?>
104+
<?php if ($transition->responses !== []): ?>
105105
<?php foreach ($transition->responses as $response): ?>
106106
<a href="#response-panel-<?= $response->get_id(); ?>"
107107
class="mdl-tabs__tab<?= ($i < 1) ? ' is-active' : '' ?> <?= $this->get_response_status($response->statuscode) ?>"
108108
title="<?= $response->statuscode . ' ' . $this->http_status->getReasonPhrase($response->statuscode) ?>"><?= $response->statuscode; ?></a>
109109
<?php $i++; endforeach; ?>
110110
<?php endif; ?>
111111
</div>
112-
<?php $i = 0; if (!empty($transition->requests)): ?>
112+
<?php $i = 0; if (!$transition->requests !== []): ?>
113113
<?php foreach ($transition->requests as $key => $request): ?>
114114
<dialog class="mdl-dialog"
115115
id="mdl-dialog-<?= $request->get_id(); ?>">
@@ -148,7 +148,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
148148
<?php endforeach; ?>
149149
</ul>
150150
<?php endif; ?>
151-
<?php if (!empty($request->body)): ?>
151+
<?php if ($request->body !== []): ?>
152152
<h5>Body</h5>
153153
<?php foreach ($request->body as $value): ?>
154154
<?php if (is_string($value)): ?>
@@ -161,7 +161,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
161161
<?php endif; ?>
162162
<?php endforeach; ?>
163163
<?php endif; ?>
164-
<?php if (!empty($request->struct)): ?>
164+
<?php if ($request->struct !== []): ?>
165165
<h5>Structure</h5>
166166
<?= $request->struct ?>
167167
<?php endif; ?>
@@ -176,7 +176,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
176176
</div>
177177
<?php $i++; endforeach; ?>
178178
<?php endif; ?>
179-
<?php if (!empty($transition->responses)): ?>
179+
<?php if ($transition->responses !== []): ?>
180180
<?php foreach ($transition->responses as $key => $response): ?>
181181
<div class="mdl-tabs__panel <?= ($i < 1) ? 'is-active' : '' ?>"
182182
id="response-panel-<?= $response->get_id(); ?>">
@@ -201,9 +201,9 @@ use Enjoy\HttpStatusCode\Statuscodes;
201201
<?php endforeach; ?>
202202
<?php endif; ?>
203203
<div class="mdl-grid">
204-
<?php foreach ($response->content as $key => $value): ?>
204+
<?php foreach ($response->content as $response_key => $value): ?>
205205
<div class="mdl-cell mdl-cell--<?= 12 / count($response->content) ?>-col">
206-
<h5 class="response-body"><?= $key; ?></h5>
206+
<h5 class="response-body"><?= $response_key; ?></h5>
207207
<pre class="response-body"
208208
id="request-<?= $response->get_id(); ?>"><?= $value; ?></pre>
209209
</div>
@@ -240,7 +240,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
240240
<?php $extras = array_filter($this->base_data, function ($value) {
241241
return !in_array($value, ['HOST', 'TITLE', 'ALT_HOST', 'FORMAT', 'DESC', 'COLOR_1', 'COLOR_2']);
242242
}, ARRAY_FILTER_USE_KEY);
243-
if (!empty($extras)):
243+
if ($extras !== []):
244244
$extras['host'] = $this->base_data['HOST']; ?>
245245
<button
246246
type="button"

src/PHPDraft/Parse/HtmlGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public function get_html(string $template = 'default', ?string $image = null, ?s
3636
{
3737
$gen = new TemplateGenerator($template, $image);
3838

39-
if (!empty($css)) {
39+
if (!is_null($css)) {
4040
$gen->css[] = explode(',', $css);
4141
}
4242

43-
if (!empty($js)) {
43+
if (!is_null($js)) {
4444
$gen->js[] = explode(',', $js);
4545
}
4646

0 commit comments

Comments
 (0)