Skip to content

Commit

Permalink
Further PHP8 fixes
Browse files Browse the repository at this point in the history
Fix type error: `implode(): Argument #2 ($array) must be of type ?array, string given`
  • Loading branch information
maxbaldanza committed Sep 5, 2022
1 parent bb13f81 commit 61d24f9
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 45 deletions.
2 changes: 1 addition & 1 deletion generator/lib/builder/om/PHP5PeerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ public static function getPrimaryKeyFromRow(\$row, \$startcol = 0)
if ($table->hasCompositePrimaryKey()) {
$script .= "
return array(" . implode($pks, ', '). ");";
return array(" . implode(', ', $pks). ");";
} else {
$script .= "
Expand Down
4 changes: 2 additions & 2 deletions generator/lib/builder/om/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ protected function addFindPk(&$script)
}
$pkType = 'array';
$pkDescription = "
A Primary key composition: ".'['. join($colNames, ', ') . ']';
A Primary key composition: ".'['. join(', ', $colNames) . ']';
$script .= "
* <code>
* \$obj = \$c->findPk(array(" . join($examplePk, ', ') . "), \$con);";
* \$obj = \$c->findPk(array(" . join(', ', $examplePk) . "), \$con);";
} else {
$pkType = 'mixed';
$script .= "
Expand Down
2 changes: 1 addition & 1 deletion generator/lib/model/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public function addTable($data)
$this->tablesByName[$tbl->getName()] = $tbl;
$this->tablesByLowercaseName[strtolower($tbl->getName())] = $tbl;
$this->tablesByPhpName[$tbl->getPhpName()] = $tbl;
if (strpos($tbl->getNamespace(), '\\') === 0) {
if (strpos((string) $tbl->getNamespace(), '\\') === 0) {
$tbl->setNamespace(substr($tbl->getNamespace(), 1));
} elseif ($namespace = $this->getNamespace()) {
if ($tbl->getNamespace() === null) {
Expand Down
2 changes: 1 addition & 1 deletion generator/lib/model/XMLElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function booleanValue($val)
if (is_numeric($val)) {
return (bool) $val;
} else {
return (in_array(strtolower($val), array('true', 't', 'y', 'yes'), true) ? true : false);
return (in_array(strtolower((string) $val), array('true', 't', 'y', 'yes'), true) ? true : false);
}
}

Expand Down
8 changes: 3 additions & 5 deletions runtime/lib/collection/PropelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public function diff(PropelCollection $collection)
/**
* @return string
*/
public function serialize()
public function serialize(): string
{
$repr = array(
'data' => $this->getArrayCopy(),
Expand All @@ -371,10 +371,8 @@ public function serialize()

/**
* @param string $data
*
* @return void
*/
public function unserialize($data)
public function unserialize($data): void
{
$repr = unserialize($data);
$this->exchangeArray($repr['data']);
Expand All @@ -389,7 +387,7 @@ public function unserialize($data)
*
* @return ArrayIterator
*/
public function getIterator()
public function getIterator(): Iterator
{
$this->iterator = new ArrayIterator($this);

Expand Down
4 changes: 1 addition & 3 deletions runtime/lib/collection/PropelObjectCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ public function fromArray($arr)
* 'Book_1' => $book1,
* )
* </code>
*
* @return array
*/
public function getArrayCopy($keyColumn = null, $usePrefix = false)
public function getArrayCopy($keyColumn = null, $usePrefix = false): array
{
if (null === $keyColumn && false === $usePrefix) {
return parent::getArrayCopy();
Expand Down
7 changes: 3 additions & 4 deletions runtime/lib/config/PropelConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ public function __construct(array $parameters = array())
* @see http://www.php.net/ArrayAccess
*
* @param integer $offset
* @return boolean
*/
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return array_key_exists($offset, $this->parameters);
}
Expand All @@ -57,7 +56,7 @@ public function offsetExists($offset)
* @param integer $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
$this->parameters[$offset] = $value;
$this->isFlattened = false;
Expand All @@ -69,7 +68,7 @@ public function offsetSet($offset, $value)
* @param integer $offset
* @return array
*/
public function offsetGet($offset)
public function offsetGet($offset): array
{
return $this->parameters[$offset];
}
Expand Down
11 changes: 3 additions & 8 deletions runtime/lib/connection/DebugPDOStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ public function getExecutedQueryString()
* Overridden for query counting and logging.
*
* @param string $input_parameters
* @return boolean
*/
public function execute($input_parameters = null)
public function execute($input_parameters = null): bool
{
$debug = $this->pdo->getDebugSnapshot();
$return = parent::execute($input_parameters);
Expand All @@ -104,10 +103,8 @@ public function execute($input_parameters = null)
* @param integer $pos Parameter identifier (for determining what to replace in the query).
* @param mixed $value The value to bind to the parameter.
* @param integer $type Explicit data type for the parameter using the PDO::PARAM_* constants. Defaults to PDO::PARAM_STR.
*
* @return boolean
*/
public function bindValue($pos, $value, $type = PDO::PARAM_STR)
public function bindValue($pos, $value, $type = PDO::PARAM_STR): bool
{
$debug = $this->pdo->getDebugSnapshot();
$typestr = isset(self::$typeMap[$type]) ? self::$typeMap[$type] : '(default)';
Expand All @@ -133,10 +130,8 @@ public function bindValue($pos, $value, $type = PDO::PARAM_STR)
* @param integer $type Explicit data type for the parameter using the PDO::PARAM_* constants. Defaults to PDO::PARAM_STR.
* @param integer $length Length of the data type. To indicate that a parameter is an OUT parameter from a stored procedure, you must explicitly set the length.
* @param mixed $driver_options
*
* @return boolean
*/
public function bindParam($pos, &$value, $type = PDO::PARAM_STR, $length = 0, $driver_options = null)
public function bindParam($pos, &$value, $type = PDO::PARAM_STR, $length = 0, $driver_options = null): bool
{
$debug = $this->pdo->getDebugSnapshot();
$typestr = isset(self::$typeMap[$type]) ? self::$typeMap[$type] : '(default)';
Expand Down
30 changes: 12 additions & 18 deletions runtime/lib/connection/PropelPDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,8 @@ public function isCommitable()

/**
* Overrides PDO::beginTransaction() to prevent errors due to already-in-progress transaction.
*
* @return boolean
*/
public function beginTransaction()
public function beginTransaction(): bool
{
$return = true;
if (!$this->nestedTransactionCount) {
Expand All @@ -246,11 +244,9 @@ public function beginTransaction()
* Overrides PDO::commit() to only commit the transaction if we are in the outermost
* transaction nesting level.
*
* @return boolean
*
* @throws PropelException
*/
public function commit()
public function commit(): bool
{
$return = true;
$opcount = $this->nestedTransactionCount;
Expand Down Expand Up @@ -279,7 +275,7 @@ public function commit()
*
* @return boolean Whether operation was successful.
*/
public function rollBack()
public function rollBack(): bool
{
$return = true;
$opcount = $this->nestedTransactionCount;
Expand All @@ -301,11 +297,11 @@ public function rollBack()
}

/**
* Rollback the whole transaction, even if this is a nested rollback
* and reset the nested transaction count to 0.
* Rollback the whole transaction, even if this is a nested rollback
* and reset the nested transaction count to 0.
*
* @return boolean Whether operation was successful.
*/
* @return boolean Whether operation was successful.
*/
public function forceRollBack()
{
$return = true;
Expand Down Expand Up @@ -334,10 +330,8 @@ public function forceRollBack()
*
* @param integer $attribute The attribute to set (e.g. PropelPDO::PROPEL_ATTR_CACHE_PREPARES).
* @param mixed $value The attribute value.
*
* @return void
*/
public function setAttribute($attribute, $value)
public function setAttribute($attribute, $value): bool
{
switch ($attribute) {
case self::PROPEL_ATTR_CACHE_PREPARES:
Expand All @@ -347,8 +341,9 @@ public function setAttribute($attribute, $value)
$this->connectionName = $value;
break;
default:
parent::setAttribute($attribute, $value);
return parent::setAttribute($attribute, $value);
}
return true;
}

/**
Expand Down Expand Up @@ -415,9 +410,8 @@ public function prepare($sql, $driver_options = array())
* Overrides PDO::exec() to log queries when required
*
* @param string $sql
* @return integer
*/
public function exec($sql)
public function exec($sql): int
{
if ($this->useDebug) {
$debug = $this->getDebugSnapshot();
Expand Down Expand Up @@ -657,7 +651,7 @@ public function getDebugSnapshot()
'microtime' => microtime(true),
'memory_get_usage' => memory_get_usage($this->getLoggingConfig('realmemoryusage', false)),
'memory_get_peak_usage' => memory_get_peak_usage($this->getLoggingConfig('realmemoryusage', false)),
);
);
} else {
throw new PropelException('Should not get debug snapshot when not debugging');
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/lib/query/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function __construct($dbName = null)
* Implementing SPL IteratorAggregate interface. This allows
* you to foreach () over a Criteria object.
*/
public function getIterator()
public function getIterator(): Traversable
{
return new CriterionIterator($this);
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/lib/query/ModelCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ModelCriteria extends Criteria
* Creates a new instance with the default capacity which corresponds to
* the specified database.
*
* @param string $dbName The dabase name
* @param string $dbName The database name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
Expand Down

0 comments on commit 61d24f9

Please sign in to comment.