Skip to content

Commit

Permalink
Fix Psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianoc72 committed Oct 14, 2021
1 parent 31b45e9 commit 8741fd3
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 47 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ tests/Fixtures/schemas/build/
tests/Fixtures/bookstore/build/
tests/Fixtures/bookstore/propel.yaml

tests/Fixtures/bookstore-packaged/

tests/Fixtures/namespaced/propel.yaml

tests/Fixtures/schemas/propel.yaml
Expand Down
6 changes: 3 additions & 3 deletions src/Propel/Generator/Model/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ public function setupObject()
/**
* Returns a build property value for the database this table belongs to.
*
* @param string $key
* @param string $name
*
* @return string
*/
public function getBuildProperty($key)
public function getBuildProperty($name)
{
return $this->database ? $this->database->getBuildProperty($key) : '';
return $this->database ? $this->database->getBuildProperty($name) : '';
}

/**
Expand Down
22 changes: 11 additions & 11 deletions src/Propel/Generator/Platform/DefaultPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,19 @@ public function isNativeIdMethodAutoIncrement()
/**
* Returns the database specific domain for a mapping type.
*
* @param string $mappingType
* @param string $propelType
*
* @throws \Propel\Generator\Exception\EngineException
*
* @return \Propel\Generator\Model\Domain
*/
public function getDomainForType($mappingType)
public function getDomainForType($propelType)
{
if (!isset($this->schemaDomainMap[$mappingType])) {
throw new EngineException(sprintf('Cannot map unknown Propel type %s to native database type.', var_export($mappingType, true)));
if (!isset($this->schemaDomainMap[$propelType])) {
throw new EngineException(sprintf('Cannot map unknown Propel type %s to native database type.', var_export($propelType, true)));
}

return $this->schemaDomainMap[$mappingType];
return $this->schemaDomainMap[$propelType];
}

/**
Expand Down Expand Up @@ -1363,23 +1363,23 @@ public function supportsVarcharWithoutSize()
* This function is used to set default column values when building
* SQL.
*
* @param bool|int|string $b A Boolean or string representation of Boolean ('y', 'true').
* @param bool|int|string $value A Boolean or string representation of Boolean ('y', 'true').
*
* @return string
*/
public function getBooleanString($b)
public function getBooleanString($value)
{
if (is_bool($b) && $b === true) {
if (is_bool($value) && $value === true) {
return '1';
}

if (is_int($b) && $b === 1) {
if (is_int($value) && $value === 1) {
return '1';
}

if (
is_string($b)
&& in_array(strtolower($b), ['1', 'true', 'y', 'yes'])
is_string($value)
&& in_array(strtolower($value), ['1', 'true', 'y', 'yes'])
) {
return '1';
}
Expand Down
8 changes: 4 additions & 4 deletions src/Propel/Generator/Platform/PgsqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ public function getMaxColumnNameLength()
}

/**
* @param mixed $b
* @param mixed $value
*
* @return string
*/
public function getBooleanString($b)
public function getBooleanString($value)
{
// parent method does the checking for allows string
// representations & returns integer
$b = parent::getBooleanString($b);
$value = parent::getBooleanString($value);

return ($b ? "'t'" : "'f'");
return ($value ? "'t'" : "'f'");
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Propel/Generator/Platform/PlatformInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ public function supportsVarcharWithoutSize();
* This function is used to set default column values when building
* SQL.
*
* @param mixed $tf A boolean or string representation of boolean ('y', 'true').
* @param mixed $value A boolean or string representation of boolean ('y', 'true').
*
* @return string
*/
public function getBooleanString($tf);
public function getBooleanString($value);

/**
* Whether the underlying PDO driver for this platform returns BLOB columns as streams (instead of strings).
Expand Down
20 changes: 18 additions & 2 deletions src/Propel/Generator/Platform/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Propel\Generator\Platform;

use PDO;
use Propel\Generator\Config\GeneratorConfigInterface;
use Propel\Generator\Model\Column;
use Propel\Generator\Model\ColumnDefaultValue;
Expand All @@ -19,6 +20,7 @@
use Propel\Generator\Model\PropelTypes;
use Propel\Generator\Model\Table;
use Propel\Generator\Model\Unique;
use Propel\Runtime\Connection\PdoConnection;
use SQLite3;

/**
Expand Down Expand Up @@ -53,8 +55,7 @@ protected function initialize()
{
parent::initialize();

$version = SQLite3::version();
$version = $version['versionString'];
$version = $this->getVersion();

$this->foreignKeySupport = version_compare($version, '3.6.19') >= 0;

Expand Down Expand Up @@ -609,4 +610,19 @@ public function supportsNativeDeleteTrigger()
{
return true;
}

/**
* @return string
*/
protected function getVersion(): string
{
if (class_exists(SQLite3::class)) {
return SQLite3::version()['versionString'];
}

//if php_sqlite3 extension is not installed, we need to query the database
$connection = new PdoConnection('sqlite::memory:');

return (string)$connection->query('SELECT sqlite_version()')->fetch(PDO::FETCH_NUM)[0];
}
}
2 changes: 1 addition & 1 deletion src/Propel/Generator/Reverse/MysqlSchemaParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ protected function addIndexes(Table $table)
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$colName = $row['Column_name'];
$colSize = $row['Sub_part'];
$name = $row['Key_name'];
$name = (string)$row['Key_name'];

if ($name === 'PRIMARY') {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Propel/Generator/Reverse/OracleSchemaParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ protected function addForeignKeys(Table $table)
$stmt3 = $this->dbh->query("SELECT TABLE_NAME, COLUMN_NAME FROM USER_CONS_COLUMNS WHERE CONSTRAINT_NAME = '" . $row['R_CONSTRAINT_NAME'] . "'");
$foreignReferenceInfo = $stmt3->fetch(PDO::FETCH_ASSOC);

if (!isset($foreignKeys[$row['CONSTRAINT_NAME']])) {
if (!isset($foreignKeys[(string)$row['CONSTRAINT_NAME']])) {
$fk = new ForeignKey($row['CONSTRAINT_NAME']);
$fk->setForeignTableCommonName($foreignReferenceInfo['TABLE_NAME']);
$onDelete = ($row['DELETE_RULE'] === 'NO ACTION') ? 'NONE' : $row['DELETE_RULE'];
Expand Down
4 changes: 2 additions & 2 deletions src/Propel/Runtime/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ interface AdapterInterface
/**
* Build database connection
*
* @param array $conparams connection parameters
* @param array $params connection parameters
*
* @return \Propel\Runtime\Connection\ConnectionInterface
*/
public function getConnection($conparams);
public function getConnection($params);

/**
* Sets the character encoding using SQL standard SET NAMES statement.
Expand Down
4 changes: 2 additions & 2 deletions src/Propel/Runtime/Adapter/MSSQL/MssqlPropelPDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ public function forceRollBack()
}

/**
* @param string|null $seqname
* @param string|null $name
*
* @return int
*/
public function lastInsertId($seqname = null)
public function lastInsertId($name = null)
{
$result = $this->query('SELECT SCOPE_IDENTITY()');

Expand Down
26 changes: 13 additions & 13 deletions src/Propel/Runtime/Adapter/Pdo/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,30 @@ abstract class PdoAdapter
/**
* Build database connection
*
* @param array $conparams connection parameters
* @param array $params connection parameters
*
* @throws \Propel\Runtime\Exception\InvalidArgumentException
* @throws \Propel\Runtime\Adapter\Exception\AdapterException
*
* @return \Propel\Runtime\Connection\PdoConnection
*/
public function getConnection($conparams)
public function getConnection($params)
{
$conparams = $this->prepareParams($conparams);
$params = $this->prepareParams($params);

if (!isset($conparams['dsn'])) {
if (!isset($params['dsn'])) {
throw new InvalidArgumentException('No dsn specified in your connection parameters');
}

$dsn = $conparams['dsn'];
$user = isset($conparams['user']) ? $conparams['user'] : null;
$password = isset($conparams['password']) ? $conparams['password'] : null;
$dsn = $params['dsn'];
$user = isset($params['user']) ? $params['user'] : null;
$password = isset($params['password']) ? $params['password'] : null;

// load any driver options from the config file
// driver options are those PDO settings that have to be passed during the connection construction
$driverOptions = [];
if (isset($conparams['options']) && is_array($conparams['options'])) {
foreach ($conparams['options'] as $option => $optiondata) {
if (isset($params['options']) && is_array($params['options'])) {
foreach ($params['options'] as $option => $optiondata) {
$value = $optiondata;
if (is_string($value) && strpos($value, '::') !== false) {
if (!defined($value)) {
Expand All @@ -77,7 +77,7 @@ public function getConnection($conparams)

try {
$con = new PdoConnection($dsn, $user, $password, $driverOptions);
$this->initConnection($con, isset($conparams['settings']) && is_array($conparams['settings']) ? $conparams['settings'] : []);
$this->initConnection($con, isset($params['settings']) && is_array($params['settings']) ? $params['settings'] : []);
} catch (PDOException $e) {
throw new AdapterException('Unable to open PDO connection', 0, $e);
}
Expand Down Expand Up @@ -110,13 +110,13 @@ public function getAdapterId()
/**
* Prepare the parameters for a Connection
*
* @param array $conparams the connection parameters from the configuration
* @param array $params the connection parameters from the configuration
*
* @return array the modified parameters
*/
protected function prepareParams($conparams)
protected function prepareParams($params)
{
return $conparams;
return $params;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Propel/Runtime/Connection/ProfilerStatementWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public function bindValue($parameter, $value, $dataType = PDO::PARAM_STR)
* Executes a prepared statement. Returns a boolean value indicating success.
* Overridden for query counting and logging.
*
* @param array|null $parameters
* @param array|null $inputParameters
*
* @return bool
*/
public function execute($parameters = null)
public function execute($inputParameters = null)
{
$this->connection->getProfiler()->start();

return parent::execute($parameters);
return parent::execute($inputParameters);
}
}
4 changes: 2 additions & 2 deletions src/Propel/Runtime/Connection/StatementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ public function rowCount();
/**
* Returns a single column from the next row of a result set.
*
* @param int $columnNumber 0-indexed number of the column you wish to retrieve from the row.
* @param int $columnIndex 0-indexed number of the column you wish to retrieve from the row.
*
* @return string|null Returns a single column from the next row of a result set or FALSE if there are no more rows.
*/
public function fetchColumn($columnNumber = 0);
public function fetchColumn($columnIndex = 0);

/**
* Returns an array containing all of the result set rows.
Expand Down
4 changes: 3 additions & 1 deletion src/Propel/Runtime/Connection/StatementWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $fetchArgument = null, $
*/
public function fetchColumn($columnIndex = 0)
{
return $this->statement->fetchColumn($columnIndex);
$output = $this->statement->fetchColumn($columnIndex);

return $output === null ? null : (string)$output;
}

/**
Expand Down

0 comments on commit 8741fd3

Please sign in to comment.