Add more "object" return types

This commit is contained in:
Nicolas Grekas 2019-08-26 18:20:41 +02:00
parent 7d451144bf
commit 7f2236f7bf
37 changed files with 68 additions and 65 deletions

View File

@ -123,7 +123,7 @@ class AnnotationsCacheWarmerTest extends TestCase
/**
* @return MockObject|Reader
*/
private function getReadOnlyReader()
private function getReadOnlyReader(): object
{
$readerMock = $this->getMockBuilder('Doctrine\Common\Annotations\Reader')->getMock();
$readerMock->expects($this->exactly(0))->method('getClassAnnotations');

View File

@ -86,7 +86,7 @@ class CachePoolDeleteCommandTest extends TestCase
/**
* @return MockObject|KernelInterface
*/
private function getKernel()
private function getKernel(): object
{
$container = $this
->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')

View File

@ -52,7 +52,7 @@ class CachePruneCommandTest extends TestCase
/**
* @return MockObject|KernelInterface
*/
private function getKernel()
private function getKernel(): object
{
$container = $this
->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')
@ -78,7 +78,7 @@ class CachePruneCommandTest extends TestCase
/**
* @return MockObject|PruneableInterface
*/
private function getPruneableInterfaceMock()
private function getPruneableInterfaceMock(): object
{
$pruneable = $this
->getMockBuilder(PruneableInterface::class)

View File

@ -39,10 +39,7 @@ class TemplateIterator implements \IteratorAggregate
$this->defaultPath = $defaultPath;
}
/**
* @return \Traversable
*/
public function getIterator()
public function getIterator(): \Traversable
{
if (null !== $this->templates) {
return $this->templates;

View File

@ -391,7 +391,7 @@ class PdoAdapter extends AbstractAdapter implements PruneableInterface
/**
* @return \PDO|Connection
*/
private function getConnection()
private function getConnection(): object
{
if (null === $this->conn) {
$this->conn = new \PDO($this->dsn, $this->username, $this->password, $this->connectionOptions);

View File

@ -73,7 +73,7 @@ class ChainAdapterTest extends AdapterTestCase
/**
* @return MockObject|PruneableCacheInterface
*/
private function getPruneableMock()
private function getPruneableMock(): object
{
$pruneable = $this
->getMockBuilder(PruneableCacheInterface::class)
@ -90,7 +90,7 @@ class ChainAdapterTest extends AdapterTestCase
/**
* @return MockObject|PruneableCacheInterface
*/
private function getFailingPruneableMock()
private function getFailingPruneableMock(): object
{
$pruneable = $this
->getMockBuilder(PruneableCacheInterface::class)
@ -107,7 +107,7 @@ class ChainAdapterTest extends AdapterTestCase
/**
* @return MockObject|AdapterInterface
*/
private function getNonPruneableMock()
private function getNonPruneableMock(): object
{
return $this
->getMockBuilder(AdapterInterface::class)

View File

@ -69,7 +69,7 @@ class TagAwareAdapterTest extends AdapterTestCase
/**
* @return MockObject|PruneableCacheInterface
*/
private function getPruneableMock()
private function getPruneableMock(): object
{
$pruneable = $this
->getMockBuilder(PruneableCacheInterface::class)
@ -86,7 +86,7 @@ class TagAwareAdapterTest extends AdapterTestCase
/**
* @return MockObject|PruneableCacheInterface
*/
private function getFailingPruneableMock()
private function getFailingPruneableMock(): object
{
$pruneable = $this
->getMockBuilder(PruneableCacheInterface::class)
@ -103,7 +103,7 @@ class TagAwareAdapterTest extends AdapterTestCase
/**
* @return MockObject|AdapterInterface
*/
private function getNonPruneableMock()
private function getNonPruneableMock(): object
{
return $this
->getMockBuilder(AdapterInterface::class)

View File

@ -11,7 +11,7 @@ class Configuration implements ConfigurationInterface
{
}
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
return new TreeBuilder('root');
}

View File

@ -7,7 +7,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
return new TreeBuilder('root');
}

View File

@ -279,7 +279,7 @@ class Wither
* @required
* @return static
*/
public function withFoo1(Foo $foo)
public function withFoo1(Foo $foo): object
{
return $this->withFoo2($foo);
}
@ -288,7 +288,7 @@ class Wither
* @required
* @return static
*/
public function withFoo2(Foo $foo)
public function withFoo2(Foo $foo): object
{
$new = clone $this;
$new->foo = $foo;

View File

@ -24,10 +24,7 @@ trait ValidatorExtensionTrait
*/
protected $validator;
/**
* @return ValidatorExtension
*/
protected function getValidatorExtension()
protected function getValidatorExtension(): ValidatorExtension
{
if (!interface_exists(ValidatorInterface::class)) {
throw new \Exception('In order to use the "ValidatorExtensionTrait", the symfony/validator component must be installed');

View File

@ -50,7 +50,7 @@ class DummyTranslator implements TranslatorInterface, LocaleAwareInterface
{
}
public function getLocale()
public function getLocale(): string
{
return 'en';
}

View File

@ -35,7 +35,7 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
/**
* @return \Redis|\RedisArray|\RedisCluster|\Predis\Client
*/
abstract protected function createRedisClient(string $host);
abstract protected function createRedisClient(string $host): object;
protected function setUp(): void
{

View File

@ -14,9 +14,9 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
class RedisArraySessionHandlerTest extends AbstractRedisSessionHandlerTestCase
{
/**
* @return \RedisArray|object
* @return \RedisArray
*/
protected function createRedisClient(string $host)
protected function createRedisClient(string $host): object
{
return new \RedisArray([$host]);
}

View File

@ -25,9 +25,9 @@ class RedisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCase
}
/**
* @return \RedisCluster|object
* @return \RedisCluster
*/
protected function createRedisClient(string $host)
protected function createRedisClient(string $host): object
{
return new \RedisCluster(null, explode(' ', getenv('REDIS_CLUSTER_HOSTS')));
}

View File

@ -14,9 +14,9 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
class RedisSessionHandlerTest extends AbstractRedisSessionHandlerTestCase
{
/**
* @return \Redis|object
* @return \Redis
*/
protected function createRedisClient(string $host)
protected function createRedisClient(string $host): object
{
$client = new \Redis();
$client->connect($host);

View File

@ -56,5 +56,5 @@ abstract class AbstractCollatorTest extends TestCase
/**
* @return Collator|\Collator
*/
abstract protected function getCollator(string $locale);
abstract protected function getCollator(string $locale): object;
}

View File

@ -963,7 +963,7 @@ abstract class AbstractIntlDateFormatterTest extends TestCase
/**
* @return IntlDateFormatter|\IntlDateFormatter
*/
abstract protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null);
abstract protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null): object;
abstract protected function getIntlErrorMessage(): string;

View File

@ -177,7 +177,7 @@ class IntlDateFormatterTest extends AbstractIntlDateFormatterTest
$this->assertIsIntlSuccess($formatter, 'U_ZERO_ERROR', IntlGlobals::U_ZERO_ERROR);
}
protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null)
protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null): object
{
return new class($locale, $datetype, $timetype, $timezone, $calendar, $pattern) extends IntlDateFormatter {
};

View File

@ -57,7 +57,7 @@ class IntlDateFormatterTest extends AbstractIntlDateFormatterTest
parent::testDateAndTimeType($timestamp, $datetype, $timetype, $expected);
}
protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null)
protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null): object
{
IntlTestHelper::requireFullIntl($this, '55.1');

View File

@ -836,7 +836,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
/**
* @return NumberFormatter|\NumberFormatter
*/
abstract protected function getNumberFormatter(string $locale = 'en', string $style = null, string $pattern = null);
abstract protected function getNumberFormatter(string $locale = 'en', string $style = null, string $pattern = null): object;
abstract protected function getIntlErrorMessage(): string;

View File

@ -216,7 +216,7 @@ class PdoStore implements PersistingStoreInterface
/**
* @return \PDO|Connection
*/
private function getConnection()
private function getConnection(): object
{
if (null === $this->conn) {
$this->conn = new \PDO($this->dsn, $this->username, $this->password, $this->connectionOptions);

View File

@ -34,7 +34,7 @@ abstract class AbstractRedisStoreTest extends AbstractStoreTest
*
* @return \Redis|\RedisArray|\RedisCluster|\Predis\Client
*/
abstract protected function getRedisConnection();
abstract protected function getRedisConnection(): object;
/**
* {@inheritdoc}

View File

@ -26,7 +26,7 @@ class PredisStoreTest extends AbstractRedisStoreTest
}
}
protected function getRedisConnection()
protected function getRedisConnection(): object
{
$redis = new \Predis\Client('tcp://'.getenv('REDIS_HOST').':6379');
$redis->connect();

View File

@ -29,7 +29,10 @@ class RedisArrayStoreTest extends AbstractRedisStoreTest
}
}
protected function getRedisConnection()
/**
* @return \RedisArray
*/
protected function getRedisConnection(): object
{
$redis = new \RedisArray([getenv('REDIS_HOST')]);

View File

@ -28,7 +28,10 @@ class RedisClusterStoreTest extends AbstractRedisStoreTest
}
}
protected function getRedisConnection()
/**
* @return \RedisCluster
*/
protected function getRedisConnection(): object
{
return new \RedisCluster(null, explode(' ', getenv('REDIS_CLUSTER_HOSTS')));
}

View File

@ -28,7 +28,10 @@ class RedisStoreTest extends AbstractRedisStoreTest
}
}
protected function getRedisConnection()
/**
* @return \Redis
*/
protected function getRedisConnection(): object
{
$redis = new \Redis();
$redis->connect(getenv('REDIS_HOST'));

View File

@ -39,7 +39,7 @@ class DockBlockFallback
/**
* @return int
*/
public function getProtAcc()
public function getProtAcc(): int
{
return $this->protAcc;
}

View File

@ -26,7 +26,7 @@ class DummyExtractor implements PropertyListExtractorInterface, PropertyDescript
/**
* {@inheritdoc}
*/
public function getShortDescription($class, $property, array $context = [])
public function getShortDescription($class, $property, array $context = []): ?string
{
return 'short';
}
@ -34,7 +34,7 @@ class DummyExtractor implements PropertyListExtractorInterface, PropertyDescript
/**
* {@inheritdoc}
*/
public function getLongDescription($class, $property, array $context = [])
public function getLongDescription($class, $property, array $context = []): ?string
{
return 'long';
}
@ -42,7 +42,7 @@ class DummyExtractor implements PropertyListExtractorInterface, PropertyDescript
/**
* {@inheritdoc}
*/
public function getTypes($class, $property, array $context = [])
public function getTypes($class, $property, array $context = []): ?array
{
return [new Type(Type::BUILTIN_TYPE_INT)];
}
@ -50,7 +50,7 @@ class DummyExtractor implements PropertyListExtractorInterface, PropertyDescript
/**
* {@inheritdoc}
*/
public function isReadable($class, $property, array $context = [])
public function isReadable($class, $property, array $context = []): ?bool
{
return true;
}
@ -58,7 +58,7 @@ class DummyExtractor implements PropertyListExtractorInterface, PropertyDescript
/**
* {@inheritdoc}
*/
public function isWritable($class, $property, array $context = [])
public function isWritable($class, $property, array $context = []): ?bool
{
return true;
}
@ -66,7 +66,7 @@ class DummyExtractor implements PropertyListExtractorInterface, PropertyDescript
/**
* {@inheritdoc}
*/
public function getProperties($class, array $context = [])
public function getProperties($class, array $context = []): ?array
{
return ['a', 'b'];
}

View File

@ -27,7 +27,7 @@ class NullExtractor implements PropertyListExtractorInterface, PropertyDescripti
/**
* {@inheritdoc}
*/
public function getShortDescription($class, $property, array $context = [])
public function getShortDescription($class, $property, array $context = []): ?string
{
$this->assertIsString($class);
$this->assertIsString($property);
@ -38,7 +38,7 @@ class NullExtractor implements PropertyListExtractorInterface, PropertyDescripti
/**
* {@inheritdoc}
*/
public function getLongDescription($class, $property, array $context = [])
public function getLongDescription($class, $property, array $context = []): ?string
{
$this->assertIsString($class);
$this->assertIsString($property);
@ -49,7 +49,7 @@ class NullExtractor implements PropertyListExtractorInterface, PropertyDescripti
/**
* {@inheritdoc}
*/
public function getTypes($class, $property, array $context = [])
public function getTypes($class, $property, array $context = []): ?array
{
$this->assertIsString($class);
$this->assertIsString($property);
@ -60,7 +60,7 @@ class NullExtractor implements PropertyListExtractorInterface, PropertyDescripti
/**
* {@inheritdoc}
*/
public function isReadable($class, $property, array $context = [])
public function isReadable($class, $property, array $context = []): ?bool
{
$this->assertIsString($class);
$this->assertIsString($property);
@ -71,7 +71,7 @@ class NullExtractor implements PropertyListExtractorInterface, PropertyDescripti
/**
* {@inheritdoc}
*/
public function isWritable($class, $property, array $context = [])
public function isWritable($class, $property, array $context = []): ?bool
{
$this->assertIsString($class);
$this->assertIsString($property);
@ -82,7 +82,7 @@ class NullExtractor implements PropertyListExtractorInterface, PropertyDescripti
/**
* {@inheritdoc}
*/
public function getProperties($class, array $context = [])
public function getProperties($class, array $context = []): ?array
{
$this->assertIsString($class);

View File

@ -106,7 +106,7 @@ class TestObjectLoader extends ObjectLoader
return 'service';
}
protected function getObject(string $id)
protected function getObject(string $id): object
{
return $this->loaderMap[$id] ?? null;
}

View File

@ -328,22 +328,22 @@ class DaoAuthenticationProviderTest extends TestCase
class TestUser implements UserInterface
{
public function getRoles()
public function getRoles(): array
{
return [];
}
public function getPassword()
public function getPassword(): ?string
{
return 'secret';
}
public function getSalt()
public function getSalt(): ?string
{
return null;
}
public function getUsername()
public function getUsername(): string
{
return 'jane_doe';
}

View File

@ -23,7 +23,7 @@ trait ObjectToPopulateTrait
*
* @return object|null an object if things check out, null otherwise
*/
protected function extractObjectToPopulate(string $class, array $context, string $key = null)
protected function extractObjectToPopulate(string $class, array $context, string $key = null): ?object
{
$key = $key ?? AbstractNormalizer::OBJECT_TO_POPULATE;

View File

@ -828,7 +828,7 @@ XML;
/**
* @return MockObject|NormalizerInterface
*/
private function createMockDateTimeNormalizer()
private function createMockDateTimeNormalizer(): object
{
$mock = $this->getMockBuilder('\Symfony\Component\Serializer\Normalizer\CustomNormalizer')->getMock();

View File

@ -78,7 +78,7 @@ class TestMemberMetadata extends MemberMetadata
{
}
protected function newReflectionMember($object)
protected function newReflectionMember($object): object
{
}
}

View File

@ -55,7 +55,7 @@ trait VarDumperTestTrait
/**
* @return string|null
*/
protected function getDump($data, $key = null, int $filter = 0)
protected function getDump($data, $key = null, int $filter = 0): ?string
{
if (null === $flags = $this->varDumperConfig['flags']) {
$flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0;

View File

@ -35,7 +35,7 @@ class Exporter
*
* @throws NotInstantiableTypeException When a value cannot be serialized
*/
public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount, &$valuesAreStatic)
public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount, &$valuesAreStatic): array
{
$refs = $values;
foreach ($values as $k => $value) {