File tree Expand file tree Collapse file tree 6 files changed +31
-29
lines changed Expand file tree Collapse file tree 6 files changed +31
-29
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ abstract class BaseParser
44
44
*
45
45
* @return \PHPDraft\Parse\BaseParser
46
46
*/
47
- public function init ($ apib ): BaseParser
47
+ public function init ($ apib ): self
48
48
{
49
49
$ this ->apib = $ apib ;
50
50
$ this ->tmp_dir = sys_get_temp_dir () . '/drafter ' ;
@@ -65,8 +65,9 @@ public function __destruct()
65
65
/**
66
66
* Parse the API Blueprint text to JSON.
67
67
*
68
- * @return string API Blueprint text
69
68
* @throws \PHPDraft\Parse\ExecutionException When the JSON is invalid or warnings are thrown in parsing
69
+ *
70
+ * @return string API Blueprint text
70
71
*/
71
72
public function parseToJson ()
72
73
{
Original file line number Diff line number Diff line change @@ -28,10 +28,9 @@ class Drafter extends BaseParser
28
28
public function init ($ apib ): BaseParser
29
29
{
30
30
parent ::init ($ apib );
31
- $ this ->drafter = Drafter ::location ();
31
+ $ this ->drafter = self ::location ();
32
32
33
33
throw new ExecutionException ('The new Drafter V4 is not supported yet. ' , 100 );
34
-
35
34
return $ this ;
36
35
}
37
36
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class DrafterAPI extends BaseParser
21
21
public function init ($ apib ): BaseParser
22
22
{
23
23
parent ::init ($ apib );
24
+
24
25
return $ this ;
25
26
}
26
27
@@ -31,7 +32,7 @@ public function init($apib): BaseParser
31
32
*/
32
33
protected function parse ()
33
34
{
34
- $ ch = DrafterAPI ::curl_init_drafter ($ this ->apib );
35
+ $ ch = self ::curl_init_drafter ($ this ->apib );
35
36
36
37
$ response = curl_exec ($ ch );
37
38
@@ -80,7 +81,7 @@ public static function available(): bool
80
81
return FALSE ;
81
82
}
82
83
83
- $ ch = DrafterAPI ::curl_init_drafter ('# Hello API
84
+ $ ch = self ::curl_init_drafter ('# Hello API
84
85
## /message
85
86
### GET
86
87
+ Response 200 (text/plain)
Original file line number Diff line number Diff line change @@ -43,8 +43,9 @@ public function __construct($json)
43
43
/**
44
44
* Gets the default template HTML.
45
45
*
46
- * @return string
47
46
* @throws \PHPDraft\Parse\ExecutionException When parsing fails
47
+ *
48
+ * @return string
48
49
*/
49
50
public function __toString ()
50
51
{
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ class LegacyDrafter extends BaseParser
28
28
public function init ($ apib ): BaseParser
29
29
{
30
30
parent ::init ($ apib );
31
- $ this ->drafter = LegacyDrafter ::location ();
31
+ $ this ->drafter = self ::location ();
32
32
33
33
return $ this ;
34
34
}
@@ -45,6 +45,7 @@ public static function location()
45
45
46
46
return empty ($ returnVal ) ? FALSE : $ returnVal ;
47
47
}
48
+
48
49
/**
49
50
* Check if a given parser is available.
50
51
*
@@ -57,7 +58,7 @@ public static function available(): bool
57
58
$ version = shell_exec ('drafter -v 2> /dev/null ' );
58
59
$ version = preg_match ('/^v3/ ' , $ version );
59
60
60
- return ( $ path && $ version === 1 ) ;
61
+ return $ path && $ version === 1 ;
61
62
}
62
63
63
64
/**
Original file line number Diff line number Diff line change 1
1
<?php
2
- /**
3
- *
4
- */
5
2
6
3
namespace PHPDraft \Parse ;
7
4
8
5
/**
9
- * Class ParserFactory
6
+ * Class ParserFactory.
10
7
*/
11
- class ParserFactory {
12
-
8
+ class ParserFactory
9
+ {
13
10
/**
14
- * Get the applicable parser
11
+ * Get the applicable parser.
15
12
*
16
13
* @return \PHPDraft\Parse\BaseParser The parser that can be used
17
14
*/
18
- static function get (): BaseParser {
19
- if (Drafter::available ()) {
20
- return new Drafter ();
21
- }
22
- if (LegacyDrafter::available ()) {
23
- return new LegacyDrafter ();
24
- }
25
- if (DrafterAPI::available ()) {
26
- return new DrafterAPI ();
27
- }
28
- throw new ResourceException ("Couldn't get an apib parser " , 255 );
29
- }
30
- }
15
+ public static function get (): BaseParser
16
+ {
17
+ if (Drafter::available ()) {
18
+ return new Drafter ();
19
+ }
20
+ if (LegacyDrafter::available ()) {
21
+ return new LegacyDrafter ();
22
+ }
23
+ if (DrafterAPI::available ()) {
24
+ return new DrafterAPI ();
25
+ }
26
+
27
+ throw new ResourceException ("Couldn't get an apib parser " , 255 );
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments