Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fine tune constructor types#32066

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:4.4fromTobion:fine-tune-constructor-types
Jun 17, 2019

Conversation

@Tobion
Copy link
Contributor

@TobionTobion commentedJun 16, 2019
edited
Loading

QA
Branch?4.4
Bug fix?no
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
Doc PRsymfony/symfony-docs#...

Fine tunes some constructor types that have been added in#24722

Form names as integer was only a workaround as forms names are used as array keys which get transformed to int. So it was added as a workaround in#6355 (comment)
With typehints added in#24722 those were mostly auto-cast anyway, e.g. in FormBuilder. There are only a few integer form names remaining documented, in the main entry points of the Form component (\Symfony\Component\Form\FormInterface::add). Internally it's always a string now. So I could remove some int docs which alsofixes#30032 what@xabbuh tried to do.

Some of these changes we're just not done before because of broken tests. It's mainly a missing explicit mock forTranslationInterface::trans which returned null. If we had return types hints in interfaces, this wouldn't happen.

publicfunctiongetMethod()
{
return$this->method;
return$this->method ??'GET';
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Must return string because of

return$this->request($link->getMethod(),$link->getUri());
whererequest has string type which would otherwise fail. So lets default back toGET which is in the constructor.

Copy link

@dFayetdFayetJun 17, 2019
edited
Loading

Choose a reason for hiding this comment

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

Will it not be better to set thenull replacement directly on themethod assignation in the__construct ?
Line 46:$this->method = $method ? strtoupper($method) : 'GET';

thrownewUnexpectedTypeException($child,'string, integer or Symfony\Component\Form\FormInterface');
}

$child = (string)$child;
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

The code forwarding this relies on the child name to be a string (instead of int)

* the name contains invalid characters
*/
publicfunction__construct($name, ?string$dataClass,EventDispatcherInterface$dispatcher,array$options = [])
publicfunction__construct(?string$name, ?string$dataClass,EventDispatcherInterface$dispatcher,array$options = [])
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

FormBuilder extendsFormConfigBuilder. In FormBuilder the $name was already changed in#24722 so it must be here too.

* @throws UnexpectedTypeException if the name is not a string or an integer
* @throws InvalidArgumentException if the name contains invalid characters
*
* @internal since Symfony 4.4
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This is only used in this single class. So wouldn't need to be public anymore. The whole method is not needed anyonce once we added real types in Form parameters in SF 5.

* @see http://tools.ietf.org/html/rfc2616#section-10.3
*/
publicfunction__construct(?string$url,int$status =302,array$headers = [])
publicfunction__construct(string$url,int$status =302,array$headers = [])
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

this was only nullable because of a unit test. but this is an error that is not meant to be caught. so it just throws a TypeError instead of\InvalidArgumentException

* violation
* @param int|null $plural The number for determining the plural
* form when translating the message
* @parammixed $code The error code of the violation
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

that must be an error. it cannot be mixed. \Symfony\Component\Validator\ConstraintViolationInterface::getCode says string|null. and calling code wouldn't be able to handle mixed.

Copy link
ContributorAuthor

@TobionTobionJun 17, 2019
edited
Loading

Choose a reason for hiding this comment

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

There is a test thatcode can be an int. So I couldn't add the string type. But the test is not respecting the contract asgetCode andsetCode both say string. But that is a topic for another time.

Copy link
Member

Choose a reason for hiding this comment

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

I am going to prepare a PR to deprecate using anything else than astring.

Copy link
Member

Choose a reason for hiding this comment

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

private$lockSetData =false;

/**
* @var string|int|null
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

this cannot be int anymore due to constructor types added in#24722

@TobionTobionforce-pushed thefine-tune-constructor-types branch 2 times, most recently from785b9cf to3baa43dCompareJune 17, 2019 01:12
* @return bool Whether the name is valid
*/
publicstaticfunctionisValidName($name)
finalpublicstaticfunctionisValidName(?string$name):bool
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

there is no point in people overwriting the method as its called withself instead of late static binding.

@TobionTobionforce-pushed thefine-tune-constructor-types branch from3baa43d to544bab4CompareJune 17, 2019 01:24
@TobionTobionforce-pushed thefine-tune-constructor-types branch from544bab4 to507794aCompareJune 17, 2019 01:43
Copy link
Member

@javiereguiluzjaviereguiluz left a comment

