Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit cb2959a

Browse files
committed
Fixing nullable return types under latest PHP 7.1 RC. Closes #206.
1 parent ee27ab0 commit cb2959a

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ matrix:
3131
group: edge
3232
fast_finish: true
3333
allow_failures:
34-
- php: 7.1
3534
- php: nightly
3635
- php: hhvm-nightly
3736

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Phony changelog
22

3+
## Next release
4+
5+
- **[FIXED]** Fixed nullable return type support for newer PHP 7.1 release
6+
candidates ([#206]).
7+
8+
[#206]: https://github.com/eloquent/phony/issues/206
9+
310
## 0.14.1 (2016-11-04)
411

512
- **[FIXED]** Checking for nullable type support no longer causes fatal errors

src/Mock/MockGenerator.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,11 @@ public static function ${returnsReference}__callStatic(
289289
$isBuiltin = $isBuiltin && false === strpos($typeString, '\\');
290290
// @codeCoverageIgnoreEnd
291291
} else {
292-
$typeString = (string) $type;
292+
if ($type->allowsNull()) {
293+
$typeString = '?' . $type; // @codeCoverageIgnore
294+
} else {
295+
$typeString = (string) $type;
296+
}
293297
}
294298

295299
if ($isBuiltin) {
@@ -488,7 +492,11 @@ private function generateMethods($methods)
488492
$isBuiltin && false === strpos($typeString, '\\');
489493
// @codeCoverageIgnoreEnd
490494
} else {
491-
$typeString = (string) $type;
495+
if ($type->allowsNull()) {
496+
$typeString = '?' . $type; // @codeCoverageIgnore
497+
} else {
498+
$typeString = (string) $type;
499+
}
492500
}
493501

494502
if ($isBuiltin) {
@@ -681,7 +689,11 @@ public function ${returnsReference}__call(
681689
$isBuiltin = $isBuiltin && false === strpos($typeString, '\\');
682690
// @codeCoverageIgnoreEnd
683691
} else {
684-
$typeString = (string) $type;
692+
if ($type->allowsNull()) {
693+
$typeString = '?' . $type; // @codeCoverageIgnore
694+
} else {
695+
$typeString = (string) $type;
696+
}
685697
}
686698

687699
if ($isBuiltin) {

test/src/Test/TestInterfaceWithNullableTypes.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
interface TestInterfaceWithNullableTypes
1717
{
18-
public function staticMethodA(?string $string, ?stdClass $object) : ?TestClassA;
19-
public function staticMethodB() : ?int;
20-
public function methodA(?string $string, ?stdClass $object) : ?TestClassA;
21-
public function methodB() : ?int;
18+
public function staticMethodA( ? string $string, ? stdClass $object) : ? TestClassA;
19+
public function staticMethodB() : ? int;
20+
public function methodA( ? string $string, ? stdClass $object) : ? TestClassA;
21+
public function methodB() : ? int;
2222

23-
public function __call($name, array $arguments) : ?int;
24-
public static function __callStatic($name, array $arguments) : ?int;
23+
public function __call($name, array $arguments) : ? int;
24+
public static function __callStatic($name, array $arguments) : ? int;
2525
}

0 commit comments

Comments
 (0)