Skip to content

[Cache] Add types to private properties #42025

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

Merged
merged 1 commit into from
Jul 9, 2021
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
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/ApcuAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class ApcuAdapter extends AbstractAdapter
{
private $marshaller;
private ?MarshallerInterface $marshaller;

/**
* @throws CacheException if APCu is not enabled
Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/Cache/Adapter/ArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
{
use LoggerAwareTrait;

private $storeSerialized;
private $values = [];
private $expiries = [];
private $defaultLifetime;
private $maxLifetime;
private $maxItems;

private static $createCacheItem;
private bool $storeSerialized;
private array $values = [];
private array $expiries = [];
private int $defaultLifetime;
private float $maxLifetime;
private int $maxItems;

private static \Closure $createCacheItem;

/**
* @param bool $storeSerialized Disabling serialization can lead to cache corruptions when storing mutable values but increases performance otherwise
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Cache/Adapter/ChainAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class ChainAdapter implements AdapterInterface, CacheInterface, PruneableInterfa
{
use ContractsTrait;

private $adapters = [];
private $adapterCount;
private $defaultLifetime;
private array $adapters = [];
private int $adapterCount;
private int $defaultLifetime;

private static $syncItem;
private static \Closure $syncItem;

/**
* @param CacheItemPoolInterface[] $adapters The ordered list of adapters used to fetch cached items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class CouchbaseBucketAdapter extends AbstractAdapter
'durabilityTimeout',
];

private $bucket;
private $marshaller;
private \CouchbaseBucket $bucket;
private MarshallerInterface $marshaller;

public function __construct(\CouchbaseBucket $bucket, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
class DoctrineAdapter extends AbstractAdapter
{
private $provider;
private CacheProvider $provider;

public function __construct(CacheProvider $provider, string $namespace = '', int $defaultLifetime = 0)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class MemcachedAdapter extends AbstractAdapter
\Memcached::OPT_SERIALIZER => \Memcached::SERIALIZER_PHP,
];

private $marshaller;
private $client;
private $lazyClient;
private MarshallerInterface $marshaller;
private \Memcached $client;
private \Memcached $lazyClient;

/**
* Using a MemcachedAdapter with a TagAwareAdapter for storing tags is discouraged.
Expand Down Expand Up @@ -327,7 +327,7 @@ private function checkResultCode(mixed $result)

private function getClient(): \Memcached
{
if ($this->client) {
if (isset($this->client)) {
return $this->client;
}

Expand Down
39 changes: 18 additions & 21 deletions src/Symfony/Component/Cache/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ class PdoAdapter extends AbstractAdapter implements PruneableInterface
{
protected $maxIdLength = 255;

private $marshaller;
private $conn;
private $dsn;
private $driver;
private $serverVersion;
private $table = 'cache_items';
private $idCol = 'item_id';
private $dataCol = 'item_data';
private $lifetimeCol = 'item_lifetime';
private $timeCol = 'item_time';
private $username = '';
private $password = '';
private $connectionOptions = [];
private $namespace;
private MarshallerInterface $marshaller;
private \PDO|Connection $conn;
private string $dsn;
private string $driver;
private string $serverVersion;
private mixed $table = 'cache_items';
private mixed $idCol = 'item_id';
private mixed $dataCol = 'item_data';
private mixed $lifetimeCol = 'item_lifetime';
private mixed $timeCol = 'item_time';
private mixed $username = '';
private mixed $password = '';
private mixed $connectionOptions = [];
private string $namespace;

/**
* You can either pass an existing database connection as PDO instance or
Expand Down Expand Up @@ -425,12 +425,9 @@ protected function doSave(array $values, int $lifetime)
return $failed;
}

/**
* @return \PDO|Connection
*/
private function getConnection(): object
private function getConnection(): \PDO|Connection
{
if (null === $this->conn) {
if (!isset($this->conn)) {
if (strpos($this->dsn, '://')) {
if (!class_exists(DriverManager::class)) {
throw new InvalidArgumentException(sprintf('Failed to parse the DSN "%s". Try running "composer require doctrine/dbal".', $this->dsn));
Expand All @@ -441,7 +438,7 @@ private function getConnection(): object
$this->conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
}
}
if (null === $this->driver) {
if (!isset($this->driver)) {
if ($this->conn instanceof \PDO) {
$this->driver = $this->conn->getAttribute(\PDO::ATTR_DRIVER_NAME);
} else {
Expand Down Expand Up @@ -483,7 +480,7 @@ private function getConnection(): object

private function getServerVersion(): string
{
if (null === $this->serverVersion) {
if (!isset($this->serverVersion)) {
$conn = $this->conn instanceof \PDO ? $this->conn : $this->conn->getWrappedConnection();
if ($conn instanceof \PDO) {
$this->serverVersion = $conn->getAttribute(\PDO::ATTR_SERVER_VERSION);
Expand Down
26 changes: 13 additions & 13 deletions src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ class PhpArrayAdapter implements AdapterInterface, CacheInterface, PruneableInte
use ContractsTrait;
use ProxyTrait;

private $file;
private $keys;
private $values;
private string $file;
private array $keys;
private array $values;

private static $createCacheItem;
private static $valuesCache = [];
private static \Closure $createCacheItem;
private static array $valuesCache = [];

/**
* @param string $file The PHP file were values are cached
Expand Down Expand Up @@ -85,7 +85,7 @@ public static function create(string $file, CacheItemPoolInterface $fallbackPool
*/
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null)
{
if (null === $this->values) {
if (!isset($this->values)) {
$this->initialize();
}
if (!isset($this->keys[$key])) {
Expand Down Expand Up @@ -121,7 +121,7 @@ public function getItem(mixed $key): CacheItem
if (!\is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
}
if (null === $this->values) {
if (!isset($this->values)) {
$this->initialize();
}
if (!isset($this->keys[$key])) {
Expand Down Expand Up @@ -155,7 +155,7 @@ public function getItems(array $keys = []): iterable
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
}
}
if (null === $this->values) {
if (!isset($this->values)) {
$this->initialize();
}

Expand All @@ -170,7 +170,7 @@ public function hasItem(mixed $key): bool
if (!\is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
}
if (null === $this->values) {
if (!isset($this->values)) {
$this->initialize();
}

Expand All @@ -185,7 +185,7 @@ public function deleteItem(mixed $key): bool
if (!\is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
}
if (null === $this->values) {
if (!isset($this->values)) {
$this->initialize();
}

Expand All @@ -211,7 +211,7 @@ public function deleteItems(array $keys): bool
$fallbackKeys[] = $key;
}
}
if (null === $this->values) {
if (!isset($this->values)) {
$this->initialize();
}

Expand All @@ -227,7 +227,7 @@ public function deleteItems(array $keys): bool
*/
public function save(CacheItemInterface $item): bool
{
if (null === $this->values) {
if (!isset($this->values)) {
$this->initialize();
}

Expand All @@ -239,7 +239,7 @@ public function save(CacheItemInterface $item): bool
*/
public function saveDeferred(CacheItemInterface $item): bool
{
if (null === $this->values) {
if (!isset($this->values)) {
$this->initialize();
}

Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class PhpFilesAdapter extends AbstractAdapter implements PruneableInterface
doDelete as private doCommonDelete;
}

private $includeHandler;
private $appendOnly;
private $values = [];
private $files = [];
private \Closure $includeHandler;
private bool $appendOnly;
private array $values = [];
private array $files = [];

private static $startTime;
private static $valuesCache = [];
private static int $startTime;
private static array $valuesCache = [];

/**
* @param $appendOnly Set to `true` to gain extra performance when the items stored in this pool never expire.
Expand Down
14 changes: 7 additions & 7 deletions src/Symfony/Component/Cache/Adapter/ProxyAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ class ProxyAdapter implements AdapterInterface, CacheInterface, PruneableInterfa
use ContractsTrait;
use ProxyTrait;

private $namespace = '';
private $namespaceLen;
private $poolHash;
private $defaultLifetime;
private string $namespace = '';
private int $namespaceLen;
private string $poolHash;
private int $defaultLifetime;

private static $createCacheItem;
private static $setInnerItem;
private static \Closure $createCacheItem;
private static \Closure $setInnerItem;

public function __construct(CacheItemPoolInterface $pool, string $namespace = '', int $defaultLifetime = 0)
{
$this->pool = $pool;
$this->poolHash = $poolHash = spl_object_hash($pool);
$this->poolHash = spl_object_hash($pool);
if ('' !== $namespace) {
\assert('' !== CacheItem::validateKey($namespace));
$this->namespace = $namespace;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/Psr16Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Psr16Adapter extends AbstractAdapter implements PruneableInterface, Resett
*/
protected const NS_SEPARATOR = '_';

private $miss;
private object $miss;

public function __construct(CacheInterface $pool, string $namespace = '', int $defaultLifetime = 0)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
private const DEFAULT_CACHE_TTL = 8640000;

/**
* @var string|null detected eviction policy used on Redis server
* detected eviction policy used on Redis server
*/
private $redisEvictionPolicy;
private string $redisEvictionPolicy;

public function __construct(\Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
{
Expand Down Expand Up @@ -268,7 +268,7 @@ protected function doInvalidate(array $tagIds): bool

private function getRedisEvictionPolicy(): string
{
if (null !== $this->redisEvictionPolicy) {
if (isset($this->redisEvictionPolicy)) {
return $this->redisEvictionPolicy;
}

Expand Down
18 changes: 9 additions & 9 deletions src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ class TagAwareAdapter implements TagAwareAdapterInterface, TagAwareCacheInterfac

public const TAGS_PREFIX = "\0tags\0";

private $deferred = [];
private $tags;
private $knownTagVersions = [];
private $knownTagVersionsTtl;
private array $deferred = [];
private AdapterInterface $tags;
private array $knownTagVersions = [];
private float $knownTagVersionsTtl;

private static $createCacheItem;
private static $setCacheItemTags;
private static $getTagsByKey;
private static $invalidateTags;
private static \Closure $createCacheItem;
private static \Closure $setCacheItemTags;
private static \Closure $getTagsByKey;
private static \Closure $invalidateTags;

public function __construct(AdapterInterface $itemsPool, AdapterInterface $tagsPool = null, float $knownTagVersionsTtl = 0.15)
{
$this->pool = $itemsPool;
$this->tags = $tagsPool ?: $itemsPool;
$this->tags = $tagsPool ?? $itemsPool;
$this->knownTagVersionsTtl = $knownTagVersionsTtl;
self::$createCacheItem ?? self::$createCacheItem = \Closure::bind(
static function ($key, $value, CacheItem $protoItem) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/TraceableAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class TraceableAdapter implements AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface
{
protected $pool;
private $calls = [];
private array $calls = [];

public function __construct(AdapterInterface $pool)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CacheDataCollector extends DataCollector implements LateDataCollectorInter
/**
* @var TraceableAdapter[]
*/
private $instances = [];
private array $instances = [];

public function addInstance(string $name, TraceableAdapter $instance)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class DefaultMarshaller implements MarshallerInterface
{
private $useIgbinarySerialize = true;
private bool $useIgbinarySerialize = true;

public function __construct(bool $useIgbinarySerialize = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class DeflateMarshaller implements MarshallerInterface
{
private $marshaller;
private MarshallerInterface $marshaller;

public function __construct(MarshallerInterface $marshaller)
{
Expand Down
Loading