Choose a reason for hiding this comment

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

Tobias, thanks a lot for the time you took to carefully review (and explain) all this.

@fabpot
Copy link
Member

Thank you@Tobion.

@fabpotfabpot merged commit507794a intosymfony:4.4Jun 17, 2019
fabpot added a commit that referenced this pull requestJun 17, 2019
This PR was merged into the 4.4 branch.Discussion----------Fine tune constructor types| Q             | A| ------------- | ---| Branch?       | 4.4| Bug fix?      | no| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->| BC breaks?    | no     <!-- seehttps://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 || License       | MIT| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->Fine tunes some constructor types that have been added in#24722Form names as integer was only a workaround as forms names are used as array keys which get transformed to int. So it was added as a workaround in#6355 (comment)With typehints added in#24722 those were mostly auto-cast anyway, e.g. in FormBuilder. There are only a few integer form names remaining documented, in the main entry points of the Form component (`\Symfony\Component\Form\FormInterface::add`). Internally it's always a string now. So I could remove some int docs which alsofixes#30032 what@xabbuh tried to do.Some of these changes we're just not done before because of broken tests. It's mainly a missing explicit mock for `TranslationInterface::trans` which returned null. If we had return types hints in interfaces, this wouldn't happen.Commits-------507794a Fine tune constructor types
* @param TranslatorInterface $translator
*/
publicfunction__construct(ConstraintViolationList$violations,Constraint$constraint,$message,array$parameters,$root,$propertyPath,$invalidValue,$translator,$translationDomain =null)
publicfunction__construct(ConstraintViolationList$violations,Constraint$constraint,string$message,array$parameters,$root,string$propertyPath,$invalidValue,$translator,string$translationDomain =null)

Choose a reason for hiding this comment

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

this breaks the 3.4 CI, so let's allow null

Choose a reason for hiding this comment

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

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

The job you linked succeded?

Choose a reason for hiding this comment

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

Yes, I relaunched it after#32074 and it passed.

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedJun 17, 2019
edited
Loading

Given the broken tests on the CI, I'd be in favor of reverting this PR and adding a BC layer if we want to be strict on 5.0 instead.

@nicolas-grekas
Copy link
Member

Ok, I'm going to submit a BC layer instead of reverting.

@nicolas-grekas
Copy link
Member

See#32074

nicolas-grekas added a commit that referenced this pull requestJun 17, 2019
This PR was merged into the 4.4 branch.Discussion----------Add BC layer for updated constructor types| Q             | A| ------------- | ---| Branch?       | 4.4| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -Reverts some CS changes done in#32066 + replaces its BC breaks by a BC layer.Our CI is too good, it bites us hard when we break our own rules :)Commits-------c34fcd9 Add BC layer for updated constructor types
@TobionTobion deleted the fine-tune-constructor-types branchJune 17, 2019 20:03
symfony-splitter pushed a commit to symfony/validator that referenced this pull requestJul 3, 2019
…codes (xabbuh)This PR was merged into the 4.4 branch.Discussion----------[Validator] deprecate non-string constraint violation codes| Q             | A| ------------- | ---| Branch?       | 4.4| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | yes| Tests pass?   | yes| Fixed tickets |symfony/symfony#32066 (comment)| License       | MIT| Doc PR        |Commits-------e217729066 deprecate non-string constraint violation codes
fabpot added a commit that referenced this pull requestJul 3, 2019
…codes (xabbuh)This PR was merged into the 4.4 branch.Discussion----------[Validator] deprecate non-string constraint violation codes| Q             | A| ------------- | ---| Branch?       | 4.4| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | yes| Tests pass?   | yes| Fixed tickets |#32066 (comment)| License       | MIT| Doc PR        |Commits-------e217729 deprecate non-string constraint violation codes
@nicolas-grekasnicolas-grekas modified the milestones:next,4.4Oct 27, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@chalasrchalasrchalasr left review comments

@fabpotfabpotfabpot approved these changes

@javiereguiluzjaviereguiluzjaviereguiluz approved these changes

@xabbuhxabbuhAwaiting requested review from xabbuhxabbuh is a code owner

+1 more reviewer

@dFayetdFayetdFayet left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.4

Development

Successfully merging this pull request may close these issues.

8 participants

@Tobion@fabpot@nicolas-grekas@javiereguiluz@xabbuh@chalasr@dFayet@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp