8000 Fix redundant type casts by fancyweb · Pull Request #44330 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix redundant type casts #44330

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 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix redundant type casts
  • Loading branch information
fancyweb committed Nov 29, 2021
commit 4243335012c0f3f16ee3707d367e2b25f3efef24
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function createChoiceLabel(object $choice): string
*/
public static function createChoiceName(object $choice, $key, string $value): string
{
return str_replace('-', '_', (string) $value);
return str_replace('-', '_', $value);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

string $value in args

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private function __construct(array $thresholds = [], $regex = '', $verboseOutput
if (!isset($this->verboseOutput[$group])) {
throw new \InvalidArgumentException(sprintf('Unsupported verbosity group "%s", expected one of "%s".', $group, implode('", "', array_keys($this->verboseOutput))));
}
$this->verboseOutput[$group] = (bool) $status;
$this->verboseOutput[$group] = $status;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@param bool[] $verboseOutput in the doc + the constructor is private and only called with a $verboseOutput in fromUrlEncodedString() and inWeakMode() and we always set valid booleans values.

}

if ($generateBaseline && !$baselineFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function setUp(): void

protected function renderForm(FormView $view, array $vars = []): string
{
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() returns a string

}

protected function renderLabel(FormView $view, $label = null, array $vars = []): string
Expand All @@ -68,42 +68,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);
}

protected function renderHelp(FormView $view): string
{
return (string) $this->renderer->searchAndRenderBlock($view, 'help');
return $this->renderer->searchAndRenderBlock($view, 'help');
}

protected function renderErrors(FormView $view): string
{
return (string) $this->renderer->searchAndRenderBlock($view, 'errors');
return $this->renderer->searchAndRenderBlock($view, 'errors');
}

protected function renderWidget(FormView $view, array $vars = []): string
{
return (string) $this->renderer->searchAndRenderBlock($view, 'widget', $vars);
return $this->renderer->searchAndRenderBlock($view, 'widget', $vars);
}

protected function renderRow(FormView $view, array $vars = []): string
{
return (string) $this->renderer->searchAndRenderBlock($view, 'row', $vars);
return $this->renderer->searchAndRenderBlock($view, 'row', $vars);
}

protected function renderRest(FormView $view, array $vars = []): string
{
return (string) $this->renderer->searchAndRenderBlock($view, 'rest', $vars);
return $this->renderer->searchAndRenderBlock($view, 'rest', $vars);
}

protected function renderStart(FormView $view, array $vars = []): string
{
return (string) $this->renderer->renderBlock($view, 'form_start', $vars);
return $this->renderer->renderBlock($view, 'form_start', $vars);
}

protected function renderEnd(FormView $view, array $vars = []): string
{
return (string) $this->renderer->renderBlock($view, 'form_end', $vars);
return $this->renderer->renderBlock($view, 'form_end', $vars);
}

protected function setTheme(FormView $view, array $themes, $useDefaultThemes = true): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function testMoneyWidgetInIso()

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

protected function renderLabel(FormView $view, $label = null, array $vars = []): string
Expand All @@ -120,42 +120,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);
}

protected function renderHelp(FormView $view): string
{
return (string) $this->renderer->searchAndRenderBlock($view, 'help');
return $this->renderer->searchAndRenderBlock($view, 'help');
}

protected function renderErrors(FormView $view): string
{
return (string) $this->renderer->searchAndRenderBlock($view, 'errors');
return $this->renderer->searchAndRenderBlock($view, 'errors');
}

protected function renderWidget(FormView $view, array $vars = []): string
{
return (string) $this->renderer->searchAndRenderBlock($view, 'widget', $vars);
return $this->renderer->searchAndRenderBlock($view, 'widget', $vars);
}

protected function renderRow(FormView $view, array $vars = []): string
{
return (string) $this->renderer->searchAndRenderBlock($view, 'row', $vars);
return $this->renderer->searchAndRenderBlock($view, 'row', $vars);
}

protected function renderRest(FormView $view, array $vars = []): string
{
return (string) $this->renderer->searchAndRenderBlock($view, 'rest', $vars);
return $this->renderer->searchAndRenderBlock($view, 'rest', $vars);
}

protected function renderStart(FormView $view, array $vars = []): string
{
return (string) $this->renderer->renderBlock($view, 'form_start', $vars);
return $this->renderer->renderBlock($view, 'form_start', $vars);
}

protected function renderEnd(FormView $view, array $vars = []): string
{
return (string) $this->renderer->renderBlock($view, 'form_end', $vars);
return $this->renderer->renderBlock($view, 'form_end', $vars);
}

