8000 Add return types - batch 2/n by nicolas-grekas · Pull Request #42505 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Add return types - batch 2/n #42505

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
Aug 13, 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
4 changes: 2 additions & 2 deletions src/Symfony/Component/Asset/Context/ContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ interface ContextInterface
*
* @return string The base path
*/
public function getBasePath();
public function getBasePath(): string;

/**
* Checks whether the request is secure or not.
*
* @return bool true if the request is secure, false otherwise
*/
public function isSecure();
public function isSecure(): bool;
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Asset/Context/NullContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class NullContext implements ContextInterface
/**
* {@inheritdoc}
*/
public function getBasePath()
public function getBasePath(): string
{
return '';
}

/**
* {@inheritdoc}
*/
public function isSecure()
public function isSecure(): bool
{
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Asset/Context/RequestStackContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(RequestStack $requestStack, string $basePath = '', b
/**
* {@inheritdoc}
*/
public function getBasePath()
public function getBasePath(): string
{
if (!$request = $this->requestStack->getMainRequest()) {
return $this->basePath;
Expand All @@ -46,7 +46,7 @@ public function getBasePath()
/**
* {@inheritdoc}
*/
public function isSecure()
public function isSecure(): bool
{
if (!$request = $this->requestStack->getMainRequest()) {
return $this->secure;
Expand Down
19 changes: 5 additions & 14 deletions src/Symfony/Component/Asset/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public function __construct(VersionStrategyInterface $versionStrategy, ContextIn
/**
* {@inheritdoc}
*/
public function getVersion(string $path)
public function getVersion(string $path): string
{
return $this->versionStrategy->getVersion($path);
}

/**
* {@inheritdoc}
*/
public function getUrl(string $path)
public function getUrl(string $path): string
{
if ($this->isAbsoluteUrl($path)) {
return $path;
Expand All @@ -52,26 +52,17 @@ public function getUrl(string $path)
return $this->versionStrategy->applyVersion($path);
}

/**
* @return ContextInterface
*/
protected function getContext()
protected function getContext(): ContextInterface
{
return $this->context;
}

/**
* @return VersionStrategyInterface
*/
protected function getVersionStrategy()
protected function getVersionStrategy(): VersionStrategyInterface
{
return $this->versionStrategy;
}

/**
* @return bool
*/
protected function isAbsoluteUrl(string $url)
protected function isAbsoluteUrl(string $url): bool
{
return str_contains($url, '://') || '//' === substr($url, 0, 2);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Asset/PackageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ interface PackageInterface
*
* @return string The version string
*/
public function getVersion(string $path);
public function getVersion(string $path): string;

/**
* Returns an absolute or root-relative public path.
*
* @return string The public path
*/
public function getUrl(string $path);
public function getUrl(string $path): string;
}
6 changes: 3 additions & 3 deletions src/Symfony/Component/Asset/Packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function addPackage(string $name, PackageInterface $package)
* @throws InvalidArgumentException If there is no package by that name
* @throws LogicException If no default package is defined
*/
public function getPackage(string $name = null)
public function getPackage(string $name = null): PackageInterface
{
if (null === $name) {
if (null === $this->defaultPackage) {
Expand All @@ -82,7 +82,7 @@ public function getPackage(string $name = null)
*
* @return string The current version
*/
public function getVersion(string $path, string $packageName = null)
public function getVersion(string $path, string $packageName = null): string
{
return $this->getPackage($packageName)->getVersion($path);
}
Expand All @@ -97,7 +97,7 @@ public function getVersion(string $path, string $packageName = null)
*
* @return string A public path which takes into account the base path and URL path
*/
public function getUrl(string $path, string $packageName = null)
public function getUrl(string $path, string $packageName = null): string
{
return $this->getPackage($packageName)->getUrl($path);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Asset/PathPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(string $basePath, VersionStrategyInterface $versionS
/**
* {@inheritdoc}
*/
public function getUrl(string $path)
public function getUrl(string $path): string
{
$versionedPath = parent::getUrl($path);

Expand All @@ -66,7 +66,7 @@ public function getUrl(string $path)
*
* @return string The base path
*/
public function getBasePath()
public function getBasePath(): string
{
return $this->getContext()->getBasePath().$this->basePath;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Asset/UrlPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __construct(string|array $baseUrls, VersionStrategyInterface $ve
/**
* {@inheritdoc}
*/
public function getUrl(string $path)
public function getUrl(string $path): string
{
if ($this->isAbsoluteUrl($path)) {
return $path;
Expand Down Expand Up @@ -95,7 +95,7 @@ public function getUrl(string $path)
*
* @return string The base URL
*/
public function getBaseUrl(string $path)
public function getBaseUrl(string $path): string
{
if (1 === \count($this->baseUrls)) {
return $this->baseUrls[0];
Expand All @@ -112,7 +112,7 @@ public function getBaseUrl(string $path)
*
* @return int The base URL index for the given path
*/
protected function chooseBaseUrl(string $path)
protected function chooseBaseUrl(string $path): int
{
return (int) fmod(hexdec(substr(hash('sha256', $path), 0, 10)), \count($this->baseUrls));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class EmptyVersionStrategy implements VersionStrategyInterface
/**
* {@inheritdoc}
*/
public function getVersion(string $path)
public function getVersion(string $path): string
{
return '';
}

/**
* {@inheritdoc}
*/
public function applyVersion(string $path)
public function applyVersion(string $path): string
{
return $path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public function __construct(string $manifestPath, HttpClientInterface $httpClien
* the version is. Instead, this returns the path to the
* versioned file.
*/
public function getVersion(string $path)
public function getVersion(string $path): string
{
return $this->applyVersion($path);
}

public function applyVersion(string $path)
public function applyVersion(string $path): string
{
return $this->getManifestPath($path) ?: $path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public function __construct(string $version, string $format = null)
/**
* {@inheritdoc}
*/
public function getVersion(string $path)
public function getVersion(string $path): string
{
return $this->version;
}

/**
* {@inheritdoc}
*/
public function applyVersion(string $path)
public function applyVersion(string $path): string
{
$versionized = sprintf($this->format, ltrim($path, '/'), $this->getVersion($path));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ interface VersionStrategyInterface
*
* @return string The version string
*/
public function getVersion(string $path);
public function getVersion(string $path): string;

/**
* Applies version to the supplied path.
*
* @return string The versionized path
*/
public function applyVersion(string $path);
public function applyVersion(string $path): string;
}
4 changes: 1 addition & 3 deletions src/Symfony/Component/CssSelector/CssSelectorConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ public function __construct(bool $html = true)
*
* Optionally, a prefix can be added to the resulting XPath
* expression with the $prefix parameter.
*
* @return string
*/
public function toXPath(string $cssExpr, string $prefix = 'descendant-or-self::')
public function toXPath(string $cssExpr, string $prefix = 'descendant-or-self::'): string
{
return $this->cache[$prefix][$cssExpr] ?? $this->cache[$prefix][$cssExpr] = $this->translator->cssToXPath($cssExpr, $prefix);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,27 @@
*/
class SyntaxErrorException extends ParseException
{
/**
* @return self
*/
public static function unexpectedToken(string $expectedValue, Token $foundToken)
public static function unexpectedToken(string $expectedValue, Token $foundToken): self
{
return new self(sprintf('Expected %s, but %s found.', $expectedValue, $foundToken));
}

/**
* @return self
*/
public static function pseudoElementFound(string $pseudoElement, string $unexpectedLocation)
public static function pseudoElementFound(string $pseudoElement, string $unexpectedLocation): self
{
return new self(sprintf('Unexpected pseudo-element "::%s" found %s.', $pseudoElement, $unexpectedLocation));
}

/**
* @return self
*/
public static function unclosedString(int $position)
public static function unclosedString(int $position): self
{
return new self(sprintf('Unclosed/invalid string at %s.', $position));
}

/**
* @return self
*/
public static function nestedNot()
public static function nestedNot(): self
{
return new self('Got nested ::not().');
}

/**
* @return self
*/
public static function stringAsFunctionArgument()
public static function stringAsFunctionArgument(): self
{
return new self('String not allowed as function argument.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/CssSelector/Parser/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getOffset(string $string)
/**
* @return array|false
*/
public function findPattern(string $pattern)
public function findPattern(string $pattern): array|false
{
$source = substr($this->source, $this->position);

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/CssSelector/Parser/TokenStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TokenStream
*
* @return $this
*/
public function push(Token $token): self
public function push(Token $token): static
{
$this->tokens[] = $token;

Expand All @@ -57,7 +57,7 @@ public function push(Token $token): self
*
* @return $this
*/
public function freeze(): self
public function freeze(): static
{
return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(int $flags = 0)
/**
* @return $this
*/
public function setFlag(int $flag, bool $on): self
public function setFlag(int $flag, bool $on): static
{
if ($on && !$this->hasFlag($flag)) {
$this->flags += $flag;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/CssSelector/XPath/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function selectorToXPath(SelectorNode $selector, string $prefix = 'descen
/**
* @return $this
*/
public function registerExtension(Extension\ExtensionInterface $extension): self
public function registerExtension(Extension\ExtensionInterface $extension): static
{
$this->extensions[$extension->getName()] = $extension;

Expand Down Expand Up @@ -145,7 +145,7 @@ public function getExtension(string $name): Extension\ExtensionInterface
/**
* @return $this
*/
public function registerParserShortcut(ParserInterface $shortcut): self
public function registerParserShortcut(ParserInterface $shortcut): static
{
$this->shortcutParsers[] = $shortcut;

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/CssSelector/XPath/XPathExpr.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function addStarPrefix(): self
*
* @return $this
*/
public function join(string $combiner, self $expr): self
public function join(string $combiner, self $expr): static
{
$path = $this->__toString().$combiner;

Expand Down
Loading
0