Skip to content

Commit

Permalink
Add missing return types
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Apr 28, 2023
1 parent 9e0eb97 commit 66c2147
Show file tree
Hide file tree
Showing 27 changed files with 568 additions and 119 deletions.
501 changes: 393 additions & 108 deletions .github/expected-missing-return-types.diff

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function getValues(): array

/**
* @param Reference[] $values The service references to put in the set
*
* @return void
*/
public function setValues(array $values)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/DependencyInjection/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALI
*
* As a separate method to allow "get()" to use the really fast `??` operator.
*/
private static function make(self $container, string $id, int $invalidBehavior)
private static function make(self $container, string $id, int $invalidBehavior): ?object
{
if (isset($container->loading[$id])) {
throw new ServiceCircularReferenceException($id, array_merge(array_keys($container->loading), [$id]));
Expand Down Expand Up @@ -338,6 +338,8 @@ public static function underscore(string $id): string

/**
* Creates a service by requiring its factory file.
*
* @return mixed
*/
protected function load(string $file)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ public function isCompiled(): bool
if ($this->asFiles && !$this->inlineFactories) {
$code .= <<<'EOF'
protected function load($file, $lazyLoad = true)
protected function load($file, $lazyLoad = true): mixed
{
if (class_exists($class = __NAMESPACE__.'\\'.$file, false)) {
return $class::do($this, $lazyLoad);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn
{
private array $processedConfigs = [];

/**
* @return string|false
*/
public function getXsdValidationBasePath()
{
return false;
}

/**
* @return string
*/
public function getNamespace()
{
return 'http://example.org/schema/dic/'.$this->getAlias();
Expand Down Expand Up @@ -67,6 +73,9 @@ public function getAlias(): string
return Container::underscore($classBaseName);
}

/**
* @return ConfigurationInterface|null
*/
public function getConfiguration(array $config, ContainerBuilder $container)
{
$class = static::class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ private function isUsingShortSyntax(array $service): bool
/**
* @throws InvalidArgumentException When tags are invalid
*/
private function parseDefinition(string $id, array|string|null $service, string $file, array $defaults, bool $return = false, bool $trackBindings = true)
private function parseDefinition(string $id, array|string|null $service, string $file, array $defaults, bool $return = false, bool $trackBindings = true): Definition|Alias|null
{
if (preg_match('/^_[a-zA-Z0-9_]*$/', $id)) {
throw new InvalidArgumentException(sprintf('Service names that start with an underscore are reserved. Rename the "%s" service or define it in XML instead.', $id));
Expand Down Expand Up @@ -706,6 +706,8 @@ private function parseDefinition(string $id, array|string|null $service, string
} else {
$this->setDefinition($id, $definition);
}

return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,41 @@ public function __construct(
$this->resolved = true;
}

/**
* @return never
*/
public function clear()
{
throw new LogicException('Impossible to call clear() on a frozen ParameterBag.');
}

/**
* @return never
*/
public function add(array $parameters)
{
throw new LogicException('Impossible to call add() on a frozen ParameterBag.');
}

/**
* @return never
*/
public function set(string $name, array|bool|string|int|float|\UnitEnum|null $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

/**
* @return never
*/
public function deprecate(string $name, string $package, string $version, string $message = 'The parameter "%s" is deprecated.')
{
throw new LogicException('Impossible to call deprecate() on a frozen ParameterBag.');
}

/**
* @return never
*/
public function remove(string $name)
{
throw new LogicException('Impossible to call remove() on a frozen ParameterBag.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ public function resolveString(string $value, array $resolving = []): mixed
}, $value);
}

/**
* @return bool
*/
public function isResolved()
{
return $this->resolved;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ProjectServiceContainer extends Container
return require $this->containerDir.\DIRECTORY_SEPARATOR.'removed-ids.php';
}

protected function load($file, $lazyLoad = true)
protected function load($file, $lazyLoad = true): mixed
{
if (class_exists($class = __NAMESPACE__.'\\'.$file, false)) {
return $class::do($this, $lazyLoad);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ class ProjectServiceContainer extends Container
return require $this->containerDir.\DIRECTORY_SEPARATOR.'removed-ids.php';
}

protected function load($file, $lazyLoad = true)
protected function load($file, $lazyLoad = true): mixed
{
if (class_exists($class = __NAMESPACE__.'\\'.$file, false)) {
return $class::do($this, $lazyLoad);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ProjectServiceContainer extends Container
return true;
}

protected function load($file, $lazyLoad = true)
protected function load($file, $lazyLoad = true): mixed
{
if (class_exists($class = __NAMESPACE__.'\\'.$file, false)) {
return $class::do($this, $lazyLoad);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ProjectServiceContainer extends Container
return true;
}

protected function load($file, $lazyLoad = true)
protected function load($file, $lazyLoad = true): mixed
{
if (class_exists($class = __NAMESPACE__.'\\'.$file, false)) {
return $class::do($this, $lazyLoad);
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/DomCrawler/AbstractUriElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ protected function canonicalizePath(string $path): string
*
* @param \DOMElement $node A \DOMElement instance
*
* @return void
*
* @throws \LogicException If given node is not an anchor
*/
abstract protected function setNode(\DOMElement $node);
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/DomCrawler/Field/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public function isDisabled(): bool

/**
* Initializes the form field.
*
* @return void
*/
abstract protected function initialize();
}
3 changes: 3 additions & 0 deletions src/Symfony/Component/ExpressionLanguage/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public function __construct(array $functions)
$this->functions = $functions;
}

/**
* @return array
*/
public function getFunction(string $name)
{
return $this->functions[$name];
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/ExpressionLanguage/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public function evaluate(array $functions, array $values)
return $results;
}

/**
* @return array
*
* @throws \BadMethodCallException when this node cannot be transformed to an array
*/
public function toArray()
{
throw new \BadMethodCallException(sprintf('Dumping a "%s" instance is not supported yet.', static::class));
Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/ExpressionLanguage/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ private function doParse(TokenStream $stream, ?array $names = []): Node\Node
return $node;
}

/**
* @return Node\Node
*/
public function parseExpression(int $precedence = 0)
{
$expr = $this->getPrimary();
Expand All @@ -151,6 +154,9 @@ public function parseExpression(int $precedence = 0)
return $expr;
}

/**
* @return Node\Node
*/
protected function getPrimary()
{
$token = $this->stream->current;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\ExpressionLanguage;

use Symfony\Component\ExpressionLanguage\Node\Node;

/**
* Represents an already parsed expression.
*
Expand All @@ -30,6 +32,9 @@ public function __construct(string $expression, string $nodes)
$this->nodes = $nodes;
}

/**
* @return Node
*/
public function getNodes()
{
return unserialize($this->nodes);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public function hardlink(string $originFile, string|iterable $targetFiles)
/**
* @param string $linkType Name of the link type, typically 'symbolic' or 'hard'
*/
private function linkException(string $origin, string $target, string $linkType)
private function linkException(string $origin, string $target, string $linkType): never
{
if (self::$lastError) {
if ('\\' === \DIRECTORY_SEPARATOR && str_contains(self::$lastError, 'error code(1314)')) {
Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/Form/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ public function configureOptions(OptionsResolver $resolver)
{
}

/**
* @return string
*/
public function getBlockPrefix()
{
return StringUtil::fqcnToBlockPrefix(static::class) ?: '';
}

/**
* @return string|null
*/
public function getParent()
{
return FormType::class;
Expand Down
Loading

0 comments on commit 66c2147

Please sign in to comment.