Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/QueryReflection/QuerySimulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public static function simulateParamValueType(Type $paramType, bool $preparedPar
return null;
}

// TODO the dateformat should be taken from bound-parameter-types, see https://github.com/staabm/phpstan-dba/pull/342
if ($paramType instanceof ObjectType && $paramType->isInstanceOf(\DateTimeInterface::class)->yes()) {
return date(self::DATE_FORMAT, 0);
}

$stringType = new StringType();
$isStringableObjectType = $paramType instanceof ObjectType
&& $paramType->isInstanceOf(Stringable::class)->yes();
Expand Down
7 changes: 7 additions & 0 deletions tests/default/config/.phpstan-dba-mysqli.cache

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

7 changes: 7 additions & 0 deletions tests/default/config/.phpstan-dba-pdo.cache

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

7 changes: 7 additions & 0 deletions tests/default/config/.phpunit-phpstan-dba-mysqli.cache

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

7 changes: 7 additions & 0 deletions tests/default/config/.phpunit-phpstan-dba-pdo.cache

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

10 changes: 10 additions & 0 deletions tests/default/data/doctrine-dbal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Types;
use function PHPStan\Testing\assertType;
use staabm\PHPStanDba\Tests\Fixture\StringableObject;

Expand Down Expand Up @@ -218,4 +219,13 @@ public function dateParameter(Connection $conn)
$fetchResult = $conn->fetchOne($query, [date('Y-m-d', strtotime('-3hour'))]);
assertType('int|false', $fetchResult);
}

public function customTypeParameters(Connection $conn)
{
$result = $conn->executeQuery(
'SELECT count(*) AS c FROM typemix WHERE c_datetime=:last_dt',
['dt' => new \DateTime()], ['dt' => Types::DATETIME_MUTABLE]
);
assertType('Doctrine\DBAL\Result', $result);
}
}