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

Appearance settings

Fix redundant type casts #44274

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
Nov 28, 2021

Conversation

fancyweb
Copy link
Contributor

Q A
Branch? 4.4
Bug fix? no
New feature? no
Deprecations? -
Tickets -
License MIT
Doc PR -

Firstly, let's see if the CI is green as I expect it. I'll explain every change with a review comment.

@carsonbot carsonbot added this to the 4.4 milestone Nov 25, 2021
@fancyweb fancyweb force-pushed the minor/type-cast-redundancy branch from e390092 to 6158331 Compare November 25, 2021 12:16
src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php Outdated Show resolved Hide resolved
@@ -57,7 +57,7 @@ protected function setUp(): void

protected function renderForm(FormView $view, array $vars = [])
{
return (string) $this->renderer->renderBlock($view, 'form', $vars);
return $this->renderer->renderBlock($view, 'form', $vars);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FormRendererInterface::renderBlock() retturns a string

@@ -66,42 +66,42 @@ protected function renderLabel(FormView $view, $label = null, array $vars = [])
$vars += ['label' => $label];
}

return (string) $this->renderer->searchAndRenderBlock($view, 'label', $vars);
return $this->renderer->searchAndRenderBlock($view, 'label', $vars);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FormRendererInterface::searchAndRenderBlock() retturns a string (same for the others)

@@ -60,17 +60,7 @@ private function getGlobalVariables(): GlobalVariables
return $this->createMock(GlobalVariables::class);
}

private function getStorage(): StringStorage
{
return $this->getMockBuilder(StringStorage::class)
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 replaced the mock with a real instance.

@@ -730,7 +730,7 @@ private function createExpression(ContainerBuilder $container, string $expressio
private function createRequestMatcher(ContainerBuilder $container, string $path = null, string $host = null, int $port = null, array $methods = [], array $ips = null, array $attributes = []): Reference
{
if ($methods) {
$methods = array_map('strtoupper', (array) $methods);
$methods = array_map('strtoupper', $methods);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

array $methods in the method args

@@ -796,8 +796,6 @@ private function isInitializedAttribute(string $attr): bool
*/
private function convertValueDataType($value, int $type)
{
$type = (int) $type;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

int $type in the args

@@ -674,12 +674,12 @@ public function parseProvider()
return [
['prefix1', false, '->parse() does not parse a number with a string prefix.', 0],
['prefix1', false, '->parse() does not parse a number with a string prefix.', 0, false],
['1.4suffix', (float) 1.4, '->parse() parses a number with a string suffix.', 3],
['1.4suffix', (float) 1.4, '->parse() parses a number with a string suffix.', 3, false],
['1.4suffix', 1.4, '->parse() parses a number with a string suffix.', 3],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

1.4 is already a float

@@ -267,7 +267,7 @@ public function add(string $body, array $headers, int $delayInMs = 0): void
throw new TransportException(json_last_error_msg());
}

$score = (int) ($this->getCurrentTimeInMilliseconds() + $delayInMs);
$score = $this->getCurrentTimeInMilliseconds() + $delayInMs;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

getCurrentTimeInMilliseconds() returns an int, int $delayInMs = 0 in the args

@@ -35,7 +35,7 @@ public function __construct(string $template)
*/
public function __toString()
{
return (string) $this->template;
return $this->template;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The $template property is set by the constructor with the string $template arg.

@@ -653,7 +653,7 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
// no break
case '+' === $scalar[0] || '-' === $scalar[0] || '.' === $scalar[0] || is_numeric($scalar[0]):
if (Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar)) {
$scalar = str_replace('_', '', (string) $scalar);
$scalar = str_replace('_', '', $scalar);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

$scalar comes from $scalar = trim($scalar);, trim returns a string.

@fancyweb fancyweb force-pushed the minor/type-cast-redundancy branch from 6158331 to e724d5a Compare November 25, 2021 16:40
}

/**
* @return string
* @return string|false
Copy link
Member

Choose a reason for hiding this comment

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

But, right now, we guarantee a string, so this is a BC break.

@nicolas-grekas
Copy link
Member

Thank you @fancyweb.

@nicolas-grekas nicolas-grekas merged commit 7b27c8d into symfony:4.4 Nov 28, 2021
@fancyweb fancyweb deleted the minor/type-cast-redundancy branch November 29, 2021 12:19
nicolas-grekas added a commit that referenced this pull request Nov 29, 2021
This PR was merged into the 5.3 branch.

Discussion
----------

Fix redundant type casts

| Q             | A
| ------------- | ---
| Branch?       | 5.3
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Continuation of #44274 on 5.3

Commits
-------

4243335 Fix redundant type casts
symfony-splitter pushed a commit to symfony/translation that referenced this pull request Nov 29, 2021
This PR was merged into the 5.3 branch.

Discussion
----------

Fix redundant type casts

| Q             | A
| ------------- | ---
| Branch?       | 5.3
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Continuation of symfony/symfony#44274 on 5.3

Commits
-------

4243335012 Fix redundant type casts
SerhiyMytrovtsiy added a commit to SerhiyMytrovtsiy/translation that referenced this pull request Oct 19, 2022
This PR was merged into the 5.3 branch.

Discussion
----------

Fix redundant type casts

| Q             | A
| ------------- | ---
| Branch?       | 5.3
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Continuation of symfony/symfony#44274 on 5.3

Commits
-------

4243335012 Fix redundant type casts
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.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.