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

Fix more type errors #708

Merged
merged 14 commits into from
Nov 7, 2024
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
974 changes: 23 additions & 951 deletions .phpstan-dba-mysqli.cache

Large diffs are not rendered by default.

974 changes: 23 additions & 951 deletions .phpstan-dba-pdo-mysql.cache

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions src/Analyzer/QueryPlanResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ final class QueryPlanResult
/**
* @var array<string, self::*>
*/
private $result = [];
private array $result = [];

/**
* @var string
*/
private $simulatedQuery;
private string $simulatedQuery;

public function __construct(string $simulatedQuery)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Ast/ExpressionFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

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

public function __construct()
{
Expand Down
7 changes: 2 additions & 5 deletions src/Ast/PreviousConnectingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ final class PreviousConnectingVisitor extends NodeVisitorAbstract
/**
* @var list<Node>
*/
private $stack = [];
private array $stack = [];

/**
* @var ?Node
*/
private $previous;
private ?Node $previous;

public function beforeTraverse(array $nodes)
{
Expand Down
5 changes: 1 addition & 4 deletions src/DbSchema/LazySchemaHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ class LazySchemaHasher implements SchemaHasher
*/
private $schemaHasherFactory;

/**
* @var SchemaHasher|null
*/
private $schemaHasher;
private ?SchemaHasher $schemaHasher = null;

/**
* @param callable():SchemaHasher $schemaHasherFactory
Expand Down
5 changes: 1 addition & 4 deletions src/DbSchema/SchemaHasherMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ final class SchemaHasherMysql implements SchemaHasher
*/
private $connection;

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

/**
* @param PDO|mysqli $connection
Expand Down
2 changes: 1 addition & 1 deletion src/DoctrineReflection/DoctrineResultObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

final class DoctrineResultObjectType extends ObjectType
{
private ?Type $rowType;
private ?Type $rowType = null;

public static function newWithRowType(Type $rowType): self
{
Expand Down
5 changes: 1 addition & 4 deletions src/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
*/
final class Error
{
/**
* @var string
*/
private $message;
private string $message;

/**
* @var ErrorCodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@

final class MysqliEscapeStringDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension, DynamicFunctionReturnTypeExtension
{
/**
* @var PhpVersion
*/
private $phpVersion;
private PhpVersion $phpVersion;

public function __construct(PhpVersion $phpVersion)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Extensions/MysqliQueryDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@

final class MysqliQueryDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension, DynamicFunctionReturnTypeExtension
{
/**
* @var PhpVersion
*/
private $phpVersion;
private PhpVersion $phpVersion;

public function __construct(PhpVersion $phpVersion)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Extensions/PdoPrepareDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@

final class PdoPrepareDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
/**
* @var PhpVersion
*/
private $phpVersion;
private PhpVersion $phpVersion;

public function __construct(PhpVersion $phpVersion)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Extensions/PdoQueryDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@

final class PdoQueryDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
/**
* @var PhpVersion
*/
private $phpVersion;
private PhpVersion $phpVersion;

public function __construct(PhpVersion $phpVersion)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Extensions/PdoQuoteDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@

final class PdoQuoteDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
/**
* @var PhpVersion
*/
private $phpVersion;
private PhpVersion $phpVersion;

public function __construct(PhpVersion $phpVersion)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@

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

public function getClass(): string
{
Expand Down
12 changes: 3 additions & 9 deletions src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,9 @@

final class PdoStatementFetchDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
/**
* @var PhpVersion
*/
private $phpVersion;

/**
* @var ReflectionProvider
*/
private $reflectionProvider;
private PhpVersion $phpVersion;

private ReflectionProvider $reflectionProvider;

public function __construct(PhpVersion $phpVersion, ReflectionProvider $reflectionProvider)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

final class PdoStatementFetchObjectDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
/**
* @var ReflectionProvider
*/
private $reflectionProvider;
private ReflectionProvider $reflectionProvider;

public function __construct(ReflectionProvider $reflectionProvider)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

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

public function getClass(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/MysqliReflection/MysqliResultObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class MysqliResultObjectType extends ObjectType
{
private ?Type $rowType;
private ?Type $rowType = null;

public function setRowType(Type $rowType): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/PdoReflection/PdoStatementObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PdoStatementObjectType extends ObjectType
/**
* @var null|QueryReflector::FETCH_TYPE*
*/
private ?int $fetchType;
private ?int $fetchType = null;

public function getRowType(): Type
{
Expand Down
2 changes: 1 addition & 1 deletion src/PdoReflection/PdoStatementReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function getColumnRowType(Type $statementType, int $columnIndex): ?Type
/**
* @param class-string $className
*/
public function getClassRowType(Type $statementType, string $className): ?Type
public function getClassRowType(Type $statementType, string $className): Type
{
return new ObjectType($className);
}
Expand Down
9 changes: 3 additions & 6 deletions src/QueryReflection/BasePdoQueryReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ abstract class BasePdoQueryReflector implements QueryReflector, RecordingReflect
/**
* @var array<string, PDOException|list<ColumnMeta>|null>
*/
protected $cache = [];
protected array $cache = [];

/**
* @var TypeMapper
Expand All @@ -71,12 +71,9 @@ abstract class BasePdoQueryReflector implements QueryReflector, RecordingReflect
/**
* @var array<string, array<string, list<string>>>
*/
protected $emulatedFlags = [];
protected array $emulatedFlags = [];

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

public function __construct(PDO $pdo)
{
Expand Down
2 changes: 1 addition & 1 deletion src/QueryReflection/ChainedReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class ChainedReflector implements QueryReflector
/**
* @var QueryReflector[]
*/
private $reflectors;
private array $reflectors;

/**
* @param QueryReflector ...$reflectors
Expand Down
10 changes: 2 additions & 8 deletions src/QueryReflection/LazyQueryReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@ final class LazyQueryReflector implements QueryReflector, RecordingReflector
*/
private $reflectorFactory;

/**
* @var QueryReflector|null
*/
private $reflector;
private ?QueryReflector $reflector = null;

/**
* @var DbaApi|null
*/
private $dbaApi;
private ?DbaApi $dbaApi = null;

/**
* @param callable():QueryReflector $reflectorFactory
Expand Down
12 changes: 3 additions & 9 deletions src/QueryReflection/MysqliQueryReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,11 @@ final class MysqliQueryReflector implements QueryReflector, RecordingReflector
/**
* @var array<string, mysqli_sql_exception|list<object>|null>
*/
private $cache = [];
private array $cache = [];

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

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

public function __construct(mysqli $mysqli)
{
Expand Down
17 changes: 4 additions & 13 deletions src/QueryReflection/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,13 @@ final class Parameter
/**
* @var non-empty-string|null
*/
public $name;
public ?string $name = null;

/**
* @var Type
*/
public $type;
public Type $type;

/**
* @var ?string
*/
public $simulatedValue;
public ?string $simulatedValue = null;

/**
* @var bool
*/
public $isOptional;
public bool $isOptional;

/**
* @param non-empty-string|null $name
Expand Down
17 changes: 4 additions & 13 deletions src/QueryReflection/QueryReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,11 @@ final class QueryReflection

private const REGEX_NAMED_PLACEHOLDER = '{(["\'])((?:(?!\1)(?s:.))*\1)|(' . self::NAMED_PATTERN . ')}';

/**
* @var QueryReflector|null
*/
private static $reflector;
private static ?QueryReflector $reflector = null;

/**
* @var RuntimeConfiguration|null
*/
private static $runtimeConfiguration;
private static ?RuntimeConfiguration $runtimeConfiguration = null;

/**
* @var SchemaReflection
*/
private $schemaReflection;
private ?SchemaReflection $schemaReflection = null;

public function __construct(?DbaApi $dbaApi = null)
{
Expand Down Expand Up @@ -599,7 +590,7 @@ public function containsNamedPlaceholders(string $queryString, array $parameters
}

/**
* @return list<string>
* @return array<string>
*/
public function extractNamedPlaceholders(string $queryString): array
{
Expand Down
12 changes: 3 additions & 9 deletions src/QueryReflection/RecordingQueryReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@

final class RecordingQueryReflector implements QueryReflector, RecordingReflector
{
/**
* @var ReflectionCache
*/
private $reflectionCache;

/**
* @var QueryReflector
*/
private $reflector;
private ReflectionCache $reflectionCache;

private QueryReflector $reflector;

public function __construct(ReflectionCache $cache, QueryReflector $wrappedReflector)
{
Expand Down
Loading