Skip to content

Commit

Permalink
Move from drafter v3 to v4.
Browse files Browse the repository at this point in the history
Issue #47,#73,#74
  • Loading branch information
SMillerDev committed Apr 6, 2020
1 parent 38ea2db commit 3ed5e59
Show file tree
Hide file tree
Showing 61 changed files with 5,979 additions and 5,360 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"php": "~7.2",
"php": "^7.2",
"ql/uri-template": "~1.0",
"vanilla/garden-cli": "~2.0",
"michelf/php-markdown": "~1.9",
Expand All @@ -32,7 +32,7 @@
"theseer/autoload": "~1.0",
"phing/phing": "~2.0",
"phpstan/phpstan-phpunit": "^0.12.6",
"phpstan/phpstan": "^0.12.8"
"phpstan/phpstan": "^0.12.17"
},
"scripts": {
"test": [
Expand Down
65 changes: 55 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions phpdraft
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* Set up include path for source handling
*/
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
parameters:
bootstrap: tests/test.bootstrap.inc.php
excludes_analyse:
- src/PHPDraft/Out/Version.php
- src/PHPDraft/Parse/Tests/BaseParserTest.php
- src/PHPDraft/Parse/Tests/DrafterTest.php
- src/PHPDraft/Parse/Tests/DrafterAPITest.php
ignoreErrors:
- '#Access to an undefined property object::\$[a-zA-Z0-9\\_]+#'
- '#Access to an undefined property PHPUnit\\Framework\\MockObject\\MockObject::\$[a-zA-Z0-9_]+#'
Expand Down
3 changes: 2 additions & 1 deletion src/PHPDraft/Core/Autoloader.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* This file contains the Autoloader.
Expand All @@ -12,7 +13,7 @@
* Autoload classes according to PSR-1.
*/
spl_autoload_register(
function ($classname) {
function (string $classname): void {
$classname = ltrim($classname, '\\');
preg_match('/^(.+)?([^\\\\]+)$/U', $classname, $match);
$classname = str_replace('\\', '/', $match[1]) . str_replace(['\\', '_'], '/', $match[2]) . '.php';
Expand Down
23 changes: 22 additions & 1 deletion src/PHPDraft/In/ApibFileParser.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* This file contains the ApibFileParser.
Expand Down Expand Up @@ -65,6 +66,16 @@ public function parse(): self
return $this;
}

/**
* Set apib content.
*
* @param string $content The content
*/
public function set_apib_content(string $content): void
{
$this->full_apib = $content;
}

/**
* Parse a given API Blueprint file
* This changes all `include(file)` tags to the contents of the file.
Expand Down Expand Up @@ -152,13 +163,23 @@ private function get_schema(string $url): string
return $result;
}

/**
* Return the value of the file.
*
* @return string
*/
public function content(): string
{
return $this->full_apib;
}

/**
* Return the value of the class.
*
* @return string
*/
public function __toString(): string
{
return $this->full_apib;
return $this->content();
}
}
7 changes: 4 additions & 3 deletions src/PHPDraft/Model/Category.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* This file contains the Category.php.
Expand Down Expand Up @@ -55,10 +56,10 @@ public function parse(stdClass $object)
$deps = [];
$struct = new ObjectStructureElement();
$struct->deps = $deps;
$struct->parse($item, $deps);
$struct->parse($item->content, $deps);

if (is_array($item->content) && isset($item->content[0]->meta->id)) {
$this->structures[$item->content[0]->meta->id] = $struct;
if (isset($item->content->content) && is_array($item->content->content) && isset($item->content->content[0]->meta->id)) {
$this->structures[$item->content->content[0]->meta->id] = $struct;
} elseif (isset($item->content->meta->id->content)) {
$this->structures[$item->content->meta->id->content] = $struct;
} else {
Expand Down
1 change: 1 addition & 0 deletions src/PHPDraft/Model/Comparable.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Created by PhpStorm.
Expand Down
24 changes: 15 additions & 9 deletions src/PHPDraft/Model/Elements/ArrayStructureElement.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* This file contains the ArrayStructureElement.php.
Expand All @@ -18,14 +19,14 @@ class ArrayStructureElement extends BasicStructureElement
/**
* Parse an array object.
*
* @param object $object APIB Item to parse
* @param array $dependencies List of dependencies build
* @param object|null $object APIB Item to parse
* @param array $dependencies List of dependencies build
*
* @return self Self reference
*/
public function parse(object $object, array &$dependencies): StructureElement
public function parse(?object $object, array &$dependencies): StructureElement
{
$this->element = (isset($object->element)) ? $object->element : 'array';
$this->element = $object->element ?? 'array';

$this->parse_common($object, $dependencies);

Expand All @@ -40,7 +41,9 @@ public function parse(object $object, array &$dependencies): StructureElement
$dependencies[] = $sub_item->element;
}

$this->value[] = (isset($sub_item->element)) ? $sub_item->element : '';
$key = $sub_item->element ?? 'any';
$value = $sub_item->content ?? NULL;
$this->value[] = [$value => $key];
}

$this->deps = $dependencies;
Expand All @@ -62,13 +65,16 @@ public function __toString(): string
}

foreach ($this->value as $item) {
$type = (in_array($item, self::DEFAULTS)) ? $item : '<a href="#object-' . str_replace(
$value = key($item);
$key = $item[$value];
$type = (in_array($key, self::DEFAULTS)) ? "<code>$key</code>" : '<a href="#object-' . str_replace(
' ',
'-',
strtolower($item)
) . '">' . $item . '</a>';
strtolower($key)
) . '">' . $key . '</a>';

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

$return .= '</ul>';
Expand Down
Loading

0 comments on commit 3ed5e59

Please sign in to comment.