Skip to content

Commit

Permalink
[TASK] Clean up code
Browse files Browse the repository at this point in the history
* adjust method/function signatures were applicable
* remove superfluous phpdoc comments
* simplify conditions
  • Loading branch information
ohader committed Dec 9, 2024
1 parent e23a301 commit a931b28
Show file tree
Hide file tree
Showing 26 changed files with 64 additions and 459 deletions.
5 changes: 0 additions & 5 deletions src/Assertable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,5 @@

interface Assertable
{
/**
* @param string $path
* @param string $command
* @return bool
*/
public function assert(string $path, string $command): bool;
}
17 changes: 2 additions & 15 deletions src/Behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ class Behavior implements Assertable
*/
private $assertions;

/**
* @param Assertable $assertable
* @param string ...$commands
* @return static
*/
public function withAssertion(Assertable $assertable, string ...$commands): self
{
$this->assertCommands($commands);
Expand All @@ -59,11 +54,6 @@ public function withAssertion(Assertable $assertable, string ...$commands): self
return $target;
}

/**
* @param string $path
* @param string $command
* @return bool
*/
public function assert(string $path, string $command): bool
{
$this->assertCommand($command);
Expand All @@ -72,13 +62,10 @@ public function assert(string $path, string $command): bool
return $this->assertions[$command]->assert($path, $command);
}

