Skip to content

Remove redundant sprintf argument. #24613

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

Merged
merged 1 commit into from
Oct 26, 2017
Merged

Conversation

Aliance
Copy link
Contributor

@Aliance Aliance commented Oct 19, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #22820
License MIT
Doc PR

cc @fabpot @ogizanagi

@@ -53,6 +53,6 @@ protected function getVariableGetterWithStrictCheck($name)
return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : (function () { throw new Twig_Error_Runtime(\'Variable "%s" does not exist.\', 0, $this->getSourceContext()); })())', $name, $name, $name, $name);
}

return sprintf('($context["%s"] ?? $this->getContext($context, "%s"))', $name, $name, $name);
return sprintf('($context["%s"] ?? $this->getContext($context, "%s"))', $name, $name);
Copy link
Contributor

Choose a reason for hiding this comment

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

%1$s? thus assign $name once here as well.

Copy link
Member

Choose a reason for hiding this comment

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

Don't you find that notation (%1$s) difficult to understand? I always struggle with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

No strong opinion. Just to make things less error prone :) basically the two assignments must always stay the same, thus id prefer a single assignment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ro0NL I thought about it, but decided not to change. But I agree that %1$s is better.

Copy link
Member

Choose a reason for hiding this comment

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

I prefer %1$s. That's how sprintf() should be used to avoid duplications, and we already have some usages in the code base

@Tobion
Copy link
Contributor

Tobion commented Oct 19, 2017

This PR should be opened against 2.7 as it is wrong there as well.

@Tobion
Copy link
Contributor

Tobion commented Oct 19, 2017

@Aliance it's enough if you open a PR for 2.7. We then merge it upwards and will resolve conflicts.

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Oct 19, 2017
@Aliance Aliance changed the base branch from master to 2.7 October 20, 2017 09:44
@Aliance Aliance force-pushed the fix-sprintf-arguments branch from 0b88aed to c8012f0 Compare October 20, 2017 09:50
@Aliance
Copy link
Contributor Author

Aliance commented Oct 20, 2017

@Tobion I rebased it on 2.7, also changed duplicated arguments to %1$s and also tried to find all the same occurrences with regexp sprintf\('(.*?)', \$(.*?), \$\2\)

@@ -437,7 +437,7 @@ private function initialize()
// corresponding elements are either descendants or have a matching HTML5 form attribute
$formId = Crawler::xpathLiteral($this->node->getAttribute('id'));

$fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%s] | descendant::textarea[@form=%s] | descendant::select[@form=%s] | //form[@id=%s]//input[not(@form)] | //form[@id=%s]//button[not(@form)] | //form[@id=%s]//textarea[not(@form)] | //form[@id=%s]//select[not(@form)]', $formId, $formId, $formId, $formId, $formId, $formId, $formId, $formId));
$fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%1$s] | descendant::textarea[@form=%1$s] | descendant::select[@form=%1$s] | //form[@id=%1$s]//input[not(@form)] | //form[@id=%1$s]//button[not(@form)] | //form[@id=%1$s]//textarea[not(@form)] | //form[@id=%1$s]//select[not(@form)]', $formId));
Copy link
Contributor

@ro0NL ro0NL Oct 26, 2017

Choose a reason for hiding this comment

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

lol :) definitely up for %1$s now.

@Tobion
Copy link
Contributor

Tobion commented Oct 26, 2017

Good catch, thanks @Aliance.

@Tobion Tobion merged commit c8012f0 into symfony:2.7 Oct 26, 2017
Tobion added a commit that referenced this pull request Oct 26, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

Remove redundant sprintf argument.

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22820
| License       | MIT
| Doc PR        | –

cc @fabpot @ogizanagi

Commits
-------

c8012f0 Remove redundant sprintf arguments.
@Aliance Aliance deleted the fix-sprintf-arguments branch October 26, 2017 14:28
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.

7 participants