Skip to content
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

Fix up PHPStan errors. #1955

Merged
merged 14 commits into from
Sep 4, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ public function objectMethods(ObjectBuilder $builder): string
if (!$this->getParameter('foreign_table')) {
throw new InvalidArgumentException(sprintf('You must define a \'foreign_table\' parameter for the \'aggregate_column\' behavior in the \'%s\' table', $this->getTable()->getName()));
}
$script = '';
$script .= $this->addObjectCompute($builder);
$script = $this->addObjectCompute($builder);
$script .= $this->addObjectUpdate();

return $script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ protected function getUpdateRelated(AbstractOMBuilder $builder): string
*/
public function queryMethods(AbstractOMBuilder $builder): string
{
$script = '';

$script .= $this->addQueryFindRelated($builder);
$script = $this->addQueryFindRelated($builder);
$script .= $this->addQueryUpdateRelated($builder);

return $script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ private function addAutoupdateBehaviorToForeignTable(): void
*/
public function objectMethods(ObjectBuilder $builder): string
{
$script = '';
$script .= $this->addObjectCompute($builder);
$script = $this->addObjectCompute($builder);
$script .= $this->addObjectUpdate();

return $script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ public function preDelete(AbstractOMBuilder $builder): ?string
public function objectMethods(AbstractOMBuilder $builder): string
{
$this->builder = $builder;
$script = '';
$script .= $this->addGetArchive($builder);
$script = $this->addGetArchive($builder);
$script .= $this->addArchive($builder);
$script .= $this->addRestoreFromArchive($builder);
$script .= $this->addPopulateFromArchive($builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ public function postUpdateQuery(AbstractOMBuilder $builder): ?string
*/
public function queryMethods(AbstractOMBuilder $builder): string
{
$script = '';
$script .= $this->addArchive($builder);
$script = $this->addArchive($builder);
if ($this->behavior->isArchiveOnUpdate()) {
$script .= $this->addSetArchiveOnUpdate($builder);
$script .= $this->addUpdateWithoutArchive($builder);
Expand Down
3 changes: 1 addition & 2 deletions src/Propel/Generator/Behavior/Delegate/DelegateBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ protected function getDelegateTable(string $delegateTableName): ?Table
*/
public function objectCall(ObjectBuilder $builder): string
{
$plural = false;
$script = '';
foreach ($this->delegates as $delegate => $type) {
$delegateTable = $this->getDelegateTable($delegate);
Expand All @@ -160,7 +159,7 @@ public function objectCall(ObjectBuilder $builder): string
$fk = $fks[0];
$ARClassName = $builder->getClassNameFromBuilder($builder->getNewStubObjectBuilder($fk->getTable()));
$ARFQCN = $builder->getNewStubObjectBuilder($fk->getTable())->getFullyQualifiedClassName();
$relationName = $builder->getRefFKPhpNameAffix($fk, $plural);
$relationName = $builder->getRefFKPhpNameAffix($fk);
} else {
$fks = $this->getTable()->getForeignKeysReferencingTable($delegate);
$fk = $fks[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ public function objectMethods(ObjectBuilder $builder): string
{
$this->builder = $builder;

$script = '';
$script .= $this->addSetLocale();
$script = $this->addSetLocale();
$script .= $this->addGetLocale();

$alias = $this->behavior->getParameter('locale_alias');
Expand Down Expand Up @@ -175,7 +174,6 @@ protected function addGetLocaleAlias(string $alias): string
*/
protected function addGetTranslation(): string
{
$plural = false;
$i18nTable = $this->behavior->getI18nTable();
$fk = $this->behavior->getI18nForeignKey();

Expand All @@ -185,7 +183,7 @@ protected function addGetTranslation(): string
'i18nListVariable' => $this->builder->getRefFKCollVarName($fk),
'localeColumnName' => $this->behavior->getLocaleColumn()->getPhpName(),
'i18nQueryName' => $this->builder->getClassNameFromBuilder($this->builder->getNewStubQueryBuilder($i18nTable)),
'i18nSetterMethod' => $this->builder->getRefFKPhpNameAffix($fk, $plural),
'i18nSetterMethod' => $this->builder->getRefFKPhpNameAffix($fk),
]);
}

Expand Down Expand Up @@ -262,13 +260,14 @@ protected function addTranslatedColumnSetter(Column $column): string
$objectBuilder = $this->builder->getNewObjectBuilder($this->behavior->getI18nTable());
$comment = '';
$functionStatement = '';

if ($this->isDateType($column->getType())) {
$objectBuilder->addTemporalMutatorComment($comment, $column);
$objectBuilder->addMutatorOpenOpen($functionStatement, $column);
} else {
$objectBuilder->addMutatorComment($comment, $column);
$objectBuilder->addMutatorOpenOpen($functionStatement, $column);
}

$objectBuilder->addMutatorOpenOpen($functionStatement, $column);
$comment = preg_replace('/^\t/m', '', $comment);
$comment = str_replace('@return $this|' . $i18nTablePhpName, '@return $this|' . $tablePhpName, $comment);
$functionStatement = preg_replace('/^\t/m', '', $functionStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public function __construct(I18nBehavior $behavior)
public function queryMethods(QueryBuilder $builder): string
{
$this->builder = $builder;
$script = '';
$script .= $this->addJoinI18n();
$script = $this->addJoinI18n();
$script .= $this->addJoinWithI18n();
$script .= $this->addUseI18nQuery();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,8 @@ public function isVersioningNecessary(?ConnectionInterface \$con = null): bool
if ({$queryClassName}::isVersioningEnabled() && (\$this->isNew() || \$this->isModified()) || \$this->isDeleted()) {
return true;
}";
$plural = false;
foreach ($this->behavior->getVersionableFks() as $fk) {
$fkGetter = $this->builder->getFKPhpNameAffix($fk, $plural);
$fkGetter = $this->builder->getFKPhpNameAffix($fk);
$script .= "
if (null !== (\$object = \$this->get{$fkGetter}(\$con)) && \$object->isVersioningNecessary(\$con)) {
return true;
Expand Down Expand Up @@ -428,9 +427,8 @@ public function addVersion(?ConnectionInterface \$con = null)
}
$script .= "
\$version->set{$this->table->getPhpName()}(\$this);";
$plural = false;
foreach ($this->behavior->getVersionableFks() as $fk) {
$fkGetter = $this->builder->getFKPhpNameAffix($fk, $plural);
$fkGetter = $this->builder->getFKPhpNameAffix($fk);
$fkVersionColumnName = $fk->getLocalColumnName() . '_version';
$fkVersionColumnPhpName = $versionTable->getColumn($fkVersionColumnName)->getPhpName();
$script .= "
Expand Down Expand Up @@ -534,7 +532,6 @@ public function populateFromVersion(\$version, \$con = null, &\$loadedObjects =
$script .= "
\$this->set" . $col->getPhpName() . '($version->get' . $col->getPhpName() . '());';
}
$plural = false;
foreach ($this->behavior->getVersionableFks() as $fk) {
$foreignTable = $fk->getForeignTable();

Expand All @@ -546,7 +543,7 @@ public function populateFromVersion(\$version, \$con = null, &\$loadedObjects =
$fkColumnName = $fk->getLocalColumnName();
$fkColumnPhpName = $fk->getLocalColumn()->getPhpName();
$fkVersionColumnPhpName = $versionTable->getColumn($fkColumnName . '_version')->getPhpName();
$fkPhpname = $this->builder->getFKPhpNameAffix($fk, $plural);
$fkPhpname = $this->builder->getFKPhpNameAffix($fk);
// FIXME: breaks lazy-loading
$script .= "
if (\$fkValue = \$version->get{$fkColumnPhpName}()) {
Expand All @@ -564,11 +561,9 @@ public function populateFromVersion(\$version, \$con = null, &\$loadedObjects =
\$this->set{$fkPhpname}(\$related);
}";
}
$plural = true;
foreach ($this->behavior->getVersionableReferrers() as $fk) {
$fkPhpNames = $this->builder->getRefFKPhpNameAffix($fk, $plural);
$plural = false;
$fkPhpName = $this->builder->getRefFKPhpNameAffix($fk, $plural);
$fkPhpNames = $this->builder->getRefFKPhpNameAffix($fk, true);
$fkPhpName = $this->builder->getRefFKPhpNameAffix($fk);
$foreignTable = $fk->getTable();
/** @var \Propel\Generator\Behavior\Versionable\VersionableBehavior $foreignBehavior */
$foreignBehavior = $foreignTable->getBehavior($this->behavior->getId());
Expand Down Expand Up @@ -872,12 +867,11 @@ public function compareVersions(int \$fromVersionNumber, int \$toVersionNumber,
*/
protected function addGetLastVersions(string &$script): void
{
$plural = true;
$versionTable = $this->behavior->getVersionTable();
$versionARClassName = $this->builder->getNewStubObjectBuilder($versionTable)->getClassName();
$versionTableMapClassName = $this->builder->getClassNameFromBuilder($this->builder->getNewTableMapBuilder($versionTable));
$fks = $versionTable->getForeignKeysReferencingTable($this->table->getName());
$relCol = $this->builder->getRefFKPhpNameAffix($fks[0], $plural);
$relCol = $this->builder->getRefFKPhpNameAffix($fks[0], true);
$versionGetter = 'get' . $relCol;
$colPrefix = Column::CONSTANT_PREFIX;

Expand Down
13 changes: 5 additions & 8 deletions src/Propel/Generator/Manager/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ public function build(): void
// -----------------------------------------------------------------------------------------

// these classes are only generated if they don't already exist
$overwrite = false;
foreach (['objectstub', 'querystub'] as $target) {
$builder = $generatorConfig->getConfiguredBuilder($table, $target);
$nbWrittenFiles += $this->doBuild($builder, $overwrite);
$nbWrittenFiles += $this->doBuild($builder, false);
}

// -----------------------------------------------------------------------------------------
Expand All @@ -93,22 +92,21 @@ public function build(): void
if ($col) {
if ($col->isEnumeratedClasses()) {
foreach ($col->getChildren() as $child) {
$overwrite = true;
foreach (['queryinheritance'] as $target) {
if (!$child->getAncestor() && $child->getClassName() === $table->getPhpName()) {
continue;
}
/** @var \Propel\Generator\Builder\Om\QueryInheritanceBuilder $builder */
$builder = $generatorConfig->getConfiguredBuilder($table, $target);
$builder->setChild($child);
$nbWrittenFiles += $this->doBuild($builder, $overwrite);
$nbWrittenFiles += $this->doBuild($builder);
}
$overwrite = false;

foreach (['objectmultiextend', 'queryinheritancestub'] as $target) {
/** @var \Propel\Generator\Builder\Om\MultiExtendObjectBuilder $builder */
$builder = $generatorConfig->getConfiguredBuilder($table, $target);
$builder->setChild($child);
$nbWrittenFiles += $this->doBuild($builder, $overwrite);
$nbWrittenFiles += $this->doBuild($builder, false);
}
}
}
Expand All @@ -119,10 +117,9 @@ public function build(): void
// -----------------------------------------------------------------------------------------

// Create [empty] interface if it does not already exist
$overwrite = false;
if ($table->getInterface()) {
$builder = $generatorConfig->getConfiguredBuilder($table, 'interface');
$nbWrittenFiles += $this->doBuild($builder, $overwrite);
$nbWrittenFiles += $this->doBuild($builder, false);
}

// ----------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/Propel/Generator/Model/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,6 @@ public function isContent(string $content): bool
{
$contentAttribute = $this->getAttribute('content');

return $contentAttribute && strtoupper($contentAttribute) === strtoupper($contentAttribute);
return $contentAttribute && strtoupper($contentAttribute) === strtoupper($content);
}
}
12 changes: 2 additions & 10 deletions src/Propel/Generator/Model/ConstraintNameGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace Propel\Generator\Model;

use Propel\Generator\Exception\EngineException;

/**
* A <code>NameGeneratorInterface</code> implementation for table-specific
* constraints. Conforms to the maximum column name length for the
Expand Down Expand Up @@ -39,8 +37,6 @@ class ConstraintNameGenerator implements NameGeneratorInterface
*
* @param array $inputs An array of input parameters
*
* @throws \Propel\Generator\Exception\EngineException
*
* @return string
*/
public function generateName(array $inputs): string
Expand All @@ -52,12 +48,8 @@ public function generateName(array $inputs): string
$constraintNbr = (string)$inputs[3];

// Calculate maximum RDBMS-specific column character limit.
try {
$maxColumnNameLength = $db->getMaxColumnNameLength();
$maxBodyLength = ($maxColumnNameLength - strlen($namePostfix) - strlen($constraintNbr) - 2);
} catch (EngineException $e) {
throw $e;
}
$maxColumnNameLength = $db->getMaxColumnNameLength();
$maxBodyLength = ($maxColumnNameLength - strlen($namePostfix) - strlen($constraintNbr) - 2);

// Do any necessary trimming.
if ($maxBodyLength !== -1 && strlen($name) > $maxBodyLength) {
Expand Down
3 changes: 1 addition & 2 deletions src/Propel/Generator/Model/Diff/ColumnDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ public function getReverseDiff(): self
*/
public function __toString(): string
{
$ret = '';
$ret .= sprintf(" %s:\n", $this->fromColumn->getFullyQualifiedName());
$ret = sprintf(" %s:\n", $this->fromColumn->getFullyQualifiedName());
$ret .= " modifiedProperties:\n";
foreach ($this->changedProperties as $key => $value) {
$ret .= sprintf(" %s: %s\n", $key, json_encode($value));
Expand Down
4 changes: 2 additions & 2 deletions src/Propel/Generator/Platform/DefaultPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ public function getDatabaseType(): string
{
$reflectionClass = new ReflectionClass($this);
$platformShortName = $reflectionClass->getShortName();
$length = strpos($platformShortName, 'Platform') ?: null;
$pos = strpos($platformShortName, 'Platform') ?: null;

return strtolower(substr($platformShortName, 0, $length));
return strtolower(substr($platformShortName, 0, $pos));
}

/**
Expand Down
6 changes: 2 additions & 4 deletions src/Propel/Generator/Platform/PgsqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ public function getAddForeignKeysDDL(Table $table): string
*/
public function getAddTableDDL(Table $table): string
{
$ret = '';
$ret .= $this->getUseSchemaDDL($table);
$ret = $this->getUseSchemaDDL($table);
$ret .= $this->getAddSequenceDDL($table);

$lines = [];
Expand Down Expand Up @@ -464,8 +463,7 @@ protected function getAddColumnComment(Column $column): string
*/
public function getDropTableDDL(Table $table): string
{
$ret = '';
$ret .= $this->getUseSchemaDDL($table);
$ret = $this->getUseSchemaDDL($table);
$pattern = "
DROP TABLE IF EXISTS %s CASCADE;
";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public function equals(?object $obj): bool
return true;
}

if (($obj === null) || !($obj instanceof AbstractCriterion)) {
if (!$obj instanceof AbstractCriterion) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function equals(?object $obj): bool
return true;
}

if ($obj === null || !($obj instanceof AbstractModelCriterion)) {
if (!$obj instanceof AbstractModelCriterion) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected function removeRecursiveSubqueryTableAliases(array &$sourceTableNames)
* joins with a null join type will be added to the FROM clause and the condition added to the WHERE clause.
* joins of a specified type: the LEFT side will be added to the fromClause and the RIGHT to the joinClause
*
* @param array<mixed>|null $params
* @param array|null $params
* @param array<string> $sourceTableNamesCollector
*
* @return array<string>
Expand Down Expand Up @@ -215,7 +215,7 @@ protected function getJoinTableNames(): array
/**
* this will also add the table names to the FROM clause if they are not already included via a LEFT JOIN
*
* @param array<mixed>|null $params
* @param array|null $params
* @param array<string> $sourceTableNamesCollector
*
* @return string|null
Expand Down Expand Up @@ -274,7 +274,7 @@ protected function setCriterionsIgnoreCase(AbstractCriterion $criterion, string
}

/**
* @param array<mixed> $params
* @param array $params
*
* @return array<string>
*/
Expand Down Expand Up @@ -344,7 +344,7 @@ protected function buildOrderByClause(array &$params): array
}

/**
* @param array<mixed> $params
* @param array $params
*
* @return string|null
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Propel/Runtime/Adapter/Pdo/MssqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function applyLimit(string &$sql, int $offset, int $limit, ?Criteria $cri

$nbOrders = count($orders);
for ($i = 0; $i < $nbOrders; $i++) {
$orderArr[trim(preg_replace('/\s+(ASC|DESC)$/i', '', $orders[$i]))] = [
$orderArr[trim((string)preg_replace('/\s+(ASC|DESC)$/i', '', $orders[$i]))] = [
'sort' => (stripos($orders[$i], ' DESC') !== false) ? 'DESC' : 'ASC',
'key' => $i,
];
Expand Down
Loading
Loading