File tree Expand file tree Collapse file tree 5 files changed +39
-4
lines changed Expand file tree Collapse file tree 5 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,26 @@ public function detectNullsyFunction(): bool
160160 return false ;
161161 }
162162
163+ /*
164+ * Detect function which return an empty string on error.
165+ */
166+ public function detectEmptyFunction (): bool
167+ {
168+ $ file = file_get_contents ($ this ->path );
169+ if ($ file === false ) {
170+ throw new \RuntimeException ('An error occured while reading ' .$ this ->path );
171+ }
172+ if ($ this ->getIsDeprecated ($ file )) {
173+ return false ;
174+ }
175+
176+ if (preg_match ('/an\s+empty\s+string\s+on\s+error/ ' , $ file )) {
177+ return true ;
178+ }
179+
180+ return false ;
181+ }
182+
163183
164184 /**
165185 * @return \SimpleXMLElement[]
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ class Method
1010{
1111 const FALSY_TYPE = 1 ;
1212 const NULLSY_TYPE = 2 ;
13+ const EMPTY_TYPE = 3 ;
1314 /**
1415 * @var \SimpleXMLElement
1516 */
@@ -162,7 +163,11 @@ private function stripReturnFalseText(string $string): string
162163 $ string = $ this ->removeString ($ string , ' and FALSE if an error occurred ' );
163164 $ string = $ this ->removeString ($ string , 'the function will return TRUE, or FALSE otherwise ' );
164165 break ;
165-
166+
167+ case self ::EMPTY_TYPE :
168+ $ string = $ this ->removeString ($ string , ' or an empty string on error ' );
169+ break ;
170+
166171 default :
167172 throw new \RuntimeException ('Incorrect error type. ' );
168173 }
Original file line number Diff line number Diff line change @@ -102,8 +102,9 @@ public function getMethods(array $paths): array
102102 $ docPage = new DocPage ($ path );
103103 $ isFalsy = $ docPage ->detectFalsyFunction ();
104104 $ isNullsy = $ docPage ->detectNullsyFunction ();
105- if ($ isFalsy || $ isNullsy ) {
106- $ errorType = $ isFalsy ? Method::FALSY_TYPE : Method::NULLSY_TYPE ;
105+ $ isEmpty = $ docPage ->detectEmptyFunction ();
106+ if ($ isFalsy || $ isNullsy || $ isEmpty ) {
107+ $ errorType = $ isFalsy ? Method::FALSY_TYPE : ($ isNullsy ? Method::NULLSY_TYPE : Method::EMPTY_TYPE );
107108
108109 $ functionObjects = $ docPage ->getMethodSynopsis ();
109110 if (count ($ functionObjects ) > 1 ) {
Original file line number Diff line number Diff line change @@ -97,14 +97,16 @@ private function writePhpFunction(): string
9797
9898 private function generateExceptionCode (string $ moduleName , Method $ method ) : string
9999 {
100- $ errorValue = null ;
101100 switch ($ method ->getErrorType ()) {
102101 case Method::FALSY_TYPE :
103102 $ errorValue = 'false ' ;
104103 break ;
105104 case Method::NULLSY_TYPE :
106105 $ errorValue = 'null ' ;
107106 break ;
107+ case Method::EMPTY_TYPE :
108+ $ errorValue = "'' " ;
109+ break ;
108110 default :
109111 throw new \LogicException ("Method doesn't have an error type " );
110112 }
Original file line number Diff line number Diff line change @@ -47,4 +47,11 @@ public function testDetectNullsyFunction()
4747 $ this ->assertFalse ($ implode ->detectNullsyFunction ());
4848 $ this ->assertTrue ($ arrayReplace ->detectNullsyFunction ());
4949 }
50+
51+ public function testDetectEmptyFunction ()
52+ {
53+ $ pgHost = new DocPage (__DIR__ . '/../doc/doc-en/en/reference/pgsql/functions/pg-host.xml ' );
54+
55+ $ this ->assertTrue ($ pgHost ->detectEmptyFunction ());
56+ }
5057}
You can’t perform that action at this time.
0 commit comments