Skip to content

Commit

Permalink
[!!!][TASK] Apply nullable and void types were applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
ohader committed Dec 9, 2024
1 parent 9dd6e2e commit b29a998
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 87 deletions.
6 changes: 3 additions & 3 deletions src/Behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function assert(string $path, string $command): bool
return $this->assertions[$command]->assert($path, $command);
}

private function assertCommands(array $commands)
private function assertCommands(array $commands): void
{
$unknownCommands = array_diff($commands, $this->availableCommands);
if ($unknownCommands === []) {
Expand All @@ -77,7 +77,7 @@ private function assertCommands(array $commands)
);
}

private function assertCommand(string $command)
private function assertCommand(string $command): void
{
if (in_array($command, $this->availableCommands, true)) {
return;
Expand All @@ -91,7 +91,7 @@ private function assertCommand(string $command)
);
}

private function assertAssertionCompleteness()
private function assertAssertionCompleteness(): void
{
$undefinedAssertions = array_diff(
$this->availableCommands,
Expand Down
9 changes: 1 addition & 8 deletions src/Collectable.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ interface Collectable
{
public function has(PharInvocation $invocation): bool;

/**
* @param int|null $flags
*/
public function collect(PharInvocation $invocation, ?int $flags = null): bool;

/**
* @param bool $reverse
* @return null|PharInvocation
*/
public function findByCallback(callable $callback, bool $reverse = false);
public function findByCallback(callable $callback, bool $reverse = false): ?PharInvocation;
}
6 changes: 2 additions & 4 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Helper
*
* @see https://bugs.php.net/bug.php?id=66569
*/
public static function resetOpCache()
public static function resetOpCache(): void
{
if (function_exists('opcache_reset')
&& function_exists('opcache_get_status')
Expand All @@ -41,10 +41,8 @@ public static function resetOpCache()
* Determines base file that can be accessed using the regular file system.
* For e.g. "phar:///home/user/bundle.phar/content.txt" that would result
* into "/home/user/bundle.phar".
*
* @return string|null
*/
public static function determineBaseFile(string $path)
public static function determineBaseFile(string $path): ?string
{
$parts = explode('/', static::normalizePath($path));

Expand Down
2 changes: 1 addition & 1 deletion src/Interceptor/ConjunctionInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function assert(string $path, string $command): bool
/**
* @param Assertable[] $assertions
*/
private function assertAssertions(array $assertions)
private function assertAssertions(array $assertions): void
{
foreach ($assertions as $assertion) {
if (!$assertion instanceof Assertable) {
Expand Down
5 changes: 1 addition & 4 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ public function assert(string $path, string $command): bool
return $this->behavior->assert($path, $command);
}

/**
* @return PharInvocation|null
*/
public function resolve(string $path, ?int $flags = null)
public function resolve(string $path, ?int $flags = null): ?PharInvocation
{
return $this->resolver->resolve($path, $flags);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Phar/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,7 @@ private function determineFileTypeByHeader(): string
return '';
}

/**
* @return int|null
*/
private function resolveManifestLength(string $content)
private function resolveManifestLength(string $content): ?int
{
if (strlen($content) < 4) {
return null;
Expand Down
5 changes: 1 addition & 4 deletions src/Phar/Stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ public static function fromContent(string $content): self
*/
private $mappedAlias = '';

/**
* @return null|string
*/
public function getContent()
public function getContent(): ?string
{
return $this->content;
}
Expand Down
12 changes: 6 additions & 6 deletions src/PharStreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ public function rmdir(string $path, int $options): bool
);
}

public function stream_cast(int $cast_as)
public function stream_cast(int $cast_as): void
{
throw new Exception(
'Method stream_select() cannot be used',
1530103999
);
}

public function stream_close()
public function stream_close(): void
{
$this->invokeInternalStreamWrapper(
'fclose',
Expand Down Expand Up @@ -330,7 +330,7 @@ public function url_stat(string $path, int $flags)
return $this->invokeInternalStreamWrapper($functionName, $path);
}

protected function assert(string $path, string $command)
protected function assert(string $path, string $command): void
{
if (Manager::instance()->assert($path, $command) === true) {
$this->collectInvocation($path);
Expand All @@ -347,7 +347,7 @@ protected function assert(string $path, string $command)
);
}

protected function collectInvocation(string $path)
protected function collectInvocation(string $path): void
{
if (isset($this->invocation)) {
return;
Expand Down Expand Up @@ -403,7 +403,7 @@ private function invokeInternalStreamWrapper(string $functionName, ...$arguments
return $result;
}

private function restoreInternalSteamWrapper()
private function restoreInternalSteamWrapper(): void
{
if (PHP_VERSION_ID < 70324
|| PHP_VERSION_ID >= 70400 && PHP_VERSION_ID < 70412) {
Expand All @@ -416,7 +416,7 @@ private function restoreInternalSteamWrapper()
}
}

private function registerStreamWrapper()
private function registerStreamWrapper(): void
{
stream_wrapper_unregister('phar');
stream_wrapper_register('phar', static::class);
Expand Down
7 changes: 1 addition & 6 deletions src/Resolvable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,5 @@

interface Resolvable
{
/**
* @param string $path
* @param null|int $flags
* @return null|PharInvocation
*/
public function resolve(string $path, ?int $flags = null);
public function resolve(string $path, ?int $flags = null): ?PharInvocation;
}
6 changes: 2 additions & 4 deletions src/Resolver/PharInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,12 @@ public function isConfirmed(): bool
return $this->confirmed;
}

public function confirm()
public function confirm(): void
{
$this->confirmed = true;
}

/**
* @param string $name
* @return mixed|null
*/
public function getVariable(string $name)
Expand All @@ -103,10 +102,9 @@ public function getVariable(string $name)
}

/**
* @param string $name
* @param mixed $value
*/
public function setVariable(string $name, $value)
public function setVariable(string $name, $value): void
{
$this->variables[$name] = $value;
}
Expand Down
10 changes: 2 additions & 8 deletions src/Resolver/PharInvocationCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ public function collect(PharInvocation $invocation, ?int $flags = null): bool
return true;
}

/**
* @param callable $callback
* @param bool $reverse
* @return null|PharInvocation
*/
public function findByCallback(callable $callback, bool $reverse = false)
public function findByCallback(callable $callback, bool $reverse = false): ?PharInvocation
{
foreach ($this->getInvocations($reverse) as $invocation) {
if (call_user_func($callback, $invocation) === true) {
Expand Down Expand Up @@ -117,10 +112,9 @@ function (PharInvocation $candidate) use ($invocation) {
/**
* Triggers warning for invocations with same alias and same confirmation state.
*
* @param PharInvocation $invocation
* @see \TYPO3\PharStreamWrapper\PharStreamWrapper::collectInvocation()
*/
private function triggerDuplicateAliasWarning(PharInvocation $invocation)
private function triggerDuplicateAliasWarning(PharInvocation $invocation): void
{
$sameAliasInvocation = $this->findByCallback(
function (PharInvocation $candidate) use ($invocation) {
Expand Down
40 changes: 7 additions & 33 deletions src/Resolver/PharInvocationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,8 @@ class PharInvocationResolver implements Resolvable
* one $baseName is referring to multiple aliases.
* @see https://secure.php.net/manual/en/phar.setalias.php
* @see https://secure.php.net/manual/en/phar.mapphar.php
*
* @param string $path
* @param int|null $flags
* @return null|PharInvocation
*/
public function resolve(string $path, ?int $flags = null)
public function resolve(string $path, ?int $flags = null): ?PharInvocation
{
$hasPharPrefix = Helper::hasPharPrefix($path);
$flags = $flags ?? static::RESOLVE_REALPATH | static::RESOLVE_ALIAS;
Expand Down Expand Up @@ -107,12 +103,7 @@ private function retrieveInvocation(string $baseName, int $flags): PharInvocatio
return $invocation;
}

/**
* @param string $path
* @param int $flags
* @return null|string
*/
private function resolveBaseName(string $path, int $flags)
private function resolveBaseName(string $path, int $flags): ?string
{
$baseName = $this->findInBaseNames($path);
if ($baseName !== null) {
Expand Down Expand Up @@ -162,21 +153,13 @@ private function resolveBaseName(string $path, int $flags)
return null;
}

/**
* @param string $path
* @return null|string
*/
private function resolvePossibleAlias(string $path)
private function resolvePossibleAlias(string $path): ?string
{
$normalizedPath = Helper::normalizePath($path);
return strstr($normalizedPath, '/', true) ?: null;
}

/**
* @param string $baseName
* @return null|PharInvocation
*/
private function findByBaseName(string $baseName)
private function findByBaseName(string $baseName): ?PharInvocation
{
return Manager::instance()->getCollection()->findByCallback(
function (PharInvocation $candidate) use ($baseName) {
Expand All @@ -186,11 +169,7 @@ function (PharInvocation $candidate) use ($baseName) {
);
}

/**
* @param string $path
* @return null|string
*/
private function findInBaseNames(string $path)
private function findInBaseNames(string $path): ?string
{
// return directly if the resolved base name was submitted
if (in_array($path, $this->baseNames, true)) {
Expand All @@ -210,10 +189,7 @@ private function findInBaseNames(string $path)
return null;
}

/**
* @param string $baseName
*/
private function addBaseName(string $baseName)
private function addBaseName(string $baseName): void
{
if (isset($this->baseNames[$baseName])) {
return;
Expand All @@ -226,11 +202,9 @@ private function addBaseName(string $baseName)
/**
* Finds confirmed(!) invocations by alias.
*
* @param string $path
* @return null|PharInvocation
* @see \TYPO3\PharStreamWrapper\PharStreamWrapper::collectInvocation()
*/
private function findByAlias(string $path)
private function findByAlias(string $path): ?PharInvocation
{
$possibleAlias = $this->resolvePossibleAlias($path);
if ($possibleAlias === null) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Interceptor/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function directoryActionAllowsInvocationDataProvider(): array
* @test
* @dataProvider directoryActionAllowsInvocationDataProvider
*/
public function directoryOpenAllowsInvocation(string $path)
public function directoryOpenAllowsInvocation(string $path): void
{
$handle = opendir('phar://' . $path);
self::assertIsResource($handle);
Expand Down Expand Up @@ -155,7 +155,7 @@ public function directoryReadAllowsInvocation(string $path, array $expectation):
* @test
* @dataProvider directoryActionAllowsInvocationDataProvider
*/
public function directoryCloseAllowsInvocation(string $path)
public function directoryCloseAllowsInvocation(string $path): void
{
$handle = opendir('phar://' . $path);
closedir($handle);
Expand Down

0 comments on commit b29a998

Please sign in to comment.