Skip to content

Commit

Permalink
Added PHPStan, apply changes for level 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Majkl578 committed Feb 17, 2018
1 parent 63efa53 commit cc7b303
Show file tree
Hide file tree
Showing 27 changed files with 89 additions and 43 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ jobs:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover clover.xml

- stage: Code Quality
env: DB=none STATIC_ANALYSIS
install: travis_retry composer update --prefer-dist
before_script:
script: vendor/bin/phpstan analyse -c phpstan.neon -l 3 lib/

- stage: Pull request coding standard
if: type = pull_request
php: 7.1
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"require-dev": {
"doctrine/coding-standard": "~2.0.0",
"phpstan/phpstan-shim": "^0.9.2",
"phpunit/phpunit": "^6.3",
"phpunit/phpunit-mock-objects": "!=3.2.4,!=3.2.5",
"symfony/console": "^2.0.5||^3.0",
Expand Down
17 changes: 9 additions & 8 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Exception;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Cache\ResultCacheStatement;
use Doctrine\DBAL\Cache\QueryCacheProfile;
Expand Down Expand Up @@ -101,7 +102,7 @@ class Connection implements DriverConnection
/**
* The wrapped driver connection.
*
* @var \Doctrine\DBAL\Driver\Connection
* @var \Doctrine\DBAL\Driver\Connection|null
*/
protected $_conn;

Expand Down Expand Up @@ -402,7 +403,7 @@ private function detectDatabasePlatform()
{
$version = $this->getDatabasePlatformVersion();

if (null !== $version) {
if ($version !== null && $this->_driver instanceof VersionAwarePlatformDriver) {
$this->platform = $this->_driver->createDatabasePlatformForVersion($version);
} else {
$this->platform = $this->_driver->getDatabasePlatform();
Expand All @@ -419,7 +420,7 @@ private function detectDatabasePlatform()
* or the underlying driver connection cannot determine the platform
* version without having to query it (performance reasons).
*
* @return string|null
* @return string|bool|null
*
* @throws Exception
*/
Expand Down Expand Up @@ -478,7 +479,7 @@ private function getDatabasePlatformVersion()
/**
* Returns the database server version if the underlying driver supports it.
*
* @return string|null
* @return string|bool|null
*/
private function getServerVersion()
{
Expand Down Expand Up @@ -868,7 +869,7 @@ public function fetchAll($sql, array $params = [], $types = [])
*
* @param string $statement The SQL statement to prepare.
*
* @return \Doctrine\DBAL\Statement The prepared statement.
* @return DriverStatement The prepared statement.
*
* @throws \Doctrine\DBAL\DBALException
*/
Expand Down Expand Up @@ -896,7 +897,7 @@ public function prepare($statement)
* @param array $types The types the previous parameters are in.
* @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp The query cache profile, optional.
*
* @return \Doctrine\DBAL\Driver\Statement The executed statement.
* @return \Doctrine\DBAL\Driver\ResultStatement The executed statement.
*
* @throws \Doctrine\DBAL\DBALException
*/
Expand Down Expand Up @@ -1132,7 +1133,7 @@ public function getTransactionNestingLevel()
/**
* Fetches the SQLSTATE associated with the last database operation.
*
* @return int The last error code.
* @return string|bool|null The last error code.
*/
public function errorCode()
{
Expand Down Expand Up @@ -1163,7 +1164,7 @@ public function errorInfo()
*
* @param string|null $seqName Name of the sequence object from which the ID should be returned.
*
* @return string A string representation of the last inserted ID.
* @return string|int|bool A string representation of the last inserted ID.
*/
public function lastInsertId($seqName = null)
{
Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Configuration;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Event\ConnectionEventArgs;
Expand Down Expand Up @@ -85,7 +86,7 @@ class MasterSlaveConnection extends Connection
/**
* Master and slave connection (one of the randomly picked slaves).
*
* @var \Doctrine\DBAL\Driver\Connection[]
* @var DriverConnection[]|null[]
*/
protected $connections = ['master' => null, 'slave' => null];

Expand Down Expand Up @@ -196,7 +197,7 @@ public function connect($connectionName = null)
*
* @param string $connectionName
*
* @return \Doctrine\DBAL\Driver
* @return DriverConnection
*/
protected function connectTo($connectionName)
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Driver/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface Connection
*
* @param string $prepareString
*
* @return \Doctrine\DBAL\Driver\Statement
* @return Statement
*/
public function prepare($prepareString);

Expand Down Expand Up @@ -71,7 +71,7 @@ public function exec($statement);
*
* @param string|null $name
*
* @return string
* @return string|int|bool
*/
public function lastInsertId($name = null);

Expand Down Expand Up @@ -99,7 +99,7 @@ public function rollBack();
/**
* Returns the error code associated with the last operation on the database handle.
*
* @return string|null The error code, or null if no operation has been run on the database handle.
* @return string|bool|null The error code, or null if no operation has been run on the database handle.
*/
public function errorCode();

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DB2Statement implements \IteratorAggregate, Statement
private $defaultFetchClass = '\stdClass';

/**
* @var string Constructor arguments for the default class to instantiate when fetching class instances.
* @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances.
*/
private $defaultFetchClassCtorArgs = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
private $defaultFetchClass = '\stdClass';

/**
* @var string Constructor arguments for the default class to instantiate when fetching class instances.
* @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances.
*/
private $defaultFetchClassCtorArgs = [];

Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* The SQLSRV statement resource.
*
* @var resource
* @var resource|null
*/
private $stmt;

Expand Down Expand Up @@ -89,7 +89,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* The constructor arguments for the default class to instantiate when fetching class instances.
*
* @var string
* @var mixed[]
*/
private $defaultFetchClassCtorArgs = [];

Expand Down Expand Up @@ -305,7 +305,7 @@ public function getIterator()
*
* @throws SQLSrvException
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface ServerInfoAwareConnection
/**
* Returns the version number of the database server connected to.
*
* @return string
* @return string|bool
*/
public function getServerVersion();

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l
*
* @see Doctrine_Adapter_Interface::errorCode()
*
* @return string The error code string.
* @return string|int|bool The error code string.
*/
public function errorCode();

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2716,7 +2716,7 @@ public function getCurrentTimestampSQL()
*
* @param int $level
*
* @return string
* @return string|int
*
* @throws \InvalidArgumentException
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ protected function _getCreateTableSQL($table, array $columns, array $options = [

foreach ($columns as $name => $column) {
if (isset($column['sequence'])) {
$sql[] = $this->getCreateSequenceSQL($column['sequence'], 1);
$sql[] = $this->getCreateSequenceSQL($column['sequence']);
}

if (isset($column['autoincrement']) && $column['autoincrement'] ||
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ protected function doModifyLimitQuery($query, $limit, $offset = null)
* Remove ORDER BY clauses in subqueries - they're not supported by SQL Server.
* Caveat: will leave ORDER BY in TOP N subqueries.
*
* @param $query
* @param string $query
* @return string
*/
private function scrubInnerOrderBy($query)
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ public function getAlterTableSQL(TableDiff $diff)
/**
* @param \Doctrine\DBAL\Schema\TableDiff $diff
*
* @return array|bool
* @return string[]|false
*/
private function getSimpleAlterTableSQL(TableDiff $diff)
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public function dropView($name)
*
* @param string $database The name of the database to create.
*
* @return void
* @return void|bool
*/
public function createDatabase($database)
{
Expand Down Expand Up @@ -917,7 +917,7 @@ protected function _getPortableTablesList($tables)
/**
* @param array $table
*
* @return array
* @return mixed[]|string
*/
protected function _getPortableTableDefinition($table)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function diffSequence(Sequence $sequence1, Sequence $sequence2)
* @param \Doctrine\DBAL\Schema\Table $table1
* @param \Doctrine\DBAL\Schema\Table $table2
*
* @return bool|\Doctrine\DBAL\Schema\TableDiff
* @return \Doctrine\DBAL\Schema\TableDiff|false
*/
public function diffTable(Table $table1, Table $table2)
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public function getOptions()
* Returns the referential action for UPDATE operations
* on the referenced table the foreign key constraint is associated with.
*
* @return string|null
* @return string|false|null
*/
public function onUpdate()
{
Expand All @@ -336,7 +336,7 @@ public function onUpdate()
* Returns the referential action for DELETE operations
* on the referenced table the foreign key constraint is associated with.
*
* @return string|null
* @return string|false|null
*/
public function onDelete()
{
Expand All @@ -349,7 +349,7 @@ public function onDelete()
*
* @param string $event Name of the database operation/event to return the referential action for.
*
* @return string|null
* @return string|false|null
*/
private function onEvent($event)
{
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/DBAL/Schema/OracleSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Types\Type;

/**
Expand Down Expand Up @@ -106,6 +107,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
$tableIndex = \array_change_key_case($tableIndex, CASE_LOWER);

$keyName = strtolower($tableIndex['name']);
$buffer = [];

if (strtolower($tableIndex['is_primary']) == "p") {
$keyName = 'primary';
Expand Down Expand Up @@ -347,6 +349,8 @@ public function createDatabase($database = null)
*/
public function dropAutoincrement($table)
{
assert($this->_platform instanceof OraclePlatform);

$sql = $this->_platform->getDropAutoincrementSql($table);
foreach ($sql as $query) {
$this->_conn->executeUpdate($query);
Expand Down
10 changes: 8 additions & 2 deletions lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Doctrine\DBAL\Schema;

use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Types\Type;

/**
Expand Down Expand Up @@ -117,6 +118,8 @@ public function dropDatabase($database)
throw $exception;
}

assert($this->_platform instanceof PostgreSqlPlatform);

$this->_execSql(
[
$this->_platform->getDisallowDatabaseConnectionsSQL($database),
Expand All @@ -133,8 +136,11 @@ public function dropDatabase($database)
*/
protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
{
$onUpdate = null;
$onDelete = null;
$onUpdate = null;
$onDelete = null;
$localColumns = null;
$foreignColumns = null;
$foreignTable = null;

if (preg_match('(ON UPDATE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) {
$onUpdate = $match[1];
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace Doctrine\DBAL\Schema;

use Doctrine\DBAL\Platforms\SQLAnywherePlatform;
use Doctrine\DBAL\Types\Type;

/**
Expand Down Expand Up @@ -67,6 +68,7 @@ public function dropDatabase($database)
*/
public function startDatabase($database)
{
assert($this->_platform instanceof SQLAnywherePlatform);
$this->_execSql($this->_platform->getStartDatabaseSQL($database));
}

Expand All @@ -77,6 +79,7 @@ public function startDatabase($database)
*/
public function stopDatabase($database)
{
assert($this->_platform instanceof SQLAnywherePlatform);
$this->_execSql($this->_platform->getStopDatabaseSQL($database));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Schema extends AbstractAsset
protected $_sequences = [];

/**
* @var \Doctrine\DBAL\Schema\SchemaConfig
* @var \Doctrine\DBAL\Schema\SchemaConfig|bool
*/
protected $_schemaConfig = false;

Expand Down
Loading

0 comments on commit cc7b303

Please sign in to comment.