Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Introduce PHP7.2 object type hint #112

Merged
merged 2 commits into from
Jul 3, 2017

Conversation

shulard
Copy link
Contributor

@shulard shulard commented Jul 3, 2017

Hello,

This PR is about introducing the PHP7.2 object type hint recently merged in the PHP core as requested in #110.

@@ -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'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alignment is broken here

Copy link
Contributor Author

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'])
Copy link
Member

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
Copy link
Member

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'],
Copy link
Member

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'],
Copy link
Member

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

Copy link
Contributor Author

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.

@Ocramius
Copy link
Member

Ocramius commented Jul 3, 2017 via email

@shulard shulard force-pushed the feature/object-type-hint branch 2 times, most recently from fb4277e to b95a4e4 Compare July 3, 2017 11:19
@Ocramius
Copy link
Member

Ocramius commented Jul 3, 2017

Couple things here:

  1. Patch target should be changed to develop
  2. Bumped PHP to 7.1 and updated PHPUnit to ^6.2.2 #114 was just merged, and that may cause rebase conflicts

@Ocramius Ocramius added this to the 3.2.0 milestone Jul 3, 2017
@shulard shulard changed the base branch from master to develop July 3, 2017 17:56
Allow the TypeGenerator to recognize this new PHP7.2 internal type.

# Conflicts:
#	src/Generator/TypeGenerator.php
@shulard shulard force-pushed the feature/object-type-hint branch from b95a4e4 to 754faf1 Compare July 3, 2017 17:59
@shulard
Copy link
Contributor Author

shulard commented Jul 3, 2017

Hello,

I've updated the target branch and rebased on the develop branch 😄.

Copy link
Member

@Ocramius Ocramius left a 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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

@michalbundyra
Copy link
Member

@Ocramius tests still are failing !

@Ocramius
Copy link
Member

Ocramius commented Jul 3, 2017

Hmm, can you check up on the test failures?

@shulard shulard force-pushed the feature/object-type-hint branch from 754faf1 to c7b1922 Compare July 3, 2017 18:06
@shulard
Copy link
Contributor Author

shulard commented Jul 3, 2017

I've just removed the PHP 7.1 conditions in the tests...

Copy link
Member

@michalbundyra michalbundyra left a 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(
Copy link
Member

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) {

Copy link
Member

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'],
Copy link
Member

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?

@shulard shulard force-pushed the feature/object-type-hint branch from c7b1922 to a8acf4e Compare July 3, 2017 18:56
Introduce a new TestAsset\ObjectHintsClass as a sample to be used in test. Also update generator tests to check for object type.
@shulard shulard force-pushed the feature/object-type-hint branch from a8acf4e to b959211 Compare July 3, 2017 18:57
@shulard
Copy link
Contributor Author

shulard commented Jul 3, 2017

Hello @webimpress,

I've updated the code with your comments and fixed the test suite. I've made a mistake in the "validTypeProvider" method...

Copy link
Member

@michalbundyra michalbundyra left a 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 !

@Ocramius
Copy link
Member

Ocramius commented Jul 3, 2017

🚢

@Ocramius Ocramius merged commit 9f6eb29 into zendframework:develop Jul 3, 2017
@Ocramius Ocramius self-assigned this Jul 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants