-
Notifications
You must be signed in to change notification settings - Fork 79
Introduce PHP7.2 object
type hint
#112
Introduce PHP7.2 object
type hint
#112
Conversation
src/Generator/TypeGenerator.php
Outdated
@@ -33,7 +33,8 @@ | |||
* | |||
* @link http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration | |||
*/ | |||
private static $internalPhpTypes = ['void', 'int', 'float', 'string', 'bool', 'array', 'callable', 'iterable']; | |||
private static $internalPhpTypes = ['void', 'int', 'float', 'string', 'bool', 'array', 'callable', 'iterable', | |||
'object']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alignment is broken here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the right alignment here ? I try to find a "too" long array property but can't find one in the project...
Is this ok?
private static $internalPhpTypes = [
'void',
'int',
'float',
'string',
'bool',
'array',
'callable',
'iterable',
'object'
];
@@ -373,7 +376,7 @@ function (array $parameter) { | |||
return PHP_VERSION_ID >= 70100 | |||
|| ( | |||
false === strpos($parameter[2], '?') | |||
&& ! in_array(strtolower($parameter[2]), ['void', 'iterable']) | |||
&& ! in_array(strtolower($parameter[2]), ['void', 'iterable', 'object']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful about the php version comparison: should be 70200
@@ -472,13 +473,19 @@ public function reflectionHintsProvider() | |||
[IterableHintsClass::class, 'iterableParameter', 'foo', 'iterable'], | |||
[IterableHintsClass::class, 'nullableIterableParameter', 'foo', '?iterable'], | |||
[IterableHintsClass::class, 'nullDefaultIterableParameter', 'foo', '?iterable'], | |||
[ObjectHintsClass::class, 'objectParameter', 'foo', 'object'], | |||
[ObjectHintsClass::class, 'nullableObjectParameter', 'foo', '?object'], | |||
[ObjectHintsClass::class, 'nullDefaultObjectParameter', 'foo', '?object'], | |||
]; | |||
|
|||
$compatibleParameters = array_filter( | |||
$parameters, | |||
function (array $parameter) { | |||
return PHP_VERSION_ID >= 70100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above: different conditionals for 70200
@@ -472,13 +473,19 @@ public function reflectionHintsProvider() | |||
[IterableHintsClass::class, 'iterableParameter', 'foo', 'iterable'], | |||
[IterableHintsClass::class, 'nullableIterableParameter', 'foo', '?iterable'], | |||
[IterableHintsClass::class, 'nullDefaultIterableParameter', 'foo', '?iterable'], | |||
[ObjectHintsClass::class, 'objectParameter', 'foo', 'object'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should only be added to the data providrr if the php version is 70200 or greater
@@ -365,6 +366,8 @@ public function returnTypeHintClassesProvider() | |||
[NullableReturnTypeHintedClass::class, 'otherClassReturn', '?\\' . InternalHintsClass::class], | |||
[IterableHintsClass::class, 'iterableReturnValue', 'iterable'], | |||
[IterableHintsClass::class, 'nullableIterableReturnValue', '?iterable'], | |||
[ObjectHintsClass::class, 'objectReturnValue', 'object'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should only be added to the data providrr if the php version is 70200 or greater
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the tests regarding PHP version.
Yup
…On 3 Jul 2017 13:04, "Stéphane HULARD" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/Generator/TypeGenerator.php
<#112 (comment)>
:
> @@ -33,7 +33,8 @@
*
* @link http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
*/
- private static $internalPhpTypes = ['void', 'int', 'float', 'string', 'bool', 'array', 'callable', 'iterable'];
+ private static $internalPhpTypes = ['void', 'int', 'float', 'string', 'bool', 'array', 'callable', 'iterable',
+ 'object'];
What's the right alignment here ? I try to find a "too" long array
property but can't find one in the project...
Is this ok?
private static $internalPhpTypes = [
'void',
'int',
'float',
'string',
'bool',
'array',
'callable',
'iterable',
'object'
];
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#112 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJakOMzTKQhdY0auFDbefLE21Kdylqlks5sKMqsgaJpZM4OMGre>
.
|
fb4277e
to
b95a4e4
Compare
Couple things here:
|
Allow the TypeGenerator to recognize this new PHP7.2 internal type. # Conflicts: # src/Generator/TypeGenerator.php
b95a4e4
to
754faf1
Compare
Hello, I've updated the target branch and rebased on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Great work, thanks!
|| ( | ||
false === strpos($parameter[2], 'object') | ||
)) | ||
&& (PHP_VERSION_ID >= 70100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this part of condition, as now develop
supports only PHP 7.1+
|| ( | ||
false === strpos($parameter[3], 'object') | ||
)) | ||
&& (PHP_VERSION_ID >= 70100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
@Ocramius tests still are failing ! |
Hmm, can you check up on the test failures? |
754faf1
to
c7b1922
Compare
I've just removed the PHP 7.1 conditions in the tests... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shulard Please see my comments.
]; | ||
|
||
$compatibleParameters = array_filter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to use this variable in line 487 and 489.
$compatibleParameters = array_filter( | ||
$parameters, | ||
function (array $parameter) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove empty line above.
@@ -241,6 +241,9 @@ public function invalidTypeProvider() | |||
['\\iterable'], | |||
['\\Iterable'], | |||
['\\ITERABLE'], | |||
['\\object'], | |||
['\\Object'], | |||
['\\OBJECT'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you added these to invalidTypeProvider
, don't we need remove 'object' from validTypeProvider
?
c7b1922
to
a8acf4e
Compare
Introduce a new TestAsset\ObjectHintsClass as a sample to be used in test. Also update generator tests to check for object type.
a8acf4e
to
b959211
Compare
Hello @webimpress, I've updated the code with your comments and fixed the test suite. I've made a mistake in the "validTypeProvider" method... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 And all green now. Thanks @shulard !
🚢 |
Hello,
This PR is about introducing the PHP7.2
object
type hint recently merged in the PHP core as requested in #110.