Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DomCrawler] [5.0] add type-hint whenever possible #32329

Merged

Conversation

Simperfit
Copy link
Contributor

Q A
Branch? 5.0
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets Contribute to #32179
License MIT
Doc PR none

Add type hint to DomCrawler

src/Symfony/Component/DomCrawler/Crawler.php Show resolved Hide resolved
*
* @return array The list of fields as [string] Fully qualified name => (mixed) value)
*/
private function walk(array $array, $base = '', array &$output = [])
private function walk(array $array, ?string $base = '', array &$output = [])
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't ?string be instead string ?

Copy link
Member

Choose a reason for hiding this comment

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

is null actually allowed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we don't allow null, it break lots of test:

TypeError: Argument 2 passed to Symfony\Component\DomCrawler\FormFieldRegistry::walk() must be of the type string, null given, called in /home/hamza/projet/contrib/symfony/src/Symfony/Component/DomCrawler/FormFieldRegistry.php on line 133

Copy link
Member

Choose a reason for hiding this comment

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

So, it means that we need to ensure that $this->base cannot be null but an empty string instead. Or we need to change the calling code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can set the default value of $this->base to an empty string, that's the proposal I've pushed.

src/Symfony/Component/DomCrawler/Crawler.php Show resolved Hide resolved
src/Symfony/Component/DomCrawler/Crawler.php Show resolved Hide resolved
src/Symfony/Component/DomCrawler/Crawler.php Show resolved Hide resolved
src/Symfony/Component/DomCrawler/Crawler.php Show resolved Hide resolved
src/Symfony/Component/DomCrawler/Crawler.php Outdated Show resolved Hide resolved
*
* @return array The list of fields as [string] Fully qualified name => (mixed) value)
*/
private function walk(array $array, $base = '', array &$output = [])
private function walk(array $array, ?string $base = '', array &$output = [])
Copy link
Member

Choose a reason for hiding this comment

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

is null actually allowed ?

@nicolas-grekas nicolas-grekas added this to the 5.0 milestone Jul 3, 2019
@Simperfit Simperfit force-pushed the feature/add-type-hint-to-domcrawler branch from c8a3972 to a4ed068 Compare July 3, 2019 17:36
@derrabus derrabus mentioned this pull request Jul 3, 2019
57 tasks
src/Symfony/Component/DomCrawler/Field/FormField.php Outdated Show resolved Hide resolved
*
* @return array The list of fields as [string] Fully qualified name => (mixed) value)
*/
private function walk(array $array, $base = '', array &$output = [])
private function walk(array $array, ?string $base = '', array &$output = [])
Copy link
Member

Choose a reason for hiding this comment

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

So, it means that we need to ensure that $this->base cannot be null but an empty string instead. Or we need to change the calling code.

@Simperfit Simperfit force-pushed the feature/add-type-hint-to-domcrawler branch from a4ed068 to 580b126 Compare July 5, 2019 06:28
@Simperfit
Copy link
Contributor Author

done @fabpot
Status: Needs Review

@fabpot
Copy link
Member

fabpot commented Jul 8, 2019

Thank you @Simperfit.

@fabpot fabpot merged commit 580b126 into symfony:master Jul 8, 2019
fabpot added a commit that referenced this pull request Jul 8, 2019
…erfit)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[DomCrawler] [5.0] add type-hint whenever possible

| Q             | A
| ------------- | ---
| Branch?       | 5.0
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | Contribute to #32179   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | none <!-- required for new features -->

<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against branch 4.4.
 - Legacy code removals go to the master branch.
-->

Add type hint to DomCrawler

Commits
-------

580b126 [DomCrawler] [5.0] add type-hint whenever possible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants