Skip to content

Commit

Permalink
[CLEANUP] Drop redundant type casts (#1009)
Browse files Browse the repository at this point in the history
Fixes #934
  • Loading branch information
oliverklee committed Jun 25, 2022
1 parent d74f760 commit d53349f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
### Removed

### Fixed
- Drop redundant type casts (#1009)
- Always drop empty values for `intExplode` calls (#1000)
- Discard invalid gender values (#996)
- Avoid some version-specific tests (#964, #967)
Expand Down
2 changes: 1 addition & 1 deletion Classes/Configuration/FlexformsConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private function getFromXml(string $key): ?string
$matchingNodes = $this->xPath->query("/T3FlexForms/data/sheet/language/field[@index='{$key}']/value");
$firstMatchingNode = $matchingNodes instanceof \DOMNodeList ? $matchingNodes->item(0) : null;

return $firstMatchingNode instanceof \DOMNode ? (string)$firstMatchingNode->textContent : null;
return $firstMatchingNode instanceof \DOMNode ? $firstMatchingNode->textContent : null;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions Classes/Email/SystemEmailFromBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ class SystemEmailFromBuilder
{
/**
* Checks whether a valid email address has been set as defaultMailFromAddress.
*
* @return bool
*/
public function canBuild(): bool
{
$configuration = $this->getEmailConfiguration();
$emailAddress = (string)($configuration['defaultMailFromAddress'] ?? '');
$emailAddress = $configuration['defaultMailFromAddress'] ?? '';

return \filter_var($emailAddress, FILTER_VALIDATE_EMAIL) !== false;
}
Expand All @@ -34,8 +32,6 @@ protected function getEmailConfiguration(): array
}

/**
* @return GeneralEmailRole
*
* @throws \UnexpectedValueException
*/
public function build(): GeneralEmailRole
Expand All @@ -49,7 +45,8 @@ public function build(): GeneralEmailRole

return GeneralUtility::makeInstance(
GeneralEmailRole::class,
(string)MailUtility::getSystemFromAddress(),
MailUtility::getSystemFromAddress(),
// @phpstan-ignore-next-line `getSystemFromName` actually returns a nullable string.
(string)MailUtility::getSystemFromName()
);
}
Expand Down
12 changes: 6 additions & 6 deletions Classes/Mapper/AbstractDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,11 @@ private function createOneToManyRelation(array &$data, string $key, AbstractMode
}

$relationConfiguration = $this->getRelationConfigurationFromTca($key);
$foreignTable = (string)($relationConfiguration['foreign_table'] ?? '');
$foreignTable = $relationConfiguration['foreign_table'] ?? '';
if ($foreignTable === '') {
throw new \UnexpectedValueException('"foreign_table" is missing in the TCA.', 1646234422);
}
$foreignField = (string)($relationConfiguration['foreign_field'] ?? '');
$foreignField = $relationConfiguration['foreign_field'] ?? '';
if (!empty($relationConfiguration['foreign_sortby'])) {
$sortingField = $relationConfiguration['foreign_sortby'];
} elseif (!empty($relationConfiguration['foreign_default_sortby'])) {
Expand Down Expand Up @@ -582,7 +582,7 @@ private function createMToNRelation(array &$data, string $key, AbstractModel $mo
if ((int)$data[$key] > 0) {
$mapper = MapperRegistry::get($this->relations[$key]);
$relationConfiguration = $this->getRelationConfigurationFromTca($key);
$mnTable = (string)($relationConfiguration['MM'] ?? '');
$mnTable = $relationConfiguration['MM'] ?? '';
if ($mnTable === '') {
throw new \UnexpectedValueException('MM relation information missing.', 1646236363);
}
Expand Down Expand Up @@ -927,7 +927,7 @@ private function deleteManyToManyRelationIntermediateRecords(AbstractModel $mode
}

$relationConfiguration = $this->getRelationConfigurationFromTca($key);
$mnTable = (string)($relationConfiguration['MM'] ?? '');
$mnTable = $relationConfiguration['MM'] ?? '';
if ($mnTable === '') {
throw new \UnexpectedValueException('MM relation information missing.', 1646236349);
}
Expand All @@ -953,7 +953,7 @@ private function createManyToManyRelationIntermediateRecords(AbstractModel $mode

$sorting = 0;
$relationConfiguration = $this->getRelationConfigurationFromTca($key);
$mnTable = (string)($relationConfiguration['MM'] ?? '');
$mnTable = $relationConfiguration['MM'] ?? '';
if ($mnTable === '') {
throw new \UnexpectedValueException('MM relation information missing.', 1646236298);
}
Expand Down Expand Up @@ -996,7 +996,7 @@ private function saveOneToManyRelationRecords(AbstractModel $model): void
}

$relationConfiguration = $this->getRelationConfigurationFromTca($key);
$foreignField = (string)($relationConfiguration['foreign_field'] ?? '');
$foreignField = $relationConfiguration['foreign_field'] ?? '';
if ($foreignField === '') {
throw new \BadMethodCallException(
'The relation ' . $this->getTableName() . ':' . $key . ' is missing the "foreign_field" setting.',
Expand Down
2 changes: 1 addition & 1 deletion Classes/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private function load(): void
*/
public function getUid(): int
{
return (int)$this->uid;
return $this->uid;
}

/**
Expand Down
20 changes: 0 additions & 20 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ parameters:
count: 1
path: Classes/Configuration/FallbackConfiguration.php

-
message: "#^Casting to string something that's already string\\.$#"
count: 1
path: Classes/Configuration/FlexformsConfiguration.php

-
message: "#^Return type \\(array\\<int, string\\>\\) of method OliverKlee\\\\Oelib\\\\DataStructures\\\\AbstractObjectWithPublicAccessors\\:\\:getAsTrimmedArray\\(\\) should be covariant with return type \\(array\\<int, non\\-empty\\-string\\>\\) of method OliverKlee\\\\Oelib\\\\DataStructures\\\\AbstractReadOnlyObjectWithAccessors\\:\\:getAsTrimmedArray\\(\\)$#"
count: 1
Expand All @@ -30,21 +25,11 @@ parameters:
count: 1
path: Classes/DataStructures/AbstractReadOnlyObjectWithPublicAccessors.php

-
message: "#^Casting to string something that's already string\\.$#"
count: 3
path: Classes/Email/SystemEmailFromBuilder.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
path: Classes/Language/SalutationSwitcher.php

-
message: "#^Casting to string something that's already string\\.$#"
count: 6
path: Classes/Mapper/AbstractDataMapper.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 4
Expand Down Expand Up @@ -75,11 +60,6 @@ parameters:
count: 1
path: Classes/Mapper/FrontEndUserMapper.php

-
message: "#^Casting to int something that's already int\\.$#"
count: 1
path: Classes/Model/AbstractModel.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
Expand Down

0 comments on commit d53349f

Please sign in to comment.