Skip to content

Commit

Permalink
Fix #124 and improve build
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Jun 30, 2020
1 parent 23ca47c commit e6ba581
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 35 deletions.
6 changes: 6 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
</fileset>
</delete>

<mkdir dir="${project.basedir}/build/coverage"/>
<mkdir dir="${project.basedir}/build/logs"/>
<mkdir dir="${project.basedir}/build/phar"/>
<mkdir dir="${project.basedir}/build/out"/>
<mkdir dir="${project.basedir}/build/tmp"/>

<property name="clean.done" value="true"/>
</target>

Expand Down
4 changes: 2 additions & 2 deletions src/PHPDraft/Model/Elements/ElementStructureElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public function __toString(): string
{
$type = $this->get_element_as_html($this->type);

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

Expand Down
4 changes: 2 additions & 2 deletions src/PHPDraft/Model/Elements/ObjectStructureElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __clearForTest()
public function parse(?object $object, array &$dependencies): StructureElement
{
$this->object = $object;
if (empty($object) || !isset($object->element) || !(isset($object->content) || isset($object->meta) )) {
if (is_null($object) || !isset($object->element) || !(isset($object->content) || isset($object->meta) )) {
return $this;
}

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

Expand Down
6 changes: 3 additions & 3 deletions src/PHPDraft/Model/HTTPRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function parse(object $object): self
$this->method = $object->attributes->method->content ?? $object->attributes->method;
$this->title = $object->meta->title->content ?? $object->meta->title ?? null;

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

$options[] = '-X' . $this->method;
if (empty($this->body)) {
if (is_null($this->body) || $this->body === []) {
//NO-OP
} elseif (is_string($this->body)) {
$options[] = '--data-binary ' . escapeshellarg($this->body);
} elseif (is_array($this->body)) {
$options[] = '--data-binary ' . escapeshellarg(join('', $this->body));
} elseif (is_subclass_of($this->struct, StructureElement::class)) {
foreach ($this->struct->value as $body) {
if (empty($body)) {
if (is_null($body) || $body === []) {
continue;
}
$options[] = '--data-binary ' . escapeshellarg(strip_tags($body->print_request($type)));
Expand Down
3 changes: 2 additions & 1 deletion src/PHPDraft/Model/Transition.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function parse(stdClass $object): self
if (!isset($transition_item->content)) {
continue;
}
$list = [];
foreach ($transition_item->content as $item) {
$value = null;
if (!in_array($item->element, ['httpRequest', 'httpResponse'])) {
Expand All @@ -131,7 +132,7 @@ public function parse(stdClass $object): self
}
$value->parse($item);

if (empty($list)) {
if ($list === []) {
$list[] = $value;
continue;
}
Expand Down
20 changes: 10 additions & 10 deletions src/PHPDraft/Out/HTML/default.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use PHPDraft\Out\Minifier;
<p class="lead"><?= $this->base_data['DESC']; ?></p>
<?php endif;?>
</div>
<?php if (!empty($this->image)): ?>
<?php if (!is_null($this->image)): ?>
<div class="media-right">
<a href="#">
<img class="media-object" src="<?= $this->image ?>" alt="Image">
Expand Down Expand Up @@ -67,7 +67,7 @@ use PHPDraft\Out\Minifier;
</nav>
<?php endif; ?>
<?php endforeach; ?>
<?php if (!empty($this->base_structures)): ?>
<?php if ($this->base_structures !== []): ?>
<nav id="nav-datastructures" class="navbar navbar-light structures" aria-label="Data structures">
<a class="navbar-brand" href="#<?= $category->get_href(); ?>">Data Structures</a>
<?php foreach ($this->base_structures as $key => $structure): ?>
Expand All @@ -81,12 +81,12 @@ use PHPDraft\Out\Minifier;
</nav>
<div class="col-md-10 main-content">
<?php foreach ($this->categories as &$category): ?>
<?php if (!empty($category->title)): ?>
<?php if (!is_null($category->title)): ?>
<h2>
<a id="<?= $category->get_href(); ?>" data-anchor-id="<?= $category->get_href(); ?>"><?= $category->title; ?></a>
</h2>
<?php endif; ?>
<?php if (!empty($category->description)): ?>
<?php if (!is_null($category->description)): ?>
<p><?= $category->description; ?></p>
<?php endif; ?>
<?php foreach ($category->children as $resource): ?>
Expand All @@ -98,7 +98,7 @@ use PHPDraft\Out\Minifier;
</a>
<small><?= $resource->href; ?></small>
</h3>
<?php if (!empty($resource->description)): ?>
<?php if (!is_null($resource->description)): ?>
<p><?= $resource->description; ?></p>
<?php endif; ?>
<?php if ($resource->url_variables !== null): ?>
Expand All @@ -123,14 +123,14 @@ use PHPDraft\Out\Minifier;
</div>
<div class="card-body">
<p class="lead"><?= $transition->description; ?></p>
<?php if (!empty($transition->requests)): ?>
<?php if ($transition->requests !== []): ?>
<?php foreach ($transition->requests as $key => $request): ?>
<div class="card">
<div class="card-header">
<h6 class="request card-title"
data-toggle="collapse"
data-target="#request-coll-<?= $request->get_id(); ?>">Request
<?php if (!empty($request->title)): ?>
<?php if (!is_null($request->title)): ?>
<var><?= $request->title;?></var>
<?php endif;?>
<span class="fas indicator fa-angle-down float-right"></span>
Expand Down Expand Up @@ -168,7 +168,7 @@ use PHPDraft\Out\Minifier;
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php if (!empty($request->body)): ?>
<?php if ($request->body !== []): ?>
<h5>Body</h5>
<?php foreach ($request->body as $value): ?>
<?php if (is_string($value)): ?>
Expand All @@ -181,7 +181,7 @@ use PHPDraft\Out\Minifier;
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php if (!empty($request->struct)): ?>
<?php if ($request->struct !== []): ?>
<h5>Structure</h5>
<div class="row">
<?= $request->struct ?>
Expand Down Expand Up @@ -294,7 +294,7 @@ use PHPDraft\Out\Minifier;
<?php $extras = array_filter($this->base_data, function ($value) {
return !in_array($value, ['HOST', 'TITLE', 'ALT_HOST', 'FORMAT', 'DESC', 'COLOR_1', 'COLOR_2']);
}, ARRAY_FILTER_USE_KEY);
if (!empty($extras)):
if ($extras !== []):
$extras['host'] = $this->base_data['HOST']; ?>
<button
type="button"
Expand Down
30 changes: 15 additions & 15 deletions src/PHPDraft/Out/HTML/material.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php if (!empty($this->base_structures)): ?>
<?php if ($this->base_structures !== []): ?>
<a class="mdl-navigation__link" href="#"><strong>Objects</strong></a>
<?php foreach ($this->base_structures as $key => $structure): ?>
<a class="mdl-navigation__link"
Expand All @@ -65,18 +65,18 @@ use Enjoy\HttpStatusCode\Statuscodes;
<main class="mdl-layout__content main-content">
<div class="page-content">
<?php foreach ($this->categories as $category): ?>
<?php if (!empty($category->title)): ?>
<?php if (!is_null($category->title)): ?>
<h3><a id="<?= $category->get_href(); ?>"><?= $category->title; ?></a></h3>
<?php endif; ?>
<?php if (!empty($category->description)): ?>
<?php if (!is_null($category->description)): ?>
<p><?= $category->description; ?></p>
<?php endif; ?>
<?php foreach ($category->children as $resource): ?>
<h4>
<a id="<?= str_replace('-', '/', $resource->get_href()); ?>"><?= $resource->title; ?></a>
<small><?= $resource->href; ?></small>
</h4>
<?php if (!empty($resource->description)): ?>
<?php if (!is_null($resource->description)): ?>
<p><?= $resource->description; ?></p>
<?php endif; ?>
<?php foreach ($resource->children as $transition): ?>
Expand All @@ -90,26 +90,26 @@ use Enjoy\HttpStatusCode\Statuscodes;
</div>
<div class="mdl-card__supporting-text">
<?= $transition->description; ?>
<?php if (!empty($transition->requests) || !empty($transition->responses)): $i = 0;?>
<?php if (!is_null($transition->requests) || !is_null($transition->responses)): $i = 0;?>
<div class="mdl-tabs mdl-js-tabs mdl-js-ripple-effect">
<div class="mdl-tabs__tab-bar">
<?php if (!empty($transition->requests)): ?>
<?php if ($transition->requests !== []): ?>
<?php foreach ($transition->requests as $request): ?>
<a href="#request-panel-<?= $request->get_id(); ?>"
class="mdl-tabs__tab<?= ($i < 1) ? ' is-active' : '' ?>">
<strong>Request</strong> <?= (empty($request->title) ? '' : ' ' . $request->title) ?>
<strong>Request</strong> <?= is_null($request->title ? '' : ' ' . $request->title) ?>
</a>
<?php $i++; endforeach; ?>
<?php endif; ?>
<?php if (!empty($transition->responses)): ?>
<?php if ($transition->responses !== []): ?>
<?php foreach ($transition->responses as $response): ?>
<a href="#response-panel-<?= $response->get_id(); ?>"
class="mdl-tabs__tab<?= ($i < 1) ? ' is-active' : '' ?> <?= $this->get_response_status($response->statuscode) ?>"
title="<?= $response->statuscode . ' ' . $this->http_status->getReasonPhrase($response->statuscode) ?>"><?= $response->statuscode; ?></a>
<?php $i++; endforeach; ?>
<?php endif; ?>
</div>
<?php $i = 0; if (!empty($transition->requests)): ?>
<?php $i = 0; if (!$transition->requests !== []): ?>
<?php foreach ($transition->requests as $key => $request): ?>
<dialog class="mdl-dialog"
id="mdl-dialog-<?= $request->get_id(); ?>">
Expand Down Expand Up @@ -148,7 +148,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php if (!empty($request->body)): ?>
<?php if ($request->body !== []): ?>
<h5>Body</h5>
<?php foreach ($request->body as $value): ?>
<?php if (is_string($value)): ?>
Expand All @@ -161,7 +161,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php if (!empty($request->struct)): ?>
<?php if ($request->struct !== []): ?>
<h5>Structure</h5>
<?= $request->struct ?>
<?php endif; ?>
Expand All @@ -176,7 +176,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
</div>
<?php $i++; endforeach; ?>
<?php endif; ?>
<?php if (!empty($transition->responses)): ?>
<?php if ($transition->responses !== []): ?>
<?php foreach ($transition->responses as $key => $response): ?>
<div class="mdl-tabs__panel <?= ($i < 1) ? 'is-active' : '' ?>"
id="response-panel-<?= $response->get_id(); ?>">
Expand All @@ -201,9 +201,9 @@ use Enjoy\HttpStatusCode\Statuscodes;
<?php endforeach; ?>
<?php endif; ?>
<div class="mdl-grid">
<?php foreach ($response->content as $key => $value): ?>
<?php foreach ($response->content as $response_key => $value): ?>
<div class="mdl-cell mdl-cell--<?= 12 / count($response->content) ?>-col">
<h5 class="response-body"><?= $key; ?></h5>
<h5 class="response-body"><?= $response_key; ?></h5>
<pre class="response-body"
id="request-<?= $response->get_id(); ?>"><?= $value; ?></pre>
</div>
Expand Down Expand Up @@ -240,7 +240,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
<?php $extras = array_filter($this->base_data, function ($value) {
return !in_array($value, ['HOST', 'TITLE', 'ALT_HOST', 'FORMAT', 'DESC', 'COLOR_1', 'COLOR_2']);
}, ARRAY_FILTER_USE_KEY);
if (!empty($extras)):
if ($extras !== []):
$extras['host'] = $this->base_data['HOST']; ?>
<button
type="button"
Expand Down
4 changes: 2 additions & 2 deletions src/PHPDraft/Parse/HtmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public function get_html(string $template = 'default', ?string $image = null, ?s
{
$gen = new TemplateGenerator($template, $image);

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

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

Expand Down

0 comments on commit e6ba581

Please sign in to comment.