/**
* @param array $commands
*/
private function assertCommands(array $commands)
{
$unknownCommands = array_diff($commands, $this->availableCommands);
if (empty($unknownCommands)) {
if ($unknownCommands === []) {
return;
}
throw new \LogicException(
Expand Down Expand Up @@ -110,7 +97,7 @@ private function assertAssertionCompleteness()
$this->availableCommands,
array_keys($this->assertions)
);
if (empty($undefinedAssertions)) {
if ($undefinedAssertions === []) {
return;
}
throw new \LogicException(
Expand Down
7 changes: 0 additions & 7 deletions src/Collectable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@

interface Collectable
{
/**
* @param PharInvocation $invocation
* @return bool
*/
public function has(PharInvocation $invocation): bool;

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

/**
* @param callable $callback
* @param bool $reverse
* @return null|PharInvocation
*/
Expand Down
25 changes: 3 additions & 22 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public static function resetOpCache()
* For e.g. "phar:///home/user/bundle.phar/content.txt" that would result
* into "/home/user/bundle.phar".
*
* @param string $path
* @return string|null
*/
public static function determineBaseFile(string $path)
Expand All @@ -60,19 +59,11 @@ public static function determineBaseFile(string $path)
return null;
}

/**
* @param string $path
* @return bool
*/
public static function hasPharPrefix(string $path): bool
{
return stripos($path, 'phar://') === 0;
}

/**
* @param string $path
* @return string
*/
public static function removePharPrefix(string $path): string
{
$path = trim($path);
Expand All @@ -84,10 +75,7 @@ public static function removePharPrefix(string $path): string

/**
* Normalizes a path, removes phar:// prefix, fixes Windows directory
* separators. Result is without trailing slash.
*
* @param string $path
* @return string
* separators. The result is without a trailing slash.
*/
public static function normalizePath(string $path): string
{
Expand All @@ -101,9 +89,6 @@ public static function normalizePath(string $path): string

/**
* Fixes a path for windows-backslashes and reduces double-slashes to single slashes
*
* @param string $path File path to process
* @return string
*/
public static function normalizeWindowsPath(string $path): string
{
Expand All @@ -113,10 +98,9 @@ public static function normalizeWindowsPath(string $path): string
/**
* Resolves all dots, slashes and removes spaces after or before a path...
*
* @param string $path Input string
* @return string Canonical path, always without trailing slash
*/
private static function getCanonicalPath($path): string
private static function getCanonicalPath(string $path): string
{
$path = static::normalizeWindowsPath($path);

Expand Down Expand Up @@ -173,11 +157,8 @@ private static function getCanonicalPath($path): string
/**
* Checks if the $path is absolute or relative (detecting either '/' or
* 'x:/' as first part of string) and returns TRUE if so.
*
* @param string $path File path to evaluate
* @return bool
*/
private static function isAbsolutePath($path): bool
private static function isAbsolutePath(string $path): bool
{
// Path starting with a / is always absolute, on every system
// On Windows also a path starting with a drive letter is absolute: X:/
Expand Down
11 changes: 3 additions & 8 deletions src/Interceptor/ConjunctionInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class ConjunctionInterceptor implements Assertable
*/
private $assertions;

/**
* @param Assertable[] $assertions
*/
public function __construct(array $assertions)
{
$this->assertAssertions($assertions);
Expand All @@ -31,9 +34,6 @@ public function __construct(array $assertions)
/**
* Executes assertions based on all contained assertions.
*
* @param string $path
* @param string $command
* @return bool
* @throws Exception
*/
public function assert(string $path, string $command): bool
Expand Down Expand Up @@ -68,11 +68,6 @@ private function assertAssertions(array $assertions)
}
}

/**
* @param string $path
* @param string $command
* @return bool
*/
private function invokeAssertions(string $path, string $command): bool
{
try {
Expand Down
7 changes: 0 additions & 7 deletions src/Interceptor/PharExtensionInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ class PharExtensionInterceptor implements Assertable
/**
* Determines whether the base file name has a ".phar" suffix.
*
* @param string $path
* @param string $command
* @return bool
* @throws Exception
*/
public function assert(string $path, string $command): bool
Expand All @@ -40,10 +37,6 @@ public function assert(string $path, string $command): bool
);
}

/**
* @param string $path
* @return bool
*/
private function baseFileContainsPharExtension(string $path): bool
{
$invocation = Manager::instance()->resolve($path);
Expand Down
7 changes: 0 additions & 7 deletions src/Interceptor/PharMetaDataInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class PharMetaDataInterceptor implements Assertable
* Determines whether the according Phar archive contains
* (potential insecure) serialized objects.
*
* @param string $path
* @param string $command
* @return bool
* @throws Exception
*/
public function assert(string $path, string $command): bool
Expand All @@ -47,10 +44,6 @@ public function assert(string $path, string $command): bool
);
}

/**
* @param string $path
* @return bool
*/
private function baseFileDoesNotHaveMetaDataIssues(string $path): bool
{
$invocation = Manager::instance()->resolve($path);
Expand Down
27 changes: 0 additions & 27 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ class Manager
*/
private $collection;

/**
* @param Behavior $behaviour
* @param Resolvable $resolver
* @param Collectable $collection
* @return self
*/
public static function initialize(
Behavior $behaviour,
Resolvable $resolver = null,
Expand All @@ -59,9 +53,6 @@ public static function initialize(
);
}

/**
* @return self
*/
public static function instance(): self
{
if (self::$instance !== null) {
Expand All @@ -73,9 +64,6 @@ public static function instance(): self
);
}

/**
* @return bool
*/
public static function destroy(): bool
{
if (self::$instance === null) {
Expand All @@ -85,11 +73,6 @@ public static function destroy(): bool
return true;
}

/**
* @param Behavior $behaviour
* @param Resolvable $resolver
* @param Collectable $collection
*/
private function __construct(
Behavior $behaviour,
Resolvable $resolver = null,
Expand All @@ -100,29 +83,19 @@ private function __construct(
$this->behavior = $behaviour;
}

/**
* @param string $path
* @param string $command
* @return bool
*/
public function assert(string $path, string $command): bool
{
return $this->behavior->assert($path, $command);
}

/**
* @param string $path
* @param null|int $flags
* @return PharInvocation|null
*/
public function resolve(string $path, int $flags = null)
{
return $this->resolver->resolve($path, $flags);
}

/**
* @return Collectable
*/
public function getCollection(): Collectable
{
return $this->collection;
Expand Down
13 changes: 0 additions & 13 deletions src/Phar/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,22 @@ class Container
*/
private $manifest;

/**
* @param Stub $stub
* @param Manifest $manifest
*/
public function __construct(Stub $stub, Manifest $manifest)
{
$this->stub = $stub;
$this->manifest = $manifest;
}

/**
* @return Stub
*/
public function getStub(): Stub
{
return $this->stub;
}

/**
* @return Manifest
*/
public function getManifest(): Manifest
{
return $this->manifest;
}

/**
* @return string
*/
public function getAlias(): string
{
return $this->manifest->getAlias() ?: $this->stub->getMappedAlias();
Expand Down
Loading

0 comments on commit a931b28

Please sign in to comment.