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
4444 *
4545 * @return \PHPDraft\Parse\BaseParser
4646 */
47- public function init ($ apib ): BaseParser
47+ public function init ($ apib ): self
4848 {
4949 $ this ->apib = $ apib ;
5050 $ this ->tmp_dir = sys_get_temp_dir () . '/drafter ' ;
@@ -65,8 +65,9 @@ public function __destruct()
6565 /**
6666 * Parse the API Blueprint text to JSON.
6767 *
68- * @return string API Blueprint text
6968 * @throws \PHPDraft\Parse\ExecutionException When the JSON is invalid or warnings are thrown in parsing
69+ *
70+ * @return string API Blueprint text
7071 */
7172 public function parseToJson ()
7273 {
Original file line number Diff line number Diff line change @@ -28,10 +28,9 @@ class Drafter extends BaseParser
2828 public function init ($ apib ): BaseParser
2929 {
3030 parent ::init ($ apib );
31- $ this ->drafter = Drafter ::location ();
31+ $ this ->drafter = self ::location ();
3232
3333 throw new ExecutionException ('The new Drafter V4 is not supported yet. ' , 100 );
34-
3534 return $ this ;
3635 }
3736
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class DrafterAPI extends BaseParser
2121 public function init ($ apib ): BaseParser
2222 {
2323 parent ::init ($ apib );
24+
2425 return $ this ;
2526 }
2627
@@ -31,7 +32,7 @@ public function init($apib): BaseParser
3132 */
3233 protected function parse ()
3334 {
34- $ ch = DrafterAPI ::curl_init_drafter ($ this ->apib );
35+ $ ch = self ::curl_init_drafter ($ this ->apib );
3536
3637 $ response = curl_exec ($ ch );
3738
@@ -80,7 +81,7 @@ public static function available(): bool
8081 return FALSE ;
8182 }
8283
83- $ ch = DrafterAPI ::curl_init_drafter ('# Hello API
84+ $ ch = self ::curl_init_drafter ('# Hello API
8485## /message
8586### GET
8687 + Response 200 (text/plain)
Original file line number Diff line number Diff line change @@ -43,8 +43,9 @@ public function __construct($json)
4343 /**
4444 * Gets the default template HTML.
4545 *
46- * @return string
4746 * @throws \PHPDraft\Parse\ExecutionException When parsing fails
47+ *
48+ * @return string
4849 */
4950 public function __toString ()
5051 {
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ class LegacyDrafter extends BaseParser
2828 public function init ($ apib ): BaseParser
2929 {
3030 parent ::init ($ apib );
31- $ this ->drafter = LegacyDrafter ::location ();
31+ $ this ->drafter = self ::location ();
3232
3333 return $ this ;
3434 }
@@ -45,6 +45,7 @@ public static function location()
4545
4646 return empty ($ returnVal ) ? FALSE : $ returnVal ;
4747 }
48+
4849 /**
4950 * Check if a given parser is available.
5051 *
@@ -57,7 +58,7 @@ public static function available(): bool
5758 $ version = shell_exec ('drafter -v 2> /dev/null ' );
5859 $ version = preg_match ('/^v3/ ' , $ version );
5960
60- return ( $ path && $ version === 1 ) ;
61+ return $ path && $ version === 1 ;
6162 }
6263
6364 /**
Original file line number Diff line number Diff line change 11<?php
2- /**
3- *
4- */
52
63namespace PHPDraft \Parse ;
74
85/**
9- * Class ParserFactory
6+ * Class ParserFactory.
107 */
11- class ParserFactory {
12-
8+ class ParserFactory
9+ {
1310 /**
14- * Get the applicable parser
11+ * Get the applicable parser.
1512 *
1613 * @return \PHPDraft\Parse\BaseParser The parser that can be used
1714 */
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