protected function setTheme(FormView $view, array $themes, $useDefaultThemes = true): void
Expand Down
11 changes: 4 additions & 7 deletions src/Symfony/Component/Console/Question/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function setHidden(bool $hidden)
throw new LogicException('A hidden question cannot use the autocompleter.');
}

F438 $this->hidden = (bool) $hidden;
$this->hidden = $hidden;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bool $hidden in args


return $this;
}
Expand All @@ -127,7 +127,7 @@ public function isHiddenFallback()
*/
public function setHiddenFallback(bool $fallback)
{
$this->hiddenFallback = (bool) $fallback;
$this->hiddenFallback = $fallback;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bool $fallback in args


return $this;
}
Expand Down Expand Up @@ -230,11 +230,8 @@ public function getValidator()
*/
public function setMaxAttempts(?int $attempts)
{
if (null !== $attempts) {
$attempts = (int) $attempts;
if ($attempts < 1) {
throw new InvalidArgumentException('Maximum number of attempts must be a positive value.');
}
if (null !== $attempts && $attempts < 1) {
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 $attempts in args

throw new InvalidArgumentException('Maximum number of attempts must be a positive value.');
}

$this->attempts = $attempts;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/DependencyInjection/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function setDecoratedService(?string $id, string $renamedId = null, int $
if (null === $id) {
$this->decoratedService = null;
} else {
$this->decoratedService = [$id, $renamedId, (int) $priority];
$this->decoratedService = [$id, $renamedId, $priority];
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 $priority = 0 in args


if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
$this->decoratedService[] = $invalidBehavior;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function set(string $name, $value)
*/
public function has(string $name)
{
return \array_key_exists((string) $name, $this->parameters);
return \array_key_exists($name, $this->parameters);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

string $name in args

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/AbstractRendererEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function setTheme(FormView $view, $themes, bool $useDefaultThemes = true)

// Do not cast, as casting turns objects into arrays of properties
$this->themes[$cacheKey] = \is_array($themes) ? $themes : [$themes];
$this->useDefaultThemes[$cacheKey] = (bool) $useDefaultThemes;
$this->useDefaultThemes[$cacheKey] = $useDefaultThemes;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bool $useDefaultThemes = true in args


// Unset instead of resetting to an empty array, in order to allow
// implementations (like TwigRendererEngine) to check whether $cacheKey
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/FormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function createNamedBuilder(string $name, string $type = FormType::class,

$type = $this->registry->getType($type);

$builder = $type->createBuilder($this, (string) $name, $options);
$builder = $type->createBuilder($this, $name, $options);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

1241

string $name in args


// Explicitly call buildForm() in order to be able to override either
// createBuilder() or buildForm() in the resolved form type
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Ldap/Adapter/ExtLdap/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function escape(string $subject, string $ignore = '', int $flags = 0)
$value = ldap_escape($subject, $ignore, $flags);

// Per RFC 4514, leading/trailing spaces should be encoded in DNs, as well as carriage returns.
if ((int) $flags & \LDAP_ESCAPE_DN) {
if ($flags & \LDAP_ESCAPE_DN) {
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 $flags = 0 in args

if (!empty($value) && ' ' === $value[0]) {
$value = '\\20'.substr($value, 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ protected function computeFallbackLocales(string $locale)
*/
protected function assertValidLocale(string $locale)
{
if (!preg_match('/^[a-z0-9@_\\.\\-]*$/i', (string) $locale)) {
if (!preg_match('/^[a-z0-9@_\\.\\-]*$/i', $locale)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

string $locale in args

throw new InvalidArgumentException(sprintf('Invalid "%s" locale.', $locale));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function addNamespaceAlias(string $alias, string $namespace)
protected function newConstraint(string $name, $options = null)
{
if (str_contains($name, '\\') && class_exists($name)) {
$className = (string) $name;
$className = $name;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

string $name in args

} elseif (str_contains($name, ':')) {
[$prefix, $className] = explode(':', $name, 2);

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/VarDumper/Cloner/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function __toString()
public function withMaxDepth(int $maxDepth)
{
$data = clone $this;
$data->maxDepth = (int) $maxDepth;
$data->maxDepth = $maxDepth;
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 $maxDepth in args


return $data;
}
Expand All @@ -220,7 +220,7 @@ public function withMaxDepth(int $maxDepth)
public function withMaxItemsPerDepth(int $maxItemsPerDepth)
{
$data = clone $this;
$data->maxItemsPerDepth = (int) $maxItemsPerDepth;
$data->maxItemsPerDepth = $maxItemsPerDepth;
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 $maxItemsPerDepth in args


return $data;
}
Expand Down
0