Skip to content

Commit

Permalink
added php 7.3 support (#369)
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Staab <m.staab@complex-it.de>
  • Loading branch information
staabm and clxmstaab authored Jun 29, 2022
1 parent 7cd9666 commit 5533f24
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jobs:
fail-fast: false
matrix:
include:
- php-version: "7.3"
db-image: 'mysql:5.7'
reflector: "pdo-mysql"
mode: "recording"
- php-version: "7.4"
db-image: 'mysql:8.0'
reflector: "pdo-mysql"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "phpstan-extension",
"license": "MIT",
"require": {
"php": "^7.4 || ^8.0",
"php": "^7.3 || ^8.0",
"composer-runtime-api": "^2.0",
"composer/semver": "^3.2",
"phpstan/phpstan": "^1.5.6"
Expand Down
5 changes: 4 additions & 1 deletion src/Ast/ExpressionFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

final class ExpressionFinder
{
private NodeFinder $nodeFinder;
/**
* @var NodeFinder
*/
private $nodeFinder;

public function __construct()
{
Expand Down
5 changes: 4 additions & 1 deletion src/DbSchema/SchemaHasherMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ final class SchemaHasherMysql
*/
private $connection;

private ?string $hash = null;
/**
* @var string|null
*/
private $hash = null;

/**
* @param PDO|mysqli $connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

final class PdoStatementExecuteTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
{
private TypeSpecifier $typeSpecifier;
/**
* @var TypeSpecifier
*/
private $typeSpecifier;

public function getClass(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

final class PdoStatementSetFetchModeTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
{
private TypeSpecifier $typeSpecifier;
/**
* @var TypeSpecifier
*/
private $typeSpecifier;

public function getClass(): string
{
Expand Down
5 changes: 4 additions & 1 deletion src/PdoReflection/PdoStatementObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

class PdoStatementObjectType extends GenericObjectType
{
private Type $bothType;
/**
* @var Type
*/
private $bothType;

/**
* @param QueryReflector::FETCH_TYPE* $fetchType
Expand Down
21 changes: 15 additions & 6 deletions src/QueryReflection/BasePdoQueryReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,27 @@ abstract class BasePdoQueryReflector implements QueryReflector, RecordingReflect
/**
* @var array<string, PDOException|list<ColumnMeta>|null>
*/
protected array $cache = [];
protected $cache = [];

protected TypeMapper $typeMapper;
/**
* @var TypeMapper
*/
protected $typeMapper;

// @phpstan-ignore-next-line
protected ?PDOStatement $stmt = null;
/**
* @var PDOStatement|null
* @phpstan-ignore-next-line
*/
protected $stmt = null;
/**
* @var array<string, array<string, list<string>>>
*/
protected array $emulatedFlags = [];
protected $emulatedFlags = [];

protected PDO $pdo;
/**
* @var PDO
*/
protected $pdo;

public function __construct(PDO $pdo, TypeMapper $typeMapper)
{
Expand Down
12 changes: 9 additions & 3 deletions src/QueryReflection/MysqliQueryReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ final class MysqliQueryReflector implements QueryReflector, RecordingReflector
private const MAX_CACHE_SIZE = 50;

/** @var array<string, mysqli_sql_exception|list<object>|null> */
private array $cache = [];
private $cache = [];

private mysqli $db;
/**
* @var mysqli
*/
private $db;

private MysqliTypeMapper $typeMapper;
/**
* @var MysqliTypeMapper
*/
private $typeMapper;

public function __construct(mysqli $mysqli)
{
Expand Down
27 changes: 21 additions & 6 deletions src/QueryReflection/ReplayAndRecordingQueryReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,27 @@

final class ReplayAndRecordingQueryReflector implements QueryReflector, RecordingReflector
{
private ReplayQueryReflector $replayReflector;

private ?RecordingQueryReflector $recordingReflector = null;
private QueryReflector $queryReflector;
private ReflectionCache $reflectionCache;
private SchemaHasherMysql $schemaHasher;
/**
* @var ReplayQueryReflector
*/
private $replayReflector;

/**
* @var RecordingQueryReflector|null
*/
private $recordingReflector = null;
/**
* @var QueryReflector
*/
private $queryReflector;
/**
* @var ReflectionCache
*/
private $reflectionCache;
/**
* @var SchemaHasherMysql
*/
private $schemaHasher;

public function __construct(ReflectionCache $reflectionCache, QueryReflector $queryReflector, SchemaHasherMysql $schemaHasher)
{
Expand Down
9 changes: 6 additions & 3 deletions src/TypeMapping/MysqliTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
final class MysqliTypeMapper
{
/** @var array<int, string> */
private array $nativeTypes = [];
private $nativeTypes = [];

/** @var array<int, string> */
private array $nativeFlags = [];
private $nativeFlags = [];

private MysqlTypeMapper $typeMapper;
/**
* @var MysqlTypeMapper
*/
private $typeMapper;

public function __construct()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public static function getAdditionalConfigFiles(): array

public function testSyntaxErrorInQueryRule(): void
{
if (\PHP_VERSION_ID < 70400) {
self::markTestSkipped('Test requires PHP 7.4.');
}

if ('mysqli' === getenv('DBA_REFLECTOR')) {
$expectedErrors = [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public static function getAdditionalConfigFiles(): array

public function testSyntaxErrorInQueryRule(): void
{
if (\PHP_VERSION_ID < 70400) {
self::markTestSkipped('Test requires PHP 7.4.');
}

if ('pdo-mysql' !== getenv('DBA_REFLECTOR')) {
$this->markTestSkipped('Only works with PdoMysqlQueryReflector');
}
Expand All @@ -49,6 +53,10 @@ public function testSyntaxErrorInQueryRule(): void

public function testSyntaxErrorInPgsqlQueryRule(): void
{
if (\PHP_VERSION_ID < 70400) {
self::markTestSkipped('Test requires PHP 7.4.');
}

if ('pdo-pgsql' !== getenv('DBA_REFLECTOR')) {
$this->markTestSkipped('Only works with PdoPgsqlQueryReflector');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public static function getAdditionalConfigFiles(): array

public function testSyntaxErrorInQueryRule(): void
{
if (\PHP_VERSION_ID < 70400) {
self::markTestSkipped('Test requires PHP 7.4.');
}

if ('pdo-mysql' !== getenv('DBA_REFLECTOR')) {
$this->markTestSkipped('Only works with PdoMysqlQueryReflector');
}
Expand Down
4 changes: 4 additions & 0 deletions tests/rules/SyntaxErrorInQueryMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public static function getAdditionalConfigFiles(): array

public function testSyntaxErrorInQueryRule(): void
{
if (\PHP_VERSION_ID < 70400) {
self::markTestSkipped('Test requires PHP 7.4.');
}

if ('mysqli' === getenv('DBA_REFLECTOR')) {
$expected = [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public static function getAdditionalConfigFiles(): array

public function testSyntaxErrorInQueryRule(): void
{
if (\PHP_VERSION_ID < 70400) {
self::markTestSkipped('Test requires PHP 7.4.');
}

if ('pdo-mysql' !== getenv('DBA_REFLECTOR')) {
$this->markTestSkipped('Only works with PdoMysqlQueryReflector');
}
Expand Down

0 comments on commit 5533f24

Please sign in to comment.