Skip to content

Commit

Permalink
Add support for PHP 8.2 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-m authored Jan 22, 2024
1 parent d87fdb6 commit 70ad5cc
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ workflows:
- matrix-conditions:
matrix:
parameters:
version: ["7.4", "8.0", "8.1"]
version: ["7.4", "8.0", "8.1", "8.2"]
install-flags: ["", "--prefer-lowest"]
15 changes: 15 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Exclude build/test files from archive
/.circleci export-ignore
/test export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/Doxyfile export-ignore
/doxygen.tag.xml export-ignore
/phpcs.xml export-ignore
/phpunit.xml export-ignore
/procrastinator.tag.xml export-ignore
/rector.php export-ignore

# Configure diff output for .php and .phar files.
*.php diff=php
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
}
],
"require": {
"php": ">=7.4 <8.2",
"php": ">=7.4 <8.3",
"ext-curl": "*",
"getdkan/procrastinator": "^5.0.0",
"guzzlehttp/guzzle": "^6.5.8 || ^7.4.5"
},
"require-dev": {
"getdkan/mock-chain": "^1.3.5",
"mikey179/vfsstream": "^1.6.10",
"getdkan/mock-chain": "^1.3.6",
"mikey179/vfsstream": "^1.6.11",
"phpunit/phpunit": "^9.6",
"rector/rector": "^0.15.18",
"squizlabs/php_codesniffer": "^3.7"
"squizlabs/php_codesniffer": "^3.7",
"symfony/phpunit-bridge": "^7.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
35 changes: 20 additions & 15 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
colors="true"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="all">
<directory phpVersion="7.4" phpVersionOperator=">=">test</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
colors="true">
<coverage processUncoveredFiles="true">
<include>
<directory>src</directory>
</include>
</coverage>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
<php>
<!-- Don't fail for external dependencies. -->
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
</php>
<testsuites>
<testsuite name="all">
<directory>test</directory>
</testsuite>
</testsuites>
</phpunit>
28 changes: 26 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,44 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Core\ValueObject\PhpVersion;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\ArrayShapeFromConstantArrayReturnRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/test',
]);

// Our base version of PHP.
$rectorConfig->phpVersion(PhpVersion::PHP_74);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74,
SetList::PHP_82,
// Please no dead code or unneeded variables.
SetList::DEAD_CODE,
// Try to figure out type hints.
SetList::TYPE_DECLARATION,
]);

$rectorConfig->skip([
// Don't throw errors on JSON parse problems. Yet.
// @todo Throw errors and deal with them appropriately.
JsonThrowOnErrorRector::class,
// We like our tags. Please don't remove them.
RemoveUselessParamTagRector::class,
RemoveUselessReturnTagRector::class,
RemoveUselessVarTagRector::class,
ArrayShapeFromConstantArrayReturnRector::class,
AddMethodCallBasedStrictParamTypeRector::class,
]);

$rectorConfig->importNames();
$rectorConfig->importShortClasses(false);
};
8 changes: 4 additions & 4 deletions src/FileFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FileFetcher extends AbstractPersistentJob
*
* Stored here so that we don't have to recompute it.
*
* @var \FileFetcher\Processor\ProcessorInterface|null
* @var ProcessorInterface|null
*/
private ?ProcessorInterface $processor = null;

Expand Down Expand Up @@ -130,7 +130,7 @@ protected function getProcessors(): array
return $processors;
}

