Add types to private/final/internal methods and constructors.
This commit is contained in:
parent
afad96285e
commit
def0ac7a2b
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Test;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
@ -137,7 +138,7 @@ class TestContainer extends Container
|
||||
return $this->getPublicContainer()->getRemovedIds();
|
||||
}
|
||||
|
||||
private function getPublicContainer()
|
||||
private function getPublicContainer(): Container
|
||||
{
|
||||
if (null === $container = $this->kernel->getContainer()) {
|
||||
throw new \LogicException('Cannot access the container on a non-booted kernel. Did you forget to boot it?');
|
||||
@ -146,7 +147,7 @@ class TestContainer extends Container
|
||||
return $container;
|
||||
}
|
||||
|
||||
private function getPrivateContainer()
|
||||
private function getPrivateContainer(): ContainerInterface
|
||||
{
|
||||
return $this->getPublicContainer()->get($this->privateServicesLocatorId);
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
return $r;
|
||||
}
|
||||
|
||||
private function getExpressionLanguage()
|
||||
private function getExpressionLanguage(): ExpressionLanguage
|
||||
{
|
||||
if (null === $this->expressionLanguage) {
|
||||
if (!class_exists(ExpressionLanguage::class)) {
|
||||
@ -200,7 +200,7 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
}
|
||||
|
||||
$providers = $this->container->getExpressionLanguageProviders();
|
||||
$this->expressionLanguage = new ExpressionLanguage(null, $providers, function ($arg) {
|
||||
$this->expressionLanguage = new ExpressionLanguage(null, $providers, function (string $arg): string {
|
||||
if ('""' === substr_replace($arg, '', 1, -1)) {
|
||||
$id = stripcslashes(substr($arg, 1, -1));
|
||||
$this->inExpression = true;
|
||||
|
@ -81,6 +81,9 @@ class AutowirePass extends AbstractRecursivePass
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
private function doProcessValue($value, bool $isRoot = false)
|
||||
{
|
||||
if ($value instanceof TypedReference) {
|
||||
@ -371,7 +374,7 @@ class AutowirePass extends AbstractRecursivePass
|
||||
$this->ambiguousServiceTypes[$type][] = $id;
|
||||
}
|
||||
|
||||
private function createTypeNotFoundMessageCallback(TypedReference $reference, string $label)
|
||||
private function createTypeNotFoundMessageCallback(TypedReference $reference, string $label): callable
|
||||
{
|
||||
if (null === $this->typesClone->container) {
|
||||
$this->typesClone->container = new ContainerBuilder($this->container->getParameterBag());
|
||||
@ -386,7 +389,7 @@ class AutowirePass extends AbstractRecursivePass
|
||||
})->bindTo($this->typesClone);
|
||||
}
|
||||
|
||||
private function createTypeNotFoundMessage(TypedReference $reference, string $label, string $currentId)
|
||||
private function createTypeNotFoundMessage(TypedReference $reference, string $label, string $currentId): string
|
||||
{
|
||||
if (!$r = $this->container->getReflectionClass($type = $reference->getType(), false)) {
|
||||
// either $type does not exist or a parent class does not exist
|
||||
@ -420,7 +423,7 @@ class AutowirePass extends AbstractRecursivePass
|
||||
return $message;
|
||||
}
|
||||
|
||||
private function createTypeAlternatives(ContainerBuilder $container, TypedReference $reference)
|
||||
private function createTypeAlternatives(ContainerBuilder $container, TypedReference $reference): string
|
||||
{
|
||||
// try suggesting available aliases first
|
||||
if ($message = $this->getAliasesSuggestionForType($container, $type = $reference->getType())) {
|
||||
@ -444,7 +447,7 @@ class AutowirePass extends AbstractRecursivePass
|
||||
return sprintf(' You should maybe alias this %s to %s.', class_exists($type, false) ? 'class' : 'interface', $message);
|
||||
}
|
||||
|
||||
private function getAliasesSuggestionForType(ContainerBuilder $container, string $type)
|
||||
private function getAliasesSuggestionForType(ContainerBuilder $container, string $type): ?string
|
||||
{
|
||||
$aliases = [];
|
||||
foreach (class_parents($type) + class_implements($type) as $parent) {
|
||||
|
@ -60,7 +60,7 @@ class RegisterEnvVarProcessorsPass implements CompilerPassInterface
|
||||
}
|
||||
}
|
||||
|
||||
private static function validateProvidedTypes($types, $class)
|
||||
private static function validateProvidedTypes(string $types, string $class): array
|
||||
{
|
||||
$types = explode('|', $types);
|
||||
|
||||
|
@ -205,6 +205,9 @@ class ResolveBindingsPass extends AbstractRecursivePass
|
||||
return parent::processValue($value, $isRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
private function getBindingValue(BoundArgument $binding)
|
||||
{
|
||||
list($bindingValue, $bindingId) = $binding->getValues();
|
||||
|
@ -26,7 +26,7 @@ class ResolveHotPathPass extends AbstractRecursivePass
|
||||
private $tagName;
|
||||
private $resolvedIds = [];
|
||||
|
||||
public function __construct($tagName = 'container.hot_path')
|
||||
public function __construct(string $tagName = 'container.hot_path')
|
||||
{
|
||||
$this->tagName = $tagName;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class ResolveInstanceofConditionalsPass implements CompilerPassInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function processDefinition(ContainerBuilder $container, string $id, Definition $definition)
|
||||
private function processDefinition(ContainerBuilder $container, string $id, Definition $definition): Definition
|
||||
{
|
||||
$instanceofConditionals = $definition->getInstanceofConditionals();
|
||||
$autoconfiguredInstanceof = $definition->isAutoconfigured() ? $container->getAutoconfiguredInstanceof() : [];
|
||||
@ -144,7 +144,7 @@ class ResolveInstanceofConditionalsPass implements CompilerPassInterface
|
||||
return $definition;
|
||||
}
|
||||
|
||||
private function mergeConditionals(array $autoconfiguredInstanceof, array $instanceofConditionals, ContainerBuilder $container)
|
||||
private function mergeConditionals(array $autoconfiguredInstanceof, array $instanceofConditionals, ContainerBuilder $container): array
|
||||
{
|
||||
// make each value an array of ChildDefinition
|
||||
$conditionals = array_map(function ($childDef) { return [$childDef]; }, $autoconfiguredInstanceof);
|
||||
|
@ -51,6 +51,8 @@ class ResolveInvalidReferencesPass implements CompilerPassInterface
|
||||
/**
|
||||
* Processes arguments to determine invalid references.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws RuntimeException When an invalid reference is found
|
||||
*/
|
||||
private function processValue($value, int $rootLevel = 0, int $level = 0)
|
||||
|
@ -88,9 +88,8 @@ final class ServiceLocatorTagPass extends AbstractRecursivePass
|
||||
|
||||
/**
|
||||
* @param Reference[] $refMap
|
||||
* @param string|null $callerId
|
||||
*/
|
||||
public static function register(ContainerBuilder $container, array $refMap, $callerId = null): Reference
|
||||
public static function register(ContainerBuilder $container, array $refMap, string $callerId = null): Reference
|
||||
{
|
||||
foreach ($refMap as $id => $ref) {
|
||||
if (!$ref instanceof Reference) {
|
||||
|
@ -422,9 +422,14 @@ class Container implements ResettableContainerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|false $registry
|
||||
* @param string|bool $load
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final protected function getService($registry, $id, $method, $load)
|
||||
final protected function getService($registry, string $id, ?string $method, $load)
|
||||
{
|
||||
if ('service_container' === $id) {
|
||||
return $this;
|
||||
|
@ -1236,7 +1236,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
|
||||
yield $k => $this->resolveServices($v);
|
||||
}
|
||||
}, function () use ($value) {
|
||||
}, function () use ($value): int {
|
||||
$count = 0;
|
||||
foreach ($value->getValues() as $v) {
|
||||
foreach (self::getServiceConditionals($v) as $s) {
|
||||
@ -1641,7 +1641,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function getExpressionLanguage()
|
||||
private function getExpressionLanguage(): ExpressionLanguage
|
||||
{
|
||||
if (null === $this->expressionLanguage) {
|
||||
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
|
||||
@ -1653,7 +1653,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
return $this->expressionLanguage;
|
||||
}
|
||||
|
||||
private function inVendors(string $path)
|
||||
private function inVendors(string $path): bool
|
||||
{
|
||||
if (null === $this->vendors) {
|
||||
$resource = new ComposerResource();
|
||||
|
@ -183,7 +183,7 @@ class GraphvizDumper extends Dumper
|
||||
return $nodes;
|
||||
}
|
||||
|
||||
private function cloneContainer()
|
||||
private function cloneContainer(): ContainerBuilder
|
||||
{
|
||||
$parameterBag = new ParameterBag($this->container->getParameterBag()->all());
|
||||
|
||||
|
@ -684,7 +684,7 @@ EOF;
|
||||
return $calls;
|
||||
}
|
||||
|
||||
private function addServiceProperties(Definition $definition, string $variableName = 'instance')
|
||||
private function addServiceProperties(Definition $definition, string $variableName = 'instance'): string
|
||||
{
|
||||
$code = '';
|
||||
foreach ($definition->getProperties() as $name => $value) {
|
||||
@ -967,7 +967,7 @@ EOTXT
|
||||
return $publicServices.$privateServices;
|
||||
}
|
||||
|
||||
private function generateServiceFiles(array $services)
|
||||
private function generateServiceFiles(array $services): iterable
|
||||
{
|
||||
$definitions = $this->container->getDefinitions();
|
||||
ksort($definitions);
|
||||
@ -993,7 +993,7 @@ EOTXT
|
||||
}
|
||||
}
|
||||
|
||||
private function addNewInstance(Definition $definition, string $return = '', string $id = null)
|
||||
private function addNewInstance(Definition $definition, string $return = '', string $id = null): string
|
||||
{
|
||||
$tail = $return ? ";\n" : '';
|
||||
|
||||
@ -1914,7 +1914,7 @@ EOF;
|
||||
}
|
||||
}
|
||||
|
||||
private function getExpressionLanguage()
|
||||
private function getExpressionLanguage(): ExpressionLanguage
|
||||
{
|
||||
if (null === $this->expressionLanguage) {
|
||||
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
|
||||
@ -1941,7 +1941,7 @@ EOF;
|
||||
return $this->expressionLanguage;
|
||||
}
|
||||
|
||||
private function isHotPath(Definition $definition)
|
||||
private function isHotPath(Definition $definition): bool
|
||||
{
|
||||
return $this->hotPathTag && $definition->hasTag($this->hotPathTag) && !$definition->isDeprecated();
|
||||
}
|
||||
@ -1965,6 +1965,9 @@ EOF;
|
||||
return 1 === \count($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
private function export($value)
|
||||
{
|
||||
if (null !== $this->targetDirRegex && \is_string($value) && preg_match($this->targetDirRegex, $value, $matches, PREG_OFFSET_CAPTURE)) {
|
||||
@ -1988,6 +1991,9 @@ EOF;
|
||||
return $this->doExport($value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
private function doExport($value, bool $resolveEnv = false)
|
||||
{
|
||||
$shouldCacheValue = $resolveEnv && \is_string($value);
|
||||
|
@ -338,11 +338,9 @@ class XmlDumper extends Dumper
|
||||
*
|
||||
* @param mixed $value Value to convert
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws RuntimeException When trying to dump object or resource
|
||||
*/
|
||||
public static function phpToXml($value)
|
||||
public static function phpToXml($value): string
|
||||
{
|
||||
switch (true) {
|
||||
case null === $value:
|
||||
|
@ -201,6 +201,8 @@ class YamlDumper extends Dumper
|
||||
* Dumps callable to YAML format.
|
||||
*
|
||||
* @param mixed $callable
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function dumpCallable($callable)
|
||||
{
|
||||
@ -299,7 +301,7 @@ class YamlDumper extends Dumper
|
||||
return sprintf('%%%s%%', $id);
|
||||
}
|
||||
|
||||
private function getExpressionCall(string $expression)
|
||||
private function getExpressionCall(string $expression): string
|
||||
{
|
||||
return sprintf('@=%s', $expression);
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final public function getProcessedConfigs()
|
||||
final public function getProcessedConfigs(): array
|
||||
{
|
||||
try {
|
||||
return $this->processedConfigs;
|
||||
|
@ -75,7 +75,7 @@ class PrototypeConfigurator extends AbstractServiceConfigurator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function exclude($excludes)
|
||||
final public function exclude($excludes): self
|
||||
{
|
||||
$this->excludes = (array) $excludes;
|
||||
|
||||
|
@ -102,7 +102,7 @@ abstract class FileLoader extends BaseFileLoader
|
||||
}
|
||||
}
|
||||
|
||||
private function findClasses(string $namespace, string $pattern, array $excludePatterns)
|
||||
private function findClasses(string $namespace, string $pattern, array $excludePatterns): array
|
||||
{
|
||||
$parameterBag = $this->container->getParameterBag();
|
||||
|
||||
|
@ -66,6 +66,8 @@ class IniFileLoader extends FileLoader
|
||||
* Note that the following features are not supported:
|
||||
* * strings with escaped quotes are not supported "foo\"bar";
|
||||
* * string concatenation ("foo" "bar").
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function phpize(string $value)
|
||||
{
|
||||
|
@ -435,7 +435,7 @@ class XmlFileLoader extends FileLoader
|
||||
}
|
||||
}
|
||||
|
||||
private function getArgumentsAsPhp(\DOMElement $node, string $name, string $file, bool $isChildDefinition = false)
|
||||
private function getArgumentsAsPhp(\DOMElement $node, string $name, string $file, bool $isChildDefinition = false): array
|
||||
{
|
||||
$arguments = [];
|
||||
foreach ($this->getChildren($node, $name) as $arg) {
|
||||
|
@ -64,8 +64,10 @@ class ServiceLocator implements ServiceProviderInterface
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withContext($externalId, Container $container)
|
||||
public function withContext(string $externalId, Container $container)
|
||||
{
|
||||
$locator = clone $this;
|
||||
$locator->externalId = $externalId;
|
||||
@ -127,7 +129,7 @@ class ServiceLocator implements ServiceProviderInterface
|
||||
return new ServiceCircularReferenceException($id, $path);
|
||||
}
|
||||
|
||||
private function formatAlternatives(array $alternatives = null, string $separator = 'and')
|
||||
private function formatAlternatives(array $alternatives = null, string $separator = 'and'): string
|
||||
{
|
||||
$format = '"%s"%s';
|
||||
if (null === $alternatives) {
|
||||
|
@ -71,7 +71,7 @@ class ResolveParameterPlaceHoldersPassTest extends TestCase
|
||||
$this->assertSame($this->container->getParameterBag()->resolveValue('%env(BAZ)%'), $boundValue);
|
||||
}
|
||||
|
||||
private function createContainerBuilder()
|
||||
private function createContainerBuilder(): ContainerBuilder
|
||||
{
|
||||
$containerBuilder = new ContainerBuilder();
|
||||
|
||||
|
@ -110,7 +110,7 @@ class YamlDumperTest extends TestCase
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services_with_tagged_argument.yml', $dumper->dump());
|
||||
}
|
||||
|
||||
private function assertEqualYamlStructure($expected, $yaml, $message = '')
|
||||
private function assertEqualYamlStructure(string $expected, string $yaml, string $message = '')
|
||||
{
|
||||
$parser = new Parser();
|
||||
|
||||
|
Reference in New Issue
Block a user