File tree Expand file tree Collapse file tree 7 files changed +25
-47
lines changed Expand file tree Collapse file tree 7 files changed +25
-47
lines changed Original file line number Diff line number Diff line change @@ -22,21 +22,21 @@ abstract class BaseHtmlGenerator
22
22
*
23
23
* @var int
24
24
*/
25
- public $ sorting ;
25
+ public int $ sorting ;
26
26
27
27
/**
28
28
* JSON representation of an API Blueprint.
29
29
*
30
- * @var stdClass
30
+ * @var object
31
31
*/
32
- protected $ object ;
32
+ protected object $ object ;
33
33
34
34
/**
35
35
* Rendered HTML
36
36
*
37
37
* @var string
38
38
*/
39
- protected $ html ;
39
+ protected string $ html ;
40
40
41
41
/**
42
42
* Constructor.
Original file line number Diff line number Diff line change @@ -24,30 +24,30 @@ abstract class BaseParser
24
24
/**
25
25
* The API Blueprint output (JSON).
26
26
*
27
- * @var object
27
+ * @var object|null
28
28
*/
29
- public $ json ;
29
+ public ? object $ json ;
30
30
31
31
/**
32
32
* Temp directory.
33
33
*
34
34
* @var string
35
35
*/
36
- protected $ tmp_dir ;
36
+ protected string $ tmp_dir ;
37
37
38
38
/**
39
39
* The API Blueprint input.
40
40
*
41
41
* @var ApibFileParser
42
42
*/
43
- protected $ apib ;
43
+ protected ApibFileParser $ apib ;
44
44
45
45
/**
46
46
* BaseParser constructor.
47
47
*
48
48
* @param ApibFileParser $apib API Blueprint text
49
49
*
50
- * @return \PHPDraft\Parse\BaseParser
50
+ * @return self
51
51
*/
52
52
public function init (ApibFileParser $ apib ): self
53
53
{
@@ -114,7 +114,7 @@ public function parseToJson(): object
114
114
*
115
115
* @return void
116
116
*/
117
- abstract protected function parse ();
117
+ abstract protected function parse (): void ;
118
118
119
119
/**
120
120
* Check if a given parser is available.
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class Drafter extends BaseParser
21
21
*
22
22
* @var string
23
23
*/
24
- protected $ drafter ;
24
+ protected string $ drafter ;
25
25
26
26
/**
27
27
* ApibToJson constructor.
@@ -33,15 +33,19 @@ class Drafter extends BaseParser
33
33
public function init (ApibFileParser $ apib ): BaseParser
34
34
{
35
35
parent ::init ($ apib );
36
- $ this ->drafter = self ::location ();
36
+ $ loc = self ::location ();
37
+ if ($ loc === false ) {
38
+ throw new \UnexpectedValueException ("Could not find drafter location! " );
39
+ }
40
+ $ this ->drafter = $ loc ;
37
41
38
42
return $ this ;
39
43
}
40
44
41
45
/**
42
46
* Return drafter location if found.
43
47
*
44
- * @return bool |string
48
+ * @return false |string
45
49
*/
46
50
public static function location ()
47
51
{
@@ -59,7 +63,12 @@ public static function location()
59
63
protected function parse (): void
60
64
{
61
65
shell_exec ("{$ this ->drafter } {$ this ->tmp_dir }/index.apib -f json -o {$ this ->tmp_dir }/index.json 2> /dev/null " );
62
- $ this ->json = json_decode (file_get_contents ($ this ->tmp_dir . '/index.json ' ));
66
+ $ content = file_get_contents ($ this ->tmp_dir . '/index.json ' );
67
+ if (!is_string ($ content )) {
68
+ throw new \RuntimeException ('Could not read intermediary APIB file! ' );
69
+ }
70
+
71
+ $ this ->json = json_decode ($ content );
63
72
}
64
73
65
74
/**
Original file line number Diff line number Diff line change @@ -74,16 +74,6 @@ public function testSetupCorrectly(): void
74
74
$ this ->assertInstanceOf ('\PHPDraft\In\ApibFileParser ' , $ this ->get_reflection_property_value ('apib ' ));
75
75
}
76
76
77
- /**
78
- * Check if the JSON is empty before parsing
79
- *
80
- * @covers \PHPDraft\Parse\BaseParser::parseToJson()
81
- */
82
- public function testPreRunStringIsEmpty (): void
83
- {
84
- $ this ->assertEmpty ($ this ->class ->json );
85
- }
86
-
87
77
/**
88
78
* Check if parsing the APIB to JSON gives the expected result
89
79
*
Original file line number Diff line number Diff line change @@ -111,16 +111,6 @@ public function testAvailableSuccess(): void
111
111
$ this ->unmock_function ('curl_exec ' );
112
112
}
113
113
114
- /**
115
- * Check if the JSON is empty before parsing
116
- *
117
- * @covers \PHPDraft\Parse\DrafterAPI::parseToJson()
118
- */
119
- public function testPreRunStringIsEmpty (): void
120
- {
121
- $ this ->assertEmpty ($ this ->class ->json );
122
- }
123
-
124
114
/**
125
115
* Check if parsing the fails without drafter
126
116
*
Original file line number Diff line number Diff line change @@ -83,16 +83,6 @@ public function testSetupCorrectly(): void
83
83
$ this ->assertInstanceOf ('\PHPDraft\In\ApibFileParser ' , $ this ->get_reflection_property_value ('apib ' ));
84
84
}
85
85
86
- /**
87
- * Check if the JSON is empty before parsing
88
- *
89
- * @covers \PHPDraft\Parse\Drafter::parseToJson()
90
- */
91
- public function testPreRunStringIsEmpty (): void
92
- {
93
- $ this ->assertEmpty ($ this ->class ->json );
94
- }
95
-
96
86
/**
97
87
* Check if parsing the APIB to JSON gives the expected result
98
88
*/
Original file line number Diff line number Diff line change @@ -57,9 +57,8 @@ public function tearDown(): void
57
57
*/
58
58
public function testSetupCorrectly (): void
59
59
{
60
- $ property = $ this ->reflection ->getProperty ('object ' );
61
- $ property ->setAccessible (true );
62
- $ this ->assertEquals (json_decode (file_get_contents (TEST_STATICS . '/drafter/json/index.json ' )), $ property ->getValue ($ this ->class ));
60
+ $ json = json_decode (file_get_contents (TEST_STATICS . '/drafter/json/index.json ' ));
61
+ $ this ->assertEquals ($ json , $ this ->get_reflection_property_value ('object ' ));
63
62
}
64
63
65
64
/**
You can’t perform that action at this time.
0 commit comments