Skip to content

Commit

Permalink
Fix CS by removing inline assignments. (#1946)
Browse files Browse the repository at this point in the history
* Fixed inline assignments

* Updated phpcs to disallow inline assignments

* Fixed inline assignments

* Fixed inline assignments

* Fixed inline assignments

* Fixed inline assignments
  • Loading branch information
michbeck committed Jan 20, 2023
1 parent 8aa4f2b commit 521dbe2
Show file tree
Hide file tree
Showing 19 changed files with 351 additions and 91 deletions.
3 changes: 3 additions & 0 deletions src/Propel/Generator/Behavior/I18n/I18nBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public function getI18nColumns(): array
$columns = [];
$i18nTable = $this->getI18nTable();
$columnNames = $this->getI18nColumnNamesFromConfig();

if ($columnNames) {
// Strategy 1: use the i18n_columns parameter
foreach ($columnNames as $columnName) {
Expand Down Expand Up @@ -386,8 +387,10 @@ protected function getLocaleColumnName(): string
protected function getI18nColumnNamesFromConfig(): array
{
$columnNames = explode(',', $this->getParameter('i18n_columns'));

foreach ($columnNames as $key => $columnName) {
$columnName = trim($columnName);

if ($columnName) {
$columnNames[$key] = $columnName;
} else {
Expand Down
30 changes: 16 additions & 14 deletions src/Propel/Generator/Behavior/Versionable/VersionableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,18 @@ public function getVersionTablePhpName(): string
*/
public function getVersionableFks(): array
{
$versionableFKs = [];
$fks = $this->getTable()->getForeignKeys();
if ($fks) {
foreach ($fks as $fk) {
if ($fk->getForeignTable()->hasBehavior($this->getName()) && !$fk->isComposite()) {
$versionableFKs[] = $fk;
}
$versionableForeignKeys = [];
if (!$this->getTable()) {
return $versionableForeignKeys;
}

foreach ($this->getTable()->getForeignKeys() as $foreignKey) {
if ($foreignKey->getForeignTable()->hasBehavior($this->getName()) && !$foreignKey->isComposite()) {
$versionableForeignKeys[] = $foreignKey;
}
}

return $versionableFKs;
return $versionableForeignKeys;
}

/**
Expand All @@ -273,12 +274,13 @@ public function getVersionableFks(): array
public function getVersionableReferrers(): array
{
$versionableReferrers = [];
$fks = $this->getTable()->getReferrers();
if ($fks) {
foreach ($fks as $fk) {
if ($fk->getTable()->hasBehavior($this->getName()) && !$fk->isComposite()) {
$versionableReferrers[] = $fk;
}
if (!$this->getTable()) {
return $versionableReferrers;
}

foreach ($this->getTable()->getReferrers() as $foreignKey) {
if ($foreignKey->getTable()->hasBehavior($this->getName()) && !$foreignKey->isComposite()) {
$versionableReferrers[] = $foreignKey;
}
}

Expand Down
29 changes: 15 additions & 14 deletions src/Propel/Generator/Builder/Om/ObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4123,8 +4123,8 @@ protected function addFKAttributes(string &$script, ForeignKey $fk): void
protected function addFKMutator(string &$script, ForeignKey $fk): void
{
$fkTable = $fk->getForeignTable();

$interface = $fk->getInterface();

if ($interface) {
$className = $this->declareClass($interface);
} else {
Expand Down Expand Up @@ -4211,13 +4211,12 @@ public function set" . $this->getFKPhpNameAffix($fk, false) . "($className \$v =
protected function addFKAccessor(string &$script, ForeignKey $fk): void
{
$table = $this->getTable();

$varName = $this->getFKVarName($fk);

$fkQueryBuilder = $this->getNewStubQueryBuilder($fk->getForeignTable());
$fkObjectBuilder = $this->getNewObjectBuilder($fk->getForeignTable())->getStubObjectBuilder();
$returnDesc = '';
$interface = $fk->getInterface();

if ($interface) {
$className = $this->declareClass($interface);
} else {
Expand Down Expand Up @@ -4324,7 +4323,7 @@ protected function addRefFKGetJoinMethods(string &$script, ForeignKey $refFK): v
$joinBehavior = $this->getBuildProperty('generator.objectModel.useLeftJoinsInDoJoinMethods') ? 'Criteria::LEFT_JOIN' : 'Criteria::INNER_JOIN';

$fkQueryClassName = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($refFK->getTable()));
$relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
$relCol = $this->getRefFKPhpNameAffix($refFK, true);

$className = $this->getClassNameFromTable($tblFK);

Expand Down Expand Up @@ -4422,9 +4421,11 @@ protected function addRefFKAttributes(string &$script, ForeignKey $refFK): void
*/
protected function addRefFKMethods(string &$script): void
{
if (!$referrers = $this->getTable()->getReferrers()) {
$referrers = $this->getTable()->getReferrers();
if (!$referrers) {
return;
}

$this->addInitRelations($script, $referrers);
foreach ($referrers as $refFK) {
$this->declareClassFromBuilder($this->getNewStubObjectBuilder($refFK->getTable()), 'Child');
Expand Down Expand Up @@ -4575,7 +4576,7 @@ protected function addRefFKAdd(string &$script, ForeignKey $refFK): void

$collName = $this->getRefFKCollVarName($refFK);

$scheduledForDeletion = lcfirst($this->getRefFKPhpNameAffix($refFK, $plural = true)) . 'ScheduledForDeletion';
$scheduledForDeletion = lcfirst($this->getRefFKPhpNameAffix($refFK, true)) . 'ScheduledForDeletion';

$script .= "
/**
Expand All @@ -4588,7 +4589,7 @@ protected function addRefFKAdd(string &$script, ForeignKey $refFK): void
public function add" . $this->getRefFKPhpNameAffix($refFK, false) . "($className \$l)
{
if (\$this->$collName === null) {
\$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "();
\$this->init" . $this->getRefFKPhpNameAffix($refFK, true) . "();
\$this->{$collName}Partial = true;
}
Expand Down Expand Up @@ -4616,7 +4617,7 @@ public function add" . $this->getRefFKPhpNameAffix($refFK, false) . "($className
protected function addRefFKCount(string &$script, ForeignKey $refFK): void
{
$fkQueryClassName = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($refFK->getTable()));
$relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
$relCol = $this->getRefFKPhpNameAffix($refFK, true);
$collName = $this->getRefFKCollVarName($refFK);

$joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
Expand Down Expand Up @@ -4670,7 +4671,7 @@ public function count{$relCol}(?Criteria \$criteria = null, bool \$distinct = fa
protected function addRefFKGet(string &$script, ForeignKey $refFK): void
{
$fkQueryClassName = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($refFK->getTable()));
$relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
$relCol = $this->getRefFKPhpNameAffix($refFK, true);
$collName = $this->getRefFKCollVarName($refFK);

$className = $this->getClassNameFromTable($refFK->getTable());
Expand Down Expand Up @@ -4698,7 +4699,7 @@ public function get$relCol(?Criteria \$criteria = null, ?ConnectionInterface \$c
if (\$this->isNew()) {
// return empty collection
if (null === \$this->$collName) {
\$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "();
\$this->init" . $this->getRefFKPhpNameAffix($refFK, true) . "();
} else {
\$collectionClassName = " . $this->getClassNameFromBuilder($this->getNewTableMapBuilder($refFK->getTable())) . "::getTableMap()->getCollectionClassName();
Expand All @@ -4714,7 +4715,7 @@ public function get$relCol(?Criteria \$criteria = null, ?ConnectionInterface \$c
if (null !== \$criteria) {
if (false !== \$this->{$collName}Partial && count(\$$collName)) {
\$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "(false);
\$this->init" . $this->getRefFKPhpNameAffix($refFK, true) . "(false);
foreach (\$$collName as \$obj) {
if (false == \$this->{$collName}->contains(\$obj)) {
Expand Down Expand Up @@ -4862,7 +4863,7 @@ protected function addRefFKRemove(string &$script, ForeignKey $refFK): void
$className = $this->getClassNameFromTable($refFK->getTable());
}

$relatedName = $this->getRefFKPhpNameAffix($refFK, $plural = true);
$relatedName = $this->getRefFKPhpNameAffix($refFK, true);
$relatedObjectClassName = $this->getRefFKPhpNameAffix($refFK, false);
$inputCollection = lcfirst($relatedName . 'ScheduledForDeletion');
$lowerRelatedObjectClassName = lcfirst($relatedObjectClassName);
Expand Down Expand Up @@ -5277,7 +5278,7 @@ protected function addCrossFkScheduledForDeletion(string &$script, CrossForeignK
*/
protected function addRefFkScheduledForDeletion(string &$script, ForeignKey $refFK): void
{
$relatedName = $this->getRefFKPhpNameAffix($refFK, $plural = true);
$relatedName = $this->getRefFKPhpNameAffix($refFK, true);
$lowerRelatedName = lcfirst($relatedName);
$lowerSingleRelatedName = lcfirst($this->getRefFKPhpNameAffix($refFK, false));
$queryClassName = $this->getNewStubQueryBuilder($refFK->getTable())->getClassname();
Expand Down Expand Up @@ -5373,7 +5374,7 @@ public function clear{$relCol}()
*/
protected function addRefFKPartial(string &$script, ForeignKey $refFK): void
{
$relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
$relCol = $this->getRefFKPhpNameAffix($refFK, true);
$collName = $this->getRefFKCollVarName($refFK);

$script .= "
Expand Down
5 changes: 1 addition & 4 deletions src/Propel/Generator/Builder/Om/TableMapBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,8 @@ public static function getValueSet(string \$colname): array
public function addInheritanceColumnConstants(string &$script): void
{
$col = $this->getTable()->getChildrenColumn();
if (!$col) {
return;
}

if (!$col->isEnumeratedClasses()) {
if (!$col || !$col->isEnumeratedClasses()) {
return;
}

Expand Down
25 changes: 14 additions & 11 deletions src/Propel/Generator/Config/GeneratorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,22 @@ public function getConfiguredPluralizer(): PluralizerInterface
*/
public function getBuildConnections(): array
{
if ($this->buildConnections === null) {
$connectionNames = $this->get()['generator']['connections'];
if ($this->buildConnections !== null) {
return $this->buildConnections;
}

$reverseConnection = $this->getConfigProperty('reverse.connection');
if ($reverseConnection !== null && !in_array($reverseConnection, $connectionNames, true)) {
$connectionNames[] = $reverseConnection;
}
$connectionNames = $this->get()['generator']['connections'];
$reverseConnection = $this->getConfigProperty('reverse.connection');

foreach ($connectionNames as $name) {
$definition = $this->getConfigProperty('database.connections.' . $name);
if ($definition) {
$this->buildConnections[$name] = $definition;
}
if ($reverseConnection !== null && !in_array($reverseConnection, $connectionNames, true)) {
$connectionNames[] = $reverseConnection;
}

foreach ($connectionNames as $name) {
$definition = $this->getConfigProperty('database.connections.' . $name);

if ($definition) {
$this->buildConnections[$name] = $definition;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Propel/Generator/Model/Behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,9 @@ public function getColumnForParameter(string $name): ?Column
protected function setupObject(): void
{
$this->setName($this->getAttribute('name'));
$id = $this->getAttribute('id');

if (!$this->allowMultiple() && $id = $this->getAttribute('id')) {
if (!$this->allowMultiple() && $id) {
throw new LogicException(sprintf('Defining an ID (%s) on a behavior which does not allow multiple instances makes no sense', $id));
}

Expand Down
91 changes: 79 additions & 12 deletions src/Propel/Generator/Model/Diff/DatabaseDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,26 @@ public function getReverseDiff(): self
*/
public function getDescription(): string
{
$numberOfAddedTables = $this->countAddedTables();
$numberOfRemovedTables = $this->countRemovedTables();
$numberOfModifiedTables = $this->countModifiedTables();
$numberOfRenamedTables = $this->countRenamedTables();
$changes = [];
if ($count = $this->countAddedTables()) {
$changes[] = sprintf('%d added tables', $count);

if ($numberOfAddedTables) {
$changes[] = sprintf('%d added tables', $numberOfAddedTables);
}
if ($count = $this->countRemovedTables()) {
$changes[] = sprintf('%d removed tables', $count);

if ($numberOfRemovedTables) {
$changes[] = sprintf('%d removed tables', $numberOfRemovedTables);
}
if ($count = $this->countModifiedTables()) {
$changes[] = sprintf('%d modified tables', $count);

if ($numberOfModifiedTables) {
$changes[] = sprintf('%d modified tables', $numberOfModifiedTables);
}
if ($count = $this->countRenamedTables()) {
$changes[] = sprintf('%d renamed tables', $count);

if ($numberOfRenamedTables) {
$changes[] = sprintf('%d renamed tables', $numberOfRenamedTables);
}

return implode(', ', $changes);
Expand All @@ -358,26 +366,85 @@ public function getDescription(): string
public function __toString(): string
{
$ret = '';
if ($addedTables = $this->getAddedTables()) {
$ret = $this->appendAddedTablesToString($ret);
$ret = $this->appendRemovedTablesToString($ret);
$ret = $this->appendModifiedTablesToString($ret);

return $this->appendRenamedTablesToString($ret);
}

/**
* @param string $ret
*
* @return string
*/
protected function appendAddedTablesToString(string $ret): string
{
$addedTables = $this->getAddedTables();

if ($addedTables) {
$ret .= "addedTables:\n";

foreach ($addedTables as $tableName => $table) {
$ret .= sprintf(" - %s\n", $tableName);
}
}
if ($removedTables = $this->getRemovedTables()) {

return $ret;
}

/**
* @param string $ret
*
* @return string
*/
protected function appendRemovedTablesToString(string $ret): string
{
$removedTables = $this->getRemovedTables();

if ($removedTables) {
$ret .= "removedTables:\n";

foreach ($removedTables as $tableName => $table) {
$ret .= sprintf(" - %s\n", $tableName);
}
}
if ($modifiedTables = $this->getModifiedTables()) {

return $ret;
}

/**
* @param string $ret
*
* @return string
*/
protected function appendModifiedTablesToString(string $ret): string
{
$modifiedTables = $this->getModifiedTables();

if ($modifiedTables) {
$ret .= "modifiedTables:\n";

foreach ($modifiedTables as $tableDiff) {
$ret .= $tableDiff->__toString();
}
}
if ($renamedTables = $this->getRenamedTables()) {

return $ret;
}

/**
* @param string $ret
*
* @return string
*/
protected function appendRenamedTablesToString(string $ret): string
{
$renamedTables = $this->getRenamedTables();

if ($renamedTables) {
$ret .= "renamedTables:\n";

foreach ($renamedTables as $fromName => $toName) {
$ret .= sprintf(" %s: %s\n", $fromName, $toName);
}
Expand Down
Loading

0 comments on commit 521dbe2

Please sign in to comment.