Skip to content
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

Support PHP 8.2 #15

Merged
merged 5 commits into from
Jan 16, 2024
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
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:
tag: << parameters.version >>
parameters:
version:
default: "7.4"
default: "8.2"
description: The `cimg/php` Docker image version tag.
type: string
install-flags:
Expand All @@ -154,7 +154,7 @@ jobs:
- when:
condition:
and:
- equal: [ "8.1", <<parameters.version>> ]
- equal: [ "8.2", <<parameters.version>> ]
- equal: [ "", <<parameters.install-flags>> ]
steps:
- run-phpunit-tests:
Expand All @@ -164,7 +164,7 @@ jobs:
condition:
not:
and:
- equal: [ "8.1", <<parameters.version>> ]
- equal: [ "8.2", <<parameters.version>> ]
- equal: [ "", <<parameters.install-flags>> ]
steps:
- run-phpunit-tests:
Expand All @@ -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"]
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"require-dev": {
"phpunit/phpunit": "^9.6",
"rector/rector": "^0.15.17",
"squizlabs/php_codesniffer": "^3.7"
"squizlabs/php_codesniffer": "^3.7",
"symfony/phpunit-bridge": "^7.0"
},
"autoload": {
"psr-4": {
Expand Down
9 changes: 8 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
<directory suffix=".php">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 suffix="Test.php">test</directory>
<directory>test</directory>
</testsuite>
</testsuites>
</phpunit>
36 changes: 30 additions & 6 deletions rector.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,50 @@
<?php

/**
* Generic PHP 7.4 update.
*/

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\ArrowFunction\AddArrowFunctionReturnTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ArrayShapeFromConstantArrayReturnRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector;

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,
AddArrowFunctionReturnTypeRector::class,
ReturnTypeFromStrictTypedCallRector::class,
]);

$rectorConfig->importNames();
$rectorConfig->importShortClasses(false);
};
2 changes: 1 addition & 1 deletion src/Mock/IdGenerator/Sequential.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Sequential implements IdGeneratorInterface
{
private int $id = 0;
public function generate()
public function generate(): int
{
$this->id++;
return $this->id;
Expand Down
14 changes: 7 additions & 7 deletions src/Mock/Storage/JsonObjectMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,27 @@ public function store($data, string $id = null): string
return parent::store($data, $id);
}

public function conditionByIsEqualTo(string $property, string $value)
public function conditionByIsEqualTo(string $property, string $value): void
{
$this->conditions[$property][] = $value;
}

public function limitTo(int $number_of_items)
public function limitTo(int $number_of_items): void
{
$this->limit = $number_of_items;
}

public function offsetBy(int $offset)
public function offsetBy(int $offset): void
{
$this->offset = $offset;
}

public function sortByAscending(string $property)
public function sortByAscending(string $property): void
{
$this->sorts['ascend'][] = $property;
}

public function sortByDescending(string $property)
public function sortByDescending(string $property): void
{
$this->sorts['descend'][] = $property;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ private function applyFilters(array $results)
return $results;
}

private function resetFilters()
private function resetFilters(): void
{
$this->offset = 0;
$this->limit = 0;
Expand All @@ -124,7 +124,7 @@ private function validate(string $data)
}
}

private function compare($a, $b, $property)
private function compare($a, $b, $property): int
{
$a = json_decode($a);
$b = json_decode($b);
Expand Down
30 changes: 15 additions & 15 deletions src/StorerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

interface StorerInterface
{
/**
* Store.
*
* @param string|HydratableInterface $data
* The data to be stored.
* @param string $id
* The identifier for the data. If the act of storing generates the
* id, there is no need to pass one.
*
* @return string
* The identifier.
*
* @throws \Exception
* Issues storing the data.
*/
/**
* Store.
*
* @param string|HydratableInterface $data
* The data to be stored.
* @param string|null $id
* The identifier for the data. If the act of storing generates the
* id, there is no need to pass one.
*
* @return string
* The identifier.
*
* @throws \Exception
* Issues storing the data.
*/
public function store($data, string $id = null): string;
}
2 changes: 1 addition & 1 deletion test/Mock/IdGenerator/SequentialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class SequentialTest extends TestCase
{
public function test()
public function test(): void
{
$generator = new Sequential();
$id1 = $generator->generate();
Expand Down
15 changes: 9 additions & 6 deletions test/Mock/Storage/MemoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

namespace ContractsTest;

use PHPUnit\Framework\TestCase;
use Contracts\Mock\Storage\Memory;
use Contracts\Mock\Storage\JsonObjectMemory;
use Contracts\Mock\Storage\MemoryFactory;

class MemoryTest extends \PHPUnit\Framework\TestCase
class MemoryTest extends TestCase
{
public function testStorageMemoryException()
public function testStorageMemoryException(): void
{
$factory = new MemoryFactory();
$store = $factory->getInstance("store");
Expand All @@ -17,9 +20,9 @@ public function testStorageMemoryException()
$store->store("Data");
}

public function testStorageMemory()
public function testStorageMemory(): void
{
$store = new \Contracts\Mock\Storage\Memory();
$store = new Memory();

$store->store("Data", "1");
$this->assertEquals("Data", $store->retrieve("1"));
Expand All @@ -37,7 +40,7 @@ public function testStorageMemory()
$this->assertNull($store->retrieve("1"));
}

public function testStorageJsonObjectMemory()
public function testStorageJsonObjectMemory(): void
{
$objects = [];
$objects[] = <<<JSON
Expand Down Expand Up @@ -68,7 +71,7 @@ public function testStorageJsonObjectMemory()
}
JSON;

$store = new \Contracts\Mock\Storage\JsonObjectMemory();
$store = new JsonObjectMemory();


foreach ($objects as $index => $object) {
Expand Down