GeezerVison is showing github.com — fixed : bug with methods returning void · sitphp/doubles@40bb4f2
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/Double.php +11-3Lines changed: 11 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -781,6 +781,7 @@ protected static function resolveDoubleCode($double_definition) |
781 | 781 | $methods_code = []; |
782 | 782 | foreach ($double_definition['methods'] as $method) { |
783 | 783 | $reference_params = []; |
| 784 | + $method_return_type = null; |
784 | 785 |
|
785 | 786 | // Check method was not already implemented |
786 | 787 | $method_name = $method instanceof \ReflectionMethod ? $method->getShortName() : $method; |
@@ -887,12 +888,19 @@ protected static function resolveDoubleCode($double_definition) |
887 | 888 | }'; |
888 | 889 | } |
889 | 890 |
|
| 891 | + if($method_return_type != 'void'){ |
| 892 | + $method_code .= '$return = '; |
| 893 | + } |
890 | 894 | if ($is_static) { |
891 | | - $method_code .= '$return = self::_double_handleStaticCall(__FUNCTION__, $args); '; |
| 895 | + $method_code .= 'self::_double_handleStaticCall(__FUNCTION__, $args); '; |
892 | 896 | } else { |
893 | | - $method_code .= '$return = $this->_double_handleInstanceCall(__FUNCTION__, $args); '; |
| 897 | + $method_code .= '$this->_double_handleInstanceCall(__FUNCTION__, $args); '; |
| 898 | + } |
| 899 | + if($method_return_type != 'void'){ |
| 900 | + $method_code .= 'return $return;'; |
894 | 901 | } |
895 | | - $method_code .= 'return $return; }'; |
| 902 | + $method_code .= ' }'; |
| 903 | + |
896 | 904 | $methods_code[] = $method_code; |
897 | 905 | } |
898 | 906 | $code = substr($code, 0, strrpos($code, "}")) . implode(PHP_EOL, $methods_code) . '}'; |
|
Collapse file
Copy file name to clipboardExpand all lines: tests/DoubleTest.php +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -568,6 +568,11 @@ public function defaultWithEscape($a = "\\") |
568 | 568 | return $a; |
569 | 569 | } |
570 | 570 |
|
| 571 | + public function returnTypeVoid(): void |
| 572 | + { |
| 573 | + |
| 574 | + } |
| 575 | + |
571 | 576 | public function returnType(): string |
572 | 577 | { |
573 | 578 | return 'string'; |
|