Skip to content

Commit 3ed5e59

Browse files
committed
Move from drafter v3 to v4.
Issue #47,#73,#74
1 parent 38ea2db commit 3ed5e59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+5979
-5360
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
],
2020
"require": {
21-
"php": "~7.2",
21+
"php": "^7.2",
2222
"ql/uri-template": "~1.0",
2323
"vanilla/garden-cli": "~2.0",
2424
"michelf/php-markdown": "~1.9",
@@ -32,7 +32,7 @@
3232
"theseer/autoload": "~1.0",
3333
"phing/phing": "~2.0",
3434
"phpstan/phpstan-phpunit": "^0.12.6",
35-
"phpstan/phpstan": "^0.12.8"
35+
"phpstan/phpstan": "^0.12.17"
3636
},
3737
"scripts": {
3838
"test": [

composer.lock

+55-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpdraft

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* Set up include path for source handling
45
*/

phpstan.neon

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
parameters:
22
bootstrap: tests/test.bootstrap.inc.php
3+
excludes_analyse:
4+
- src/PHPDraft/Out/Version.php
5+
- src/PHPDraft/Parse/Tests/BaseParserTest.php
6+
- src/PHPDraft/Parse/Tests/DrafterTest.php
7+
- src/PHPDraft/Parse/Tests/DrafterAPITest.php
38
ignoreErrors:
49
- '#Access to an undefined property object::\$[a-zA-Z0-9\\_]+#'
510
- '#Access to an undefined property PHPUnit\\Framework\\MockObject\\MockObject::\$[a-zA-Z0-9_]+#'

src/PHPDraft/Core/Autoloader.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
/**
45
* This file contains the Autoloader.
@@ -12,7 +13,7 @@
1213
* Autoload classes according to PSR-1.
1314
*/
1415
spl_autoload_register(
15-
function ($classname) {
16+
function (string $classname): void {
1617
$classname = ltrim($classname, '\\');
1718
preg_match('/^(.+)?([^\\\\]+)$/U', $classname, $match);
1819
$classname = str_replace('\\', '/', $match[1]) . str_replace(['\\', '_'], '/', $match[2]) . '.php';

src/PHPDraft/In/ApibFileParser.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
/**
45
* This file contains the ApibFileParser.
@@ -65,6 +66,16 @@ public function parse(): self
6566
return $this;
6667
}
6768

69+
/**
70+
* Set apib content.
71+
*
72+
* @param string $content The content
73+
*/
74+
public function set_apib_content(string $content): void
75+
{
76+
$this->full_apib = $content;
77+
}
78+
6879
/**
6980
* Parse a given API Blueprint file
7081
* This changes all `include(file)` tags to the contents of the file.
@@ -152,13 +163,23 @@ private function get_schema(string $url): string
152163
return $result;
153164
}
154165

166+
/**
167+
* Return the value of the file.
168+
*
169+
* @return string
170+
*/
171+
public function content(): string
172+
{
173+
return $this->full_apib;
174+
}
175+
155176
/**
156177
* Return the value of the class.
157178
*
158179
* @return string
159180
*/
160181
public function __toString(): string
161182
{
162-
return $this->full_apib;
183+
return $this->content();
163184
}
164185
}

src/PHPDraft/Model/Category.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
/**
45
* This file contains the Category.php.
@@ -55,10 +56,10 @@ public function parse(stdClass $object)
5556
$deps = [];
5657
$struct = new ObjectStructureElement();
5758
$struct->deps = $deps;
58-
$struct->parse($item, $deps);
59+
$struct->parse($item->content, $deps);
5960

60-
if (is_array($item->content) && isset($item->content[0]->meta->id)) {
61-
$this->structures[$item->content[0]->meta->id] = $struct;
61+
if (isset($item->content->content) && is_array($item->content->content) && isset($item->content->content[0]->meta->id)) {
62+
$this->structures[$item->content->content[0]->meta->id] = $struct;
6263
} elseif (isset($item->content->meta->id->content)) {
6364
$this->structures[$item->content->meta->id->content] = $struct;
6465
} else {

src/PHPDraft/Model/Comparable.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
/**
45
* Created by PhpStorm.

src/PHPDraft/Model/Elements/ArrayStructureElement.php

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
/**
45
* This file contains the ArrayStructureElement.php.
@@ -18,14 +19,14 @@ class ArrayStructureElement extends BasicStructureElement
1819
/**
1920
* Parse an array object.
2021
*
21-
* @param object $object APIB Item to parse
22-
* @param array $dependencies List of dependencies build
22+
* @param object|null $object APIB Item to parse
23+
* @param array $dependencies List of dependencies build
2324
*
2425
* @return self Self reference
2526
*/
26-
public function parse(object $object, array &$dependencies): StructureElement
27+
public function parse(?object $object, array &$dependencies): StructureElement
2728
{
28-
$this->element = (isset($object->element)) ? $object->element : 'array';
29+
$this->element = $object->element ?? 'array';
2930

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

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

43-
$this->value[] = (isset($sub_item->element)) ? $sub_item->element : '';
44+
$key = $sub_item->element ?? 'any';
45+
$value = $sub_item->content ?? NULL;
46+
$this->value[] = [$value => $key];
4447
}
4548

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

6467
foreach ($this->value as $item) {
65-
$type = (in_array($item, self::DEFAULTS)) ? $item : '<a href="#object-' . str_replace(
68+
$value = key($item);
69+
$key = $item[$value];
70+
$type = (in_array($key, self::DEFAULTS)) ? "<code>$key</code>" : '<a href="#object-' . str_replace(
6671
' ',
6772
'-',
68-
strtolower($item)
69-
) . '">' . $item . '</a>';
73+
strtolower($key)
74+
) . '">' . $key . '</a>';
7075

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

7480
$return .= '</ul>';

0 commit comments

Comments
 (0)