Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix phpstan 0.10 #327

Open
wants to merge 1 commit into
base: v3.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
tests/mysql.local.neon
composer.lock
.idea
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ matrix:
env: COMPOSER_EXTRA_ARGS="--prefer-stable" COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"

install:
- if [ "$PHPSTAN" = "1" ]; then composer require --dev --no-update phpstan/phpstan-shim:^0.9; fi
- if [ "$PHPSTAN" = "1" ]; then composer require --dev --no-update phpstan/phpstan-shim:^0.10; fi
- travis_retry composer update --no-interaction --prefer-dist $COMPOSER_EXTRA_ARGS
- travis_retry composer create-project --no-interaction jakub-onderka/php-parallel-lint /tmp/php-parallel-lint
# - travis_retry composer create-project --no-interaction kdyby/code-checker /tmp/code-checker
Expand Down
5 changes: 1 addition & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ parameters:
- '#Parameter \#1 \$firstResult of method [^\s]+::setFirstResult\(\) expects int, (int\|)?null given#'
- '#Method Doctrine\\DBAL\\Driver\\Connection::query\(\) invoked with \d+ parameter, 0 required#'
- '#Kdyby\\Doctrine\\EmptyResultSet::__construct\(\) does not call parent constructor from Kdyby\\Doctrine\\ResultSet.#'
- '#Call to an undefined method Serializable::__sleep\(\).#'
- '#Call to an undefined method Serializable::__wakeup\(\).#'
- '#Access to an undefined property Nette\\Http\\SessionSection::\$entity#'
- '#Binary operation "&" between string and .+ results in an error#'
- '#Call to an undefined method Reflector::get#' # TODO refactoring class Panel
- '#Call to an undefined method object::getId\(\)#' # class SimpleParameterFormatter
- '#Method Kdyby\\Doctrine\\NativeQueryBuilder::(join|where|andWhere|orWhere)\(\) should return \$this but returns call_user_func_array#' # NativeQueryBuilder shortcuts
4 changes: 2 additions & 2 deletions src/Kdyby/Doctrine/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Connection extends Doctrine\DBAL\Connection
const POSTGRE_ERR_UNIQUE = 23505; // todo: verify, source: http://www.postgresql.org/docs/8.2/static/errcodes-appendix.html

/**
* @var Doctrine\ORM\EntityManager
* @var Doctrine\ORM\EntityManager|null
*/
private $entityManager;

