Skip to content

Commit

Permalink
PHP8 CodeStyle and tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bezpiatovs committed Oct 30, 2020
1 parent bdb6e66 commit dc89c01
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 51 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Propel/Runtime/Adapter/Pdo/PgsqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function quoteIdentifierTable($table)
* @param \Propel\Runtime\Connection\ConnectionInterface $con propel connection
* @param \Propel\Runtime\ActiveQuery\Criteria|string $query query the criteria or the query string
*
* @return \PDOStatement A PDO statement executed using the connection, ready to be fetched
* @return \Propel\Runtime\Connection\StatementInterface A PDO statement executed using the connection, ready to be fetched
*/
public function doExplainPlan(ConnectionInterface $con, $query)
{
Expand Down
6 changes: 4 additions & 2 deletions src/Propel/Runtime/Collection/CollectionIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,22 +230,24 @@ public function append($value)

/**
* @param int $sort_flags
*
*
* @return void
*/
public function asort($sort_flags = SORT_REGULAR)
{
/* @phpstan-ignore-next-line */
parent::asort($sort_flags);
$this->refreshPositions();
}

/**
* @param int $sort_flags
*
*
* @return void
*/
public function ksort($sort_flags = SORT_REGULAR)
{
/* @phpstan-ignore-next-line */
parent::ksort($sort_flags);
$this->refreshPositions();
}
Expand Down
9 changes: 4 additions & 5 deletions src/Propel/Runtime/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function inTransaction();
/**
* Retrieve a database connection attribute.
*
* @param string|int $attribute The name of the attribute to retrieve,
* @param int $attribute The name of the attribute to retrieve,
* e.g. PDO::ATTR_AUTOCOMMIT
*
* @return mixed A successful call returns the value of the requested attribute.
Expand All @@ -88,7 +88,7 @@ public function getAttribute(int $attribute);
/**
* Set an attribute.
*
* @param string|int $attribute
* @param int|string $attribute
* @param mixed $value
*
* @return bool TRUE on success or FALSE on failure.
Expand Down Expand Up @@ -166,12 +166,11 @@ public function exec($statement);
*
* @param string $statement This must be a valid SQL statement for the target
* database server.
* @param array|null $driver_options
* @param array $driver_options
*
* @throws \Propel\Runtime\Connection\Exception\ConnectionException depending on error handling.
*
* @return \PDOStatement|bool A Statement object if the database server
* successfully prepares, FALSE otherwise.
* @return \Propel\Runtime\Connection\StatementInterface|\PDOStatement|bool
*/
public function prepare(string $statement, array $driver_options = []);

Expand Down
10 changes: 5 additions & 5 deletions src/Propel/Runtime/Connection/ConnectionWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function commit()
$return = true;
$opcount = $this->nestedTransactionCount;

if ($opcount > 0) {
if ($opcount > 0 and $this->inTransaction()) {
if ($opcount === 1) {
if ($this->isUncommitable) {
throw new RollbackException('Cannot commit because a nested transaction was rolled back');
Expand Down Expand Up @@ -260,7 +260,7 @@ public function rollBack()
$return = true;
$opcount = $this->nestedTransactionCount;

if ($opcount > 0) {
if ($opcount > 0 and $this->inTransaction()) {
if ($opcount === 1) {
$return = $this->connection->rollBack();
if ($this->useDebug) {
Expand Down Expand Up @@ -335,7 +335,7 @@ public function getAttribute(int $attribute)
/**
* Set an attribute.
*
* @param string|int $attribute The attribute name, or the constant name containing the attribute name (e.g. 'PDO::ATTR_CASE')
* @param int|string $attribute The attribute name, or the constant name containing the attribute name (e.g. 'PDO::ATTR_CASE')
* @param mixed $value
*
* @throws \Propel\Runtime\Exception\InvalidArgumentException
Expand Down Expand Up @@ -380,10 +380,10 @@ public function setAttribute($attribute, $value)
* - Add query caching support if the PropelPDO::PROPEL_ATTR_CACHE_PREPARES was set to true.
*
* @param string $statement This must be a valid SQL statement for the target database server.
* @param array|null $driver_options One $array or more key => value pairs to set attribute values
* @param array $driver_options One $array or more key => value pairs to set attribute values
* for the PDOStatement object that this method returns.
*
* @return \PDOStatement
* @return \Propel\Runtime\Connection\StatementInterface|bool
*/
public function prepare(string $statement, array $driver_options = [])
{
Expand Down
11 changes: 10 additions & 1 deletion src/Propel/Runtime/Connection/PdoConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function lastInsertId($name = null)
* @param string $statement
* @param array $driver_options
*
* @return bool|\PDOStatement
* @return \PDOStatement|bool
*/
public function prepare(string $statement, array $driver_options = [])
{
Expand All @@ -196,16 +196,25 @@ public function quote($string, $parameter_type = \PDO::PARAM_STR)
return $this->pdo->quote($string, $parameter_type);
}

/**
* @return bool
*/
public function beginTransaction()
{
return $this->pdo->beginTransaction();
}

/**
* @return bool
*/
public function commit()
{
return $this->pdo->commit();
}

/**
* @return bool
*/
public function rollBack()
{
return $this->pdo->rollBack();
Expand Down
6 changes: 4 additions & 2 deletions src/Propel/Runtime/Connection/StatementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

namespace Propel\Runtime\Connection;

use PDO;

/**
* Interface for Propel StatementWrapper object.
* Interface for Propel Statement object.
* Based on the PDOStatement interface.
* @see http://php.net/manual/en/book.pdo.php
*
Expand Down Expand Up @@ -370,7 +372,7 @@ public function closeCursor();

/**
* Dump an SQL prepared command
* @return bool No value is returned.
* @return void No value is returned.
*/
public function debugDumpParams();
}
23 changes: 13 additions & 10 deletions src/Propel/Runtime/Connection/StatementWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public function __construct($sql, ConnectionWrapper $connection)
*/
public function prepare($options)
{
$this->statement = $this->connection->getWrappedConnection()->prepare($this->sql, $options);
/** @var \PDOStatement $statement */
$statement = $this->connection->getWrappedConnection()->prepare($this->sql, $options);
$this->statement = $statement;

return $this;
}
Expand All @@ -86,10 +88,11 @@ public function prepare($options)
*/
public function query()
{
$wrapped_connection = $this->connection->getWrappedConnection();
$this->statement = $wrapped_connection->query($this->sql);
/** @var \PDOStatement $statement */
$statement = $this->connection->getWrappedConnection()->query($this->sql);
$this->statement = $statement;

return $wrapped_connection->getDataFetcher($this);
return $this->connection->getWrappedConnection()->getDataFetcher($this);
}

/**
Expand Down Expand Up @@ -301,7 +304,7 @@ public function rowCount()
*
* @return \Traversable
*/
public function getIterator(): \Iterator
public function getIterator(): \Traversable
{
return $this->statement;
}
Expand Down Expand Up @@ -415,18 +418,18 @@ public function nextRowset()
/**
* {@inheritDoc}
*/
public function debugDumpParams()
public function debugDumpParams(): void
{
return $this->statement->debugDumpParams();
$this->statement->debugDumpParams();
}

/**
* @param $method
* @param $args
* @param string $method
* @param mixed $args
*
* @return mixed
*/
public function __call($method, $args)
public function __call(string $method, $args)
{
return call_user_func_array([$this->statement, $method], $args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
namespace Propel\Tests\Common\Config;

use Propel\Common\Config\ConfigurationManager;
use Propel\Common\Config\Exception\InvalidConfigurationException;
use Propel\Common\Config\Exception\InvalidArgumentException;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;

class ConfigurationManagerTest extends ConfigTestCase
{
Expand Down
14 changes: 7 additions & 7 deletions tests/Propel/Tests/Generator/Model/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ public function testEnumType()
$this->assertSame('int', $column->getPhpType());
$this->assertTrue($column->isPhpPrimitiveType());
$this->assertTrue($column->isEnumType());
$this->assertStringContainsString('FOO', $column->getValueSet());
$this->assertStringContainsString('BAR', $column->getValueSet());
$this->assertContains('FOO', $column->getValueSet());
$this->assertContains('BAR', $column->getValueSet());
}

/**
Expand All @@ -521,8 +521,8 @@ public function testSetType()
$this->assertSame('int', $column->getPhpType());
$this->assertTrue($column->isPhpPrimitiveType());
$this->assertTrue($column->isSetType());
$this->assertStringContainsString('FOO', $column->getValueSet());
$this->assertStringContainsString('BAR', $column->getValueSet());
$this->assertContains('FOO', $column->getValueSet());
$this->assertContains('BAR', $column->getValueSet());
}

/**
Expand All @@ -533,9 +533,9 @@ public function testSetStringValueSet()
$column = new Column();
$column->setValueSet(' FOO , BAR , BAZ');

$this->assertStringContainsString('FOO', $column->getValueSet());
$this->assertStringContainsString('BAR', $column->getValueSet());
$this->assertStringContainsString('BAZ', $column->getValueSet());
$this->assertContains('FOO', $column->getValueSet());
$this->assertContains('BAR', $column->getValueSet());
$this->assertContains('BAZ', $column->getValueSet());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Propel/Tests/Generator/Model/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ public function testAddForeignKey()
$this->assertInstanceOf('Propel\Generator\Model\ForeignKey', $table->addForeignKey($fk));
$this->assertCount(1, $table->getForeignKeys());
$this->assertTrue($table->hasForeignKeys());
$this->assertStringContainsString('authors', $table->getForeignTableNames());
$this->assertContains('authors', $table->getForeignTableNames());
}

/**
Expand All @@ -826,7 +826,7 @@ public function testAddArrayForeignKey()
$this->assertCount(1, $table->getForeignKeys());
$this->assertTrue($table->hasForeignKeys());

$this->assertStringContainsString('authors', $table->getForeignTableNames());
$this->assertContains('authors', $table->getForeignTableNames());
}

/**
Expand Down Expand Up @@ -882,7 +882,7 @@ public function testGetColumnForeignKeys()
$table->addForeignKey($fk2);

$this->assertCount(1, $table->getColumnForeignKeys('author_id'));
$this->assertStringContainsString($fk1, $table->getColumnForeignKeys('author_id'));
$this->assertContains($fk1, $table->getColumnForeignKeys('author_id'));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Propel/Tests/Generator/Util/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function testValidateReturnsFalseWhenTwoTablesHaveSamePhpName()
$validator = new SchemaValidator($schema);

$this->assertFalse($validator->validate());
$this->assertStringContainsString('Table "bar" declares a phpName already used in another table', $validator->getErrors());
$this->assertContains('Table "bar" declares a phpName already used in another table', $validator->getErrors());
}

/**
Expand Down Expand Up @@ -147,7 +147,7 @@ public function testValidateReturnsFalseWhenTableHasNoPk()
$validator = new SchemaValidator($schema);

$this->assertFalse($validator->validate());
$this->assertStringContainsString('Table "foo" does not have a primary key defined. Propel requires all tables to have a primary key.', $validator->getErrors());
$this->assertContains('Table "foo" does not have a primary key defined. Propel requires all tables to have a primary key.', $validator->getErrors());
}

/**
Expand All @@ -173,7 +173,7 @@ public function testValidateReturnsFalseWhenTableHasAReservedName()
$validator = new SchemaValidator($schema);

$this->assertFalse($validator->validate());
$this->assertStringContainsString('Table "TABLE_NAME" uses a reserved keyword as name', $validator->getErrors());
$this->assertContains('Table "TABLE_NAME" uses a reserved keyword as name', $validator->getErrors());
}

/**
Expand All @@ -194,6 +194,6 @@ public function testValidateReturnsFalseWhenTwoColumnsHaveSamePhpName()
$validator = new SchemaValidator($schema);

$this->assertFalse($validator->validate());
$this->assertStringContainsString('Column "bar" declares a phpName already used in table "foo_table"', $validator->getErrors());
$this->assertContains('Column "bar" declares a phpName already used in table "foo_table"', $validator->getErrors());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function testGetReadConnectionBuildsConnectionBasedOnARandomReadConfigura
$con = $manager->getReadConnection(new SqliteAdapter());
$pdo = $con->getWrappedConnection();
$expected = [PDO::CASE_LOWER, PDO::CASE_UPPER];
$this->assertStringContainsString($pdo->getAttribute(PDO::ATTR_CASE), $expected);
$this->assertContains($pdo->getAttribute(PDO::ATTR_CASE), $expected);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function testGetReadConnectionBuildsConnectionBasedOnARandomReadConfigura
$con = $manager->getReadConnection(new SqliteAdapter());
$pdo = $con->getWrappedConnection();
$expected = [PDO::CASE_LOWER, PDO::CASE_UPPER];
$this->assertStringContainsString($pdo->getAttribute(PDO::ATTR_CASE), $expected);
$this->assertContains($pdo->getAttribute(PDO::ATTR_CASE), $expected);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Propel/Tests/Runtime/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testTypeHintClass()
$method = $reflection->getMethod('setDummyObject');
$param = $method->getParameters()[0];

$this->assertEquals(DummyObjectClass::class, $param->getClass()->name);
$this->assertEquals(DummyObjectClass::class, $param->getType()->getName());
$this->assertTrue($param->allowsNull());
}

Expand All @@ -43,7 +43,7 @@ public function testTypeHintArray()
$method = $reflection->getMethod('setSomeArray');
$param = $method->getParameters()[0];

$this->assertTrue($param->isArray());
$this->assertTrue($param->getType() && $param->getType()->getName() === 'array');
$this->assertTrue($param->allowsNull());
}

Expand All @@ -56,7 +56,7 @@ public function testInterface()
$method = $reflection->getMethod('setTypeObject');
$param = $method->getParameters()[0];

$this->assertEquals(TypeObjectInterface::class, $param->getClass()->name);
$this->assertEquals(TypeObjectInterface::class, $param->getType()->getName());
$this->assertTrue($param->allowsNull());
}

Expand Down

0 comments on commit dc89c01

Please sign in to comment.