private static function getDefaultProcessors()
private static function getDefaultProcessors(): array
{
return [
Local::class => new Local(),
Expand All @@ -141,7 +141,7 @@ private static function getDefaultProcessors()
/**
* Get the processor used by this file fetcher object.
*
* @return \FileFetcher\Processor\ProcessorInterface|null
* @return ProcessorInterface|null
* A processor object, determined by configuration, or NULL if none is
* suitable.
*/
Expand Down Expand Up @@ -248,7 +248,7 @@ private function unsetDuplicateCustomProcessorClasses(array $processors):void
* @param $processorClass
* Processor class name.
*
* @return \FileFetcher\Processor\ProcessorInterface|null
* @return ProcessorInterface|null
* An instance of the processor class. If the given class name does not
* exist, or does not implement ProcessorInterface, then null is
* returned.
Expand Down
28 changes: 14 additions & 14 deletions test/FileFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class FileFetcherTest extends TestCase
{

public function testCopyALocalFile()
public function testCopyALocalFile(): void
{
$config = ["filePath" => __DIR__ . '/files/tiny.csv'];
$fetcher = FileFetcher::get("1", new Memory(), $config);
Expand All @@ -34,7 +34,7 @@ public function testCopyALocalFile()
);
}

public function testKeepOriginalFilename()
public function testKeepOriginalFilename(): void
{
$fetcher = FileFetcher::get(
"2",
Expand All @@ -50,12 +50,12 @@ public function testKeepOriginalFilename()
$state = $fetcher->getState();

$this->assertEquals(
basename($state['source']),
basename($state['destination'])
basename((string) $state['source']),
basename((string) $state['destination'])
);
}

public function testConfigValidationErrorConfigurationMissing()
public function testConfigValidationErrorConfigurationMissing(): void
{
$this->expectExceptionMessage('Constructor missing expected config filePath.');
FileFetcher::get(
Expand All @@ -64,7 +64,7 @@ public function testConfigValidationErrorConfigurationMissing()
);
}

public function testConfigValidationErrorMissingFilePath()
public function testConfigValidationErrorMissingFilePath(): void
{
$this->expectExceptionMessage('Constructor missing expected config filePath.');
FileFetcher::get(
Expand All @@ -74,9 +74,9 @@ public function testConfigValidationErrorMissingFilePath()
);
}

public function testCustomProcessorsValidationIsNotAnArray()
public function testCustomProcessorsValidationIsNotAnArray(): void
{
$fetcher = FileFetcher::get(
FileFetcher::get(
"2",
new Memory(),
[
Expand All @@ -88,9 +88,9 @@ public function testCustomProcessorsValidationIsNotAnArray()
$this->assertTrue(true);
}

public function testCustomProcessorsValidationNotAClass()
public function testCustomProcessorsValidationNotAClass(): void
{
$fetcher = FileFetcher::get(
FileFetcher::get(
"2",
new Memory(),
[
Expand All @@ -102,9 +102,9 @@ public function testCustomProcessorsValidationNotAClass()
$this->assertTrue(true);
}

public function testCustomProcessorsValidationImproperClass()
public function testCustomProcessorsValidationImproperClass(): void
{
$fetcher = FileFetcher::get(
FileFetcher::get(
"2",
new Memory(),
[
Expand All @@ -116,7 +116,7 @@ public function testCustomProcessorsValidationImproperClass()
$this->assertTrue(true);
}

public function testSwitchProcessor()
public function testSwitchProcessor(): void
{
$file_path = __DIR__ . '/files/tiny.csv';
$temporary_directory = '/temp/foo';
Expand Down Expand Up @@ -191,7 +191,7 @@ public function testSwitchProcessor()
/**
* @covers ::addProcessors
*/
public function testAddProcessors()
public function testAddProcessors(): void
{
$file_path = __DIR__ . '/files/tiny.csv';
$temporary_directory = '/temp/foo';
Expand Down
3 changes: 3 additions & 0 deletions test/Mock/FakeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public function setupState(array $state): array
return $state;
}

/**
* @return array{state: mixed[], result: Result}
*/
public function copy(array $state, Result $result, int $timeLimit = PHP_INT_MAX): array
{
return ['state' => $state, 'result' => $result];
Expand Down
5 changes: 2 additions & 3 deletions test/Mock/FakeRemote.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ protected function getClient(): Client
return new Client(['handler' => $handlerStack]);
}

private function getMockHandler()
private function getMockHandler(): MockHandler
{
$mock = new MockHandler([
return new MockHandler([
new Response(200, ['X-Foo' => 'Bar'], 'Hello, World'),
]);
return $mock;
}

protected function getFileSize($path): int
Expand Down
4 changes: 2 additions & 2 deletions test/Processor/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class LocalTest extends TestCase
{

public function provideSource()
public function provideSource(): array
{
return [
'any-normal-file' => ['blah'],
Expand All @@ -24,7 +24,7 @@ public function provideSource()
* @covers ::isServerCompatible
* @dataProvider provideSource
*/
public function test($source)
public function test(string $source): void
{
$processor = new Local();
$state = ['source' => $source];
Expand Down
6 changes: 3 additions & 3 deletions test/Processor/RemoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class RemoteTest extends TestCase
{

public function testCopyAFileWithRemoteProcessor()
public function testCopyAFileWithRemoteProcessor(): void
{
$config = [
"filePath" => 'http://notreal.blah/notacsv.csv',
Expand Down Expand Up @@ -51,13 +51,13 @@ public function provideIsServerCompatible(): array
*
* @dataProvider provideIsServerCompatible
*/
public function testIsServerCompatible($expected, $source)
public function testIsServerCompatible(bool $expected, string $source): void
{
$processor = new Remote();
$this->assertSame($expected, $processor->isServerCompatible(['source' => $source]));
}

public function testCopyException()
public function testCopyException(): void
{
// Ensure the status object contains the message from an exception.
// We'll use vfsstream to mock a file system with no permissions to
Expand Down

0 comments on commit 70ad5cc

Please sign in to comment.