Skip to content

Commit

Permalink
Merge pull request #78 from ohader/php84
Browse files Browse the repository at this point in the history
[TASK] Raise compatibility to PHP 7.1-8.4
  • Loading branch information
ohader authored Dec 9, 2024
2 parents a931b28 + b29a998 commit e9ddb4e
Show file tree
Hide file tree
Showing 26 changed files with 157 additions and 244 deletions.
13 changes: 2 additions & 11 deletions .github/workflows/tests-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']

steps:
- uses: actions/checkout@v4
Expand All @@ -33,17 +33,8 @@ jobs:
find . -name \*.php ! -path './vendor/*' | parallel --gnu php -d display_errors=stderr -l {} > /dev/null \;
- name: Install dependencies
if: ${{ matrix.php <= '8.1' }}
run: composer install --prefer-dist --no-progress --no-suggest

- name: Install dependencies PHP 8.2
# @todo: Needed until prophecy (req by phpunit) allows PHP 8.2, https://github.com/phpspec/prophecy/issues/556
if: ${{ matrix.php > '8.1' }}
run: composer install --prefer-dist --no-progress --no-suggest --ignore-platform-req=php+

- name: Run test suite
env:
SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT: 1
SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE: 1
run: |
vendor/bin/simple-phpunit --colors
vendor/bin/phpunit --colors
16 changes: 2 additions & 14 deletions .github/workflows/tests-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']

steps:
- uses: actions/checkout@v4
Expand All @@ -29,23 +29,11 @@ jobs:
run: composer validate

- name: Install dependencies
if: ${{ matrix.php <= '8.1' }}
# Remove xdebug dependency as performance testing is not relevant at this point.
run: |
composer remove --dev --no-update ext-xdebug
composer install --prefer-dist --no-progress --no-suggest
- name: Install dependencies PHP 8.2
# @todo: Needed until prophecy (req by phpunit) allows PHP 8.2, https://github.com/phpspec/prophecy/issues/556
if: ${{ matrix.php > '8.1' }}
# Remove xdebug dependency as performance testing is not relevant at this point.
run: |
composer remove --dev --no-update ext-xdebug
composer install --prefer-dist --no-progress --no-suggest --ignore-platform-req=php+
- name: Run test suite
env:
SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT: 1
SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE: 1
run: |
vendor/bin/simple-phpunit --colors
vendor/bin/phpunit --colors
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
"homepage": "https://typo3.org/",
"keywords": ["php", "phar", "stream-wrapper", "security"],
"require": {
"php": "^7.0 || ~8.0 || ~8.1 || ~8.2 || ~8.3",
"php": "^7.1 || ^8.0",
"ext-json": "*"
},
"require-dev": {
"ext-xdebug": "*",
"phpspec/prophecy": "^1.10",
"symfony/phpunit-bridge": "^5.1"
"phpunit/phpunit": "^7 || ^8 || ^9"
},
"suggest": {
"ext-fileinfo": "For PHP builtin file type guessing, otherwise uses internal processing"
Expand Down
3 changes: 0 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
colors="true"
processIsolation="true"
verbose="true">
<php>
<ini name="SYMFONY_PHPUNIT_REMOVE" value="symfony/yaml"/>
</php>
<testsuites>
<testsuite name="functional tests">
<directory>tests/Functional/</directory>
Expand Down
22 changes: 11 additions & 11 deletions src/Behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

class Behavior implements Assertable
{
const COMMAND_DIR_OPENDIR = 'dir_opendir';
const COMMAND_MKDIR = 'mkdir';
const COMMAND_RENAME = 'rename';
const COMMAND_RMDIR = 'rmdir';
const COMMAND_STEAM_METADATA = 'stream_metadata';
const COMMAND_STREAM_OPEN = 'stream_open';
const COMMAND_UNLINK = 'unlink';
const COMMAND_URL_STAT = 'url_stat';
public const COMMAND_DIR_OPENDIR = 'dir_opendir';
public const COMMAND_MKDIR = 'mkdir';
public const COMMAND_RENAME = 'rename';
public const COMMAND_RMDIR = 'rmdir';
public const COMMAND_STEAM_METADATA = 'stream_metadata';
public const COMMAND_STREAM_OPEN = 'stream_open';
public const COMMAND_UNLINK = 'unlink';
public const COMMAND_URL_STAT = 'url_stat';

/**
* @var string[]
Expand Down 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
11 changes: 2 additions & 9 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;
public function collect(PharInvocation $invocation, ?int $flags = null): bool;

/**
* @param bool $reverse
* @return null|PharInvocation
*/
public function findByCallback(callable $callback, $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
13 changes: 5 additions & 8 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class Manager

public static function initialize(
Behavior $behaviour,
Resolvable $resolver = null,
Collectable $collection = null
?Resolvable $resolver = null,
?Collectable $collection = null
): self {
if (self::$instance === null) {
self::$instance = new self($behaviour, $resolver, $collection);
Expand Down Expand Up @@ -75,8 +75,8 @@ public static function destroy(): bool

private function __construct(
Behavior $behaviour,
Resolvable $resolver = null,
Collectable $collection = null
?Resolvable $resolver = null,
?Collectable $collection = null
) {
$this->collection = $collection ?? new PharInvocationCollection();
$this->resolver = $resolver ?? new PharInvocationResolver();
Expand All @@ -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
16 changes: 8 additions & 8 deletions src/PharStreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PharStreamWrapper
* Internal stream constants that are not exposed to PHP, but used...
* @see https://github.com/php/php-src/blob/e17fc0d73c611ad0207cac8a4a01ded38251a7dc/main/php_streams.h
*/
const STREAM_OPEN_FOR_INCLUDE = 128;
public const STREAM_OPEN_FOR_INCLUDE = 128;

/**
* @var resource
Expand Down 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 @@ -204,7 +204,7 @@ public function stream_open(
string $path,
string $mode,
int $options,
string &$opened_path = null
?string &$opened_path = null
): bool {
$this->assert($path, Behavior::COMMAND_STREAM_OPEN);
$arguments = [$path, $mode, (bool) ($options & STREAM_USE_PATH)];
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
Loading

0 comments on commit e9ddb4e

Please sign in to comment.