Expand Down Expand Up @@ -201,7 +201,7 @@ public function query()
{
$args = func_get_args();
try {
return call_user_func_array('parent::query', $args);
return parent::query(...$args);

} catch (\Exception $e) {
throw $this->resolveException($e, func_get_arg(0));
Expand Down
12 changes: 8 additions & 4 deletions src/Kdyby/Doctrine/Dql/InlineParamsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class InlineParamsBuilder extends Kdyby\Doctrine\QueryBuilder
*/
public function join($join, $alias, $conditionType = NULL, $condition = NULL, $indexBy = NULL)
{
call_user_func_array([$this, 'innerJoin'], func_get_args());
$args = func_get_args();
$this->innerJoin(...$args);
return $this;
}

Expand Down Expand Up @@ -82,7 +83,8 @@ public function leftJoin($join, $alias, $conditionType = NULL, $condition = NULL
*/
public function where($predicates)
{
call_user_func_array('parent::where', Helpers::separateParameters($this, func_get_args()));
$args = Helpers::separateParameters($this, func_get_args());
parent::where(...$args);
return $this;
}

Expand All @@ -94,7 +96,8 @@ public function where($predicates)
*/
public function andWhere()
{
call_user_func_array('parent::andWhere', Helpers::separateParameters($this, func_get_args()));
$args = Helpers::separateParameters($this, func_get_args());
parent::andWhere(...$args);
return $this;
}

Expand All @@ -106,7 +109,8 @@ public function andWhere()
*/
public function orWhere()
{
call_user_func_array('parent::orWhere', Helpers::separateParameters($this, func_get_args()));
$args = Helpers::separateParameters($this, func_get_args());
parent::orWhere(...$args);
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Kdyby/Doctrine/DqlSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public function getRootAlias()
{
reset($this->builder->from);

return key($this->builder->from);
return (string) key($this->builder->from);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Kdyby/Doctrine/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class EntityManager extends Doctrine\ORM\EntityManager implements Persistence\Qu
private $nonLockingUniqueInserter;

/**
* @var \Kdyby\Doctrine\Diagnostics\EntityManagerUnitOfWorkSnapshotPanel
* @var \Kdyby\Doctrine\Diagnostics\EntityManagerUnitOfWorkSnapshotPanel|null
*/
private $panel;

Expand Down
11 changes: 8 additions & 3 deletions src/Kdyby/Doctrine/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ public static function getPropertyLine(\ReflectionProperty $property)

$context = 'file';
$contextBrackets = 0;
foreach (token_get_all(file_get_contents($class->getFileName())) as $token) {
$fileContent = file_get_contents($class->getFileName() ?: '');
if ($fileContent === FALSE) {
return NULL;
}

foreach (token_get_all($fileContent) as $token) {
if ($token === '{') {
$contextBrackets += 1;

Expand Down Expand Up @@ -141,7 +146,7 @@ public static function executeBatch(Connection $connection, $query, $callback =
$delimiter = $match[1];
$query = substr($query, strlen($match[0]));
} else {
preg_match('(' . preg_quote($delimiter) . '|[\'`"]|/\\*|-- |#|$)', $query, $match, PREG_OFFSET_CAPTURE, $offset); // should always match
preg_match('(' . preg_quote($delimiter) . '|[\'`"]|/\\*|-- |#|$)', $query, $match, PREG_OFFSET_CAPTURE, (int) $offset); // should always match
$found = $match[0][0];
$offset = $match[0][1] + strlen($found);

Expand Down Expand Up @@ -196,7 +201,7 @@ public static function loadFromFile(Connection $connection, $file, $callback = N
$delimiter = ';';
$sql = '';
while (!feof($handle)) {
$s = rtrim(fgets($handle));
$s = rtrim(fgets($handle) ?: '');
if (substr($s, 0, 10) === 'DELIMITER ') {
$delimiter = substr($s, 10);

Expand Down
12 changes: 9 additions & 3 deletions src/Kdyby/Doctrine/NativeQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ protected function addTableResultMapping($table, $alias, $joinedFrom = NULL)
*/
public function where($predicates)
{
return call_user_func_array('parent::where', Helpers::separateParameters($this, func_get_args()));
$args = Helpers::separateParameters($this, func_get_args());
parent::where(...$args);
return $this;
}


Expand All @@ -338,7 +340,9 @@ public function where($predicates)
*/
public function andWhere($where)
{
return call_user_func_array('parent::andWhere', Helpers::separateParameters($this, func_get_args()));
$args = Helpers::separateParameters($this, func_get_args());
parent::andWhere(...$args);
return $this;
}


Expand All @@ -349,7 +353,9 @@ public function andWhere($where)
*/
public function orWhere($where)
{
return call_user_func_array('parent::orWhere', Helpers::separateParameters($this, func_get_args()));
$args = Helpers::separateParameters($this, func_get_args());
parent::orWhere(...$args);
return $this;
}

}
2 changes: 1 addition & 1 deletion src/Kdyby/Doctrine/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private function autoJoin(&$key, $methodJoin = "innerJoin")
$rootAliases = $this->getRootAliases();
$alias = reset($rootAliases);

if (($i = strpos($key, '.')) === FALSE || !in_array(substr($key, 0, $i), $rootAliases)) {
if (($i = strpos($key, '.')) === FALSE || !in_array(substr($key, 0, $i ?: 0), $rootAliases)) {
// there is no root alias to join from, assume first root alias
$key = $alias . '.' . $key;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kdyby/Doctrine/QueryObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected function getQuery(Queryable $repository)

/**
* @param Queryable $repository
* @return \Doctrine\ORM\Query|\Doctrine\ORM\QueryBuilder
* @return \Doctrine\ORM\Query|\Doctrine\ORM\QueryBuilder|null
*/
protected function doCreateCountQuery(Queryable $repository)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Kdyby/Doctrine/RepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RepositoryFactory implements Doctrine\ORM\Repository\RepositoryFactory
/**
* The list of EntityRepository instances.
*
* @var Doctrine\ORM\EntityRepository[]
* @var Doctrine\ORM\EntityRepository[][]
*/
private $repositoryList = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Kdyby/Doctrine/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function __construct(ORM\AbstractQuery $query, QueryObject $queryObject =


/**
* @param bool $fetchJoinCollection
* @param bool|mixed $fetchJoinCollection
* @throws InvalidStateException
* @return ResultSet
*/
Expand Down
6 changes: 4 additions & 2 deletions src/Kdyby/Doctrine/Tools/NonLockingUniqueInserter.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ private function doInsert($entity)
$this->prepareInsert($meta, array_merge($fields, $associations, $discriminator))->execute();

// assign ID to entity
if ($idGen = $meta->idGenerator) {
/** @var \Doctrine\ORM\Id\AbstractIdGenerator|null $idGen */
$idGen = $meta->idGenerator;
if ($idGen) {
if ($idGen->isPostInsertGenerator()) {
$id = $idGen->generate($this->em, $entity);
$identifierFields = $meta->getIdentifierFieldNames();
Expand Down Expand Up @@ -184,7 +186,7 @@ private function prepareInsert(ClassMetadata $meta, array $data)
// bind values
$paramIndex = 1;
foreach ($data as $column) {
$statement->bindValue($paramIndex++, $column['value'], $column['type']);
$statement->bindValue((string) ($paramIndex++), $column['value'], $column['type']);
}

return $statement;
Expand Down
2 changes: 1 addition & 1 deletion tests/KdybyTests/Doctrine/Console/CommandTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ abstract class CommandTestCase extends Tester\TestCase
];

/**
* @var Nette\DI\Container
* @var Nette\DI\Container|null
*/
private $serviceLocator;

Expand Down
5 changes: 3 additions & 2 deletions tests/KdybyTests/Doctrine/proxies-sessions-test/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
exit(1);
}

\Tracy\Debugger::enable(FALSE, getenv('TEMP_DIR'));
$logDir = getenv('TEMP_DIR') ?: '';
\Tracy\Debugger::enable(FALSE, $logDir);

if ($sessionId = getenv('SESSION_ID')) {
$GLOBALS['_COOKIE'][session_name()] = $sessionId;
}

$config = new Nette\Configurator();
$config->setTempDirectory(getenv('TEMP_DIR'));
$config->setTempDirectory($logDir);
$config->addParameters([
'appDir' => __DIR__,
'wwwDir' => __DIR__,
Expand Down