diff --git a/src/PHPDraft/Parse/BaseHtmlGenerator.php b/src/PHPDraft/Parse/BaseHtmlGenerator.php
index 862901f5..afd23494 100644
--- a/src/PHPDraft/Parse/BaseHtmlGenerator.php
+++ b/src/PHPDraft/Parse/BaseHtmlGenerator.php
@@ -22,21 +22,21 @@ abstract class BaseHtmlGenerator
*
* @var int
*/
- public $sorting;
+ public int $sorting;
/**
* JSON representation of an API Blueprint.
*
- * @var stdClass
+ * @var object
*/
- protected $object;
+ protected object $object;
/**
* Rendered HTML
*
* @var string
*/
- protected $html;
+ protected string $html;
/**
* Constructor.
diff --git a/src/PHPDraft/Parse/BaseParser.php b/src/PHPDraft/Parse/BaseParser.php
index 0cf98857..840b572a 100644
--- a/src/PHPDraft/Parse/BaseParser.php
+++ b/src/PHPDraft/Parse/BaseParser.php
@@ -24,30 +24,30 @@ abstract class BaseParser
/**
* The API Blueprint output (JSON).
*
- * @var object
+ * @var object|null
*/
- public $json;
+ public ?object $json;
/**
* Temp directory.
*
* @var string
*/
- protected $tmp_dir;
+ protected string $tmp_dir;
/**
* The API Blueprint input.
*
* @var ApibFileParser
*/
- protected $apib;
+ protected ApibFileParser $apib;
/**
* BaseParser constructor.
*
* @param ApibFileParser $apib API Blueprint text
*
- * @return \PHPDraft\Parse\BaseParser
+ * @return self
*/
public function init(ApibFileParser $apib): self
{
@@ -114,7 +114,7 @@ public function parseToJson(): object
*
* @return void
*/
- abstract protected function parse();
+ abstract protected function parse(): void;
/**
* Check if a given parser is available.
diff --git a/src/PHPDraft/Parse/Drafter.php b/src/PHPDraft/Parse/Drafter.php
index 1e8b404a..b6fe2696 100644
--- a/src/PHPDraft/Parse/Drafter.php
+++ b/src/PHPDraft/Parse/Drafter.php
@@ -21,7 +21,7 @@ class Drafter extends BaseParser
*
* @var string
*/
- protected $drafter;
+ protected string $drafter;
/**
* ApibToJson constructor.
@@ -33,7 +33,11 @@ class Drafter extends BaseParser
public function init(ApibFileParser $apib): BaseParser
{
parent::init($apib);
- $this->drafter = self::location();
+ $loc = self::location();
+ if ($loc === false) {
+ throw new \UnexpectedValueException("Could not find drafter location!");
+ }
+ $this->drafter = $loc;
return $this;
}
@@ -41,7 +45,7 @@ public function init(ApibFileParser $apib): BaseParser
/**
* Return drafter location if found.
*
- * @return bool|string
+ * @return false|string
*/
public static function location()
{
@@ -59,7 +63,12 @@ public static function location()
protected function parse(): void
{
shell_exec("{$this->drafter} {$this->tmp_dir}/index.apib -f json -o {$this->tmp_dir}/index.json 2> /dev/null");
- $this->json = json_decode(file_get_contents($this->tmp_dir . '/index.json'));
+ $content = file_get_contents($this->tmp_dir . '/index.json');
+ if (!is_string($content)) {
+ throw new \RuntimeException('Could not read intermediary APIB file!');
+ }
+
+ $this->json = json_decode($content);
}
/**
diff --git a/src/PHPDraft/Parse/Tests/BaseParserTest.php b/src/PHPDraft/Parse/Tests/BaseParserTest.php
index 305063e4..19a97d6f 100644
--- a/src/PHPDraft/Parse/Tests/BaseParserTest.php
+++ b/src/PHPDraft/Parse/Tests/BaseParserTest.php
@@ -74,16 +74,6 @@ public function testSetupCorrectly(): void
$this->assertInstanceOf('\PHPDraft\In\ApibFileParser', $this->get_reflection_property_value('apib'));
}
- /**
- * Check if the JSON is empty before parsing
- *
- * @covers \PHPDraft\Parse\BaseParser::parseToJson()
- */
- public function testPreRunStringIsEmpty(): void
- {
- $this->assertEmpty($this->class->json);
- }
-
/**
* Check if parsing the APIB to JSON gives the expected result
*
diff --git a/src/PHPDraft/Parse/Tests/DrafterAPITest.php b/src/PHPDraft/Parse/Tests/DrafterAPITest.php
index 84cc01f7..eea12384 100644
--- a/src/PHPDraft/Parse/Tests/DrafterAPITest.php
+++ b/src/PHPDraft/Parse/Tests/DrafterAPITest.php
@@ -111,16 +111,6 @@ public function testAvailableSuccess(): void
$this->unmock_function('curl_exec');
}
- /**
- * Check if the JSON is empty before parsing
- *
- * @covers \PHPDraft\Parse\DrafterAPI::parseToJson()
- */
- public function testPreRunStringIsEmpty(): void
- {
- $this->assertEmpty($this->class->json);
- }
-
/**
* Check if parsing the fails without drafter
*
diff --git a/src/PHPDraft/Parse/Tests/DrafterTest.php b/src/PHPDraft/Parse/Tests/DrafterTest.php
index c1365134..c4172ef2 100644
--- a/src/PHPDraft/Parse/Tests/DrafterTest.php
+++ b/src/PHPDraft/Parse/Tests/DrafterTest.php
@@ -83,16 +83,6 @@ public function testSetupCorrectly(): void
$this->assertInstanceOf('\PHPDraft\In\ApibFileParser', $this->get_reflection_property_value('apib'));
}
- /**
- * Check if the JSON is empty before parsing
- *
- * @covers \PHPDraft\Parse\Drafter::parseToJson()
- */
- public function testPreRunStringIsEmpty(): void
- {
- $this->assertEmpty($this->class->json);
- }
-
/**
* Check if parsing the APIB to JSON gives the expected result
*/
diff --git a/src/PHPDraft/Parse/Tests/HtmlGeneratorTest.php b/src/PHPDraft/Parse/Tests/HtmlGeneratorTest.php
index c9c3322d..1925ddf7 100644
--- a/src/PHPDraft/Parse/Tests/HtmlGeneratorTest.php
+++ b/src/PHPDraft/Parse/Tests/HtmlGeneratorTest.php
@@ -57,9 +57,8 @@ public function tearDown(): void
*/
public function testSetupCorrectly(): void
{
- $property = $this->reflection->getProperty('object');
- $property->setAccessible(true);
- $this->assertEquals(json_decode(file_get_contents(TEST_STATICS . '/drafter/json/index.json')), $property->getValue($this->class));
+ $json = json_decode(file_get_contents(TEST_STATICS . '/drafter/json/index.json'));
+ $this->assertEquals($json, $this->get_reflection_property_value('object'));
}
/**