Skip to content

Commit

Permalink
Finish strict param refactoring (#1849)
Browse files Browse the repository at this point in the history
* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues

* TE-10483: Fixed remaining issues
  • Loading branch information
Dmytro Dymarchuk authored Mar 30, 2022
1 parent f6a2e5f commit 5bb404f
Show file tree
Hide file tree
Showing 40 changed files with 646 additions and 345 deletions.
11 changes: 11 additions & 0 deletions src/Propel/Generator/Builder/Om/AbstractOMBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ public function getNamespace(): ?string
return $this->getTable()->getNamespace();
}

/**
* Returns the user-defined namespace for this table,
* or the database namespace otherwise.
*
* @return string
*/
public function getNamespaceOrFail(): string
{
return $this->getTable()->getNamespaceOrFail();
}

/**
* This declares the class use and returns the correct name to use (short classname, Alias, or FQCN)
*
Expand Down
6 changes: 3 additions & 3 deletions src/Propel/Generator/Builder/Om/ObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3000,12 +3000,12 @@ protected function addToArray(string &$script): void
}
$script .= "
*
* @return array|string An associative array containing the field names (as keys) and field values
* @return array An associative array containing the field names (as keys) and field values
*/
public function toArray(string \$keyType = TableMap::$defaultKeyType, bool \$includeLazyLoadColumns = true, array \$alreadyDumpedObjects = []" . ($hasFks ? ', bool $includeForeignObjects = false' : '') . ")
public function toArray(string \$keyType = TableMap::$defaultKeyType, bool \$includeLazyLoadColumns = true, array \$alreadyDumpedObjects = []" . ($hasFks ? ', bool $includeForeignObjects = false' : '') . "): array
{
if (isset(\$alreadyDumpedObjects['$objectClassName'][\$this->hashCode()])) {
return '*RECURSION*';
return ['*RECURSION*'];
}
\$alreadyDumpedObjects['$objectClassName'][\$this->hashCode()] = true;
\$keys = " . $this->getTableMapClassName() . "::getFieldNames(\$keyType);
Expand Down
8 changes: 4 additions & 4 deletions src/Propel/Generator/Builder/Om/TableMapBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1025,21 +1025,21 @@ protected function addGetOMClassInheritance(string &$script): void
* objects that inherit from the default.
*
* @param array \$row ConnectionInterface result row.
* @param int \$colnum Column to examine for OM class information (first is 0).
* @param int \$colNum Column to examine for OM class information (first is 0).
* @param bool \$withPrefix Whether to return the path with the class name
* @throws \Propel\Runtime\Exception\PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*
* @return string The OM class
*/
public static function getOMClass(array \$row, int \$colnum, bool \$withPrefix = true): string
public static function getOMClass(array \$row, int \$colNum, bool \$withPrefix = true): string
{
try {
";
if ($col->isEnumeratedClasses()) {
$script .= "
\$omClass = null;
\$classKey = \$row[\$colnum + " . ($col->getPosition() - 1) . "];
\$classKey = \$row[\$colNum + " . ($col->getPosition() - 1) . "];
switch (\$classKey) {
";
Expand All @@ -1064,7 +1064,7 @@ public static function getOMClass(array \$row, int \$colnum, bool \$withPrefix =
";
} else { /* if not enumerated */
$script .= "
\$omClass = \$row[\$colnum + " . ($col->getPosition() - 1) . "];
\$omClass = \$row[\$colNum + " . ($col->getPosition() - 1) . "];
\$omClass = preg_replace('#\.#', '\\\\', '.'.\$omClass);
";
}
Expand Down
4 changes: 2 additions & 2 deletions src/Propel/Generator/Manager/MigrationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ public function getAlreadyExecutedMigrationTimestamps(): array
}

/**
* @return int
* @return int|null
*/
public function getFirstUpMigrationTimestamp(): int
public function getFirstUpMigrationTimestamp(): ?int
{
$validTimestamps = $this->getValidMigrationTimestamps();

Expand Down
18 changes: 18 additions & 0 deletions src/Propel/Generator/Model/Behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,24 @@ public function getTable(): ?Table
return $this->table;
}

/**
* Returns the table this behavior is applied to
*
* @throws \Propel\Generator\Exception\LogicException
*
* @return \Propel\Generator\Model\Table
*/
public function getTableOrFail(): Table
{
$table = $this->getTable();

if ($table === null) {
throw new LogicException('Table is not defined.');
}

return $table;
}

/**
* Sets the database this behavior is applied to
*
Expand Down
14 changes: 6 additions & 8 deletions src/Propel/Generator/Model/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Column extends MappingModel
];

/**
* @var string|null
* @var string
*/
private $name;

Expand Down Expand Up @@ -225,15 +225,13 @@ class Column extends MappingModel
/**
* Creates a new column and set the name.
*
* @param string|null $name The column's name
* @param string $name The column's name
* @param string|null $type The column's type
* @param string|int|null $size The column's size
*/
public function __construct(?string $name = null, ?string $type = null, $size = null)
public function __construct(string $name, ?string $type = null, $size = null)
{
if ($name !== null) {
$this->setName($name);
}
$this->setName($name);

if ($type !== null) {
$this->setType($type);
Expand Down Expand Up @@ -469,9 +467,9 @@ public function getFullyQualifiedName(): string
/**
* Returns the column name.
*
* @return string|null
* @return string
*/
public function getName(): ?string
public function getName(): string
{
return $this->name;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Propel/Generator/Model/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public function removeTable(Table $table): void
public function addTable($table): Table
{
if (!$table instanceof Table) {
$tbl = new Table();
$tbl = new Table($table['name']);
$tbl->setDatabase($this);
$tbl->loadMapping($table);

Expand Down
22 changes: 22 additions & 0 deletions src/Propel/Generator/Model/ScopedMappingModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Propel\Generator\Model;

use Propel\Generator\Exception\LogicException;

/**
* Data about an element with a name and optional namespace, schema and package
* attributes.
Expand Down Expand Up @@ -89,6 +91,26 @@ public function getNamespace(bool $getAbsoluteNamespace = false): ?string
return $this->namespace;
}

/**
* Returns the namespace.
*
* @param bool $getAbsoluteNamespace
*
* @throws \Propel\Generator\Exception\LogicException
*
* @return string
*/
public function getNamespaceOrFail(bool $getAbsoluteNamespace = false): string
{
$namespace = $this->getNamespace($getAbsoluteNamespace);

if ($namespace === null) {
throw new LogicException('Namespace is not defined.');
}

return $namespace;
}

/**
* Sets the namespace.
*
Expand Down
55 changes: 45 additions & 10 deletions src/Propel/Generator/Model/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Propel\Generator\Exception\BuildException;
use Propel\Generator\Exception\EngineException;
use Propel\Generator\Exception\InvalidArgumentException;
use Propel\Generator\Exception\LogicException;
use Propel\Generator\Platform\MysqlPlatform;
use Propel\Generator\Platform\PlatformInterface;
use Propel\Runtime\Exception\RuntimeException;
Expand Down Expand Up @@ -233,15 +234,13 @@ class Table extends ScopedMappingModel implements IdMethod
/**
* Constructs a table object with a name
*
* @param string|null $name table name
* @param string $name table name
*/
public function __construct(?string $name = null)
public function __construct(string $name)
{
parent::__construct();

if ($name !== null) {
$this->setCommonName($name);
}
$this->setCommonName($name);

$this->idMethod = IdMethod::NO_ID_METHOD;
$this->defaultAccessorVisibility = static::VISIBILITY_PUBLIC;
Expand All @@ -254,9 +253,9 @@ public function __construct(?string $name = null)
*
* If autoPrefix is set. Otherwise get the common name.
*
* @return string|null
* @return string
*/
private function getStdSeparatedName(): ?string
private function getStdSeparatedName(): string
{
if ($this->schema && $this->getBuildProperty('generator.schema.autoPrefix')) {
return $this->schema . NameGeneratorInterface::STD_SEPARATOR_CHAR . $this->getCommonName();
Expand Down Expand Up @@ -661,7 +660,7 @@ public function addColumn($col): Column
return $col;
}

$column = new Column();
$column = new Column($col['name']);
$column->setTable($this);
$column->loadMapping($col);

Expand Down Expand Up @@ -1335,9 +1334,9 @@ public function getCamelCaseName(): string
/**
* Returns the common name (without schema name), but with table prefix if defined.
*
* @return string|null
* @return string
*/
public function getCommonName(): ?string
public function getCommonName(): string
{
return $this->commonName;
}
Expand Down Expand Up @@ -1931,6 +1930,24 @@ public function getDatabase(): ?Database
return $this->database;
}

/**
* Get the database that contains this table.
*
* @throws \Propel\Generator\Exception\LogicException
*
* @return \Propel\Generator\Model\Database
*/
public function getDatabaseOrFail(): Database
{
$database = $this->getDatabase();

if ($database === null) {
throw new LogicException('Database is not defined.');
}

return $database;
}

/**
* Returns the Database platform.
*
Expand Down Expand Up @@ -2090,6 +2107,24 @@ public function getAutoIncrementPrimaryKey(): ?Column
return null;
}

/**
* Returns the auto incremented primary key.
*
* @throws \Propel\Generator\Exception\LogicException
*
* @return \Propel\Generator\Model\Column
*/
public function getAutoIncrementPrimaryKeyOrFail(): Column
{
$column = $this->getAutoIncrementPrimaryKey();

if ($column === null) {
throw new LogicException('Autoincrement primary key is not defined.');
}

return $column;
}

/**
* Returns whether there is a cross reference status for this foreign
* key.
Expand Down
36 changes: 36 additions & 0 deletions src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ public function getModelName(): ?string
return $this->modelName;
}

/**
* Returns the name of the class for this model criteria
*
* @throws \Propel\Runtime\Exception\LogicException
*
* @return string
*/
public function getModelNameOrFail(): string
{
$modelName = $this->getModelName();

if ($modelName === null) {
throw new LogicException('Model name is not defined.');
}

return $modelName;
}

/**
* Sets the model name.
* This also sets `this->modelTableMapName` and `this->tableMap`.
Expand Down Expand Up @@ -272,6 +290,24 @@ public function getTableMap(): ?TableMap
return $this->tableMap;
}

/**
* Returns the TableMap object for this Criteria
*
* @throws \Propel\Runtime\Exception\LogicException
*
* @return \Propel\Runtime\Map\TableMap
*/
public function getTableMapOrFail(): TableMap
{
$tableMap = $this->getTableMap();

if ($tableMap === null) {
throw new LogicException('Table map is not defined.');
}

return $tableMap;
}

/**
* Returns the name of the table as used in the query.
*
Expand Down
18 changes: 18 additions & 0 deletions src/Propel/Runtime/ActiveQuery/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,24 @@ public function getJoinCondition(): ?AbstractCriterion
return $this->joinCondition;
}

/**
* Get the custom join condition, if previously set
*
* @throws \Propel\Runtime\Exception\LogicException
*
* @return \Propel\Runtime\ActiveQuery\Criterion\AbstractCriterion
*/
public function getJoinConditionOrFail(): AbstractCriterion
{
$joinCondition = $this->getJoinCondition();

if ($joinCondition === null) {
throw new LogicException('Join condition is not defined.');
}

return $joinCondition;
}

/**
* Set the custom join condition Criterion based on the conditions of this join
*
Expand Down
8 changes: 8 additions & 0 deletions src/Propel/Runtime/ActiveRecord/ActiveRecordInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
* This ActiveRecord interface helps to find Propel Object
*
* @author jaugustin
*
* @method array toArray(string $keyType = \Propel\Runtime\Map\TableMap::TYPE_FIELDNAME, bool $includeLazyLoadColumns = true, array $alreadyDumpedObjects = [], bool $includeForeignObjects = false): array
*/
interface ActiveRecordInterface
{
/**
* Returns true if the primary key for this object is null.
*
* @return bool
*/
public function isPrimaryKeyNull(): bool;
}
Loading

0 comments on commit 5bb404f

Please sign in to comment.