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 only PHP >= 8.1 #134

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [7.4, 8.0, 8.1]
php: [8.1, 8.2, 8.3]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ help:
| xargs -I _ sh -c 'printf "%-40s " _; make _ -nB | (grep -i "^# Help:" || echo "") | tail -1 | sed "s/^# Help: //g"'


.PHONY: run run-php7.4 run-php8.0 run-php8.1 run-php8.2
run-php7.4:
@# Help: It creates and runs a docker image with PHP 7.4
docker-compose run --rm php74 bash -c "rm composer.lock || true; composer install --no-interaction; bash"
run-php8.0:
@# Help: It creates and runs a docker image with PHP 8.0
docker-compose run --rm php80 bash -c "rm composer.lock || true; composer install --no-interaction; bash"
.PHONY: run run-php8.1 run-php8.2
run-php8.1:
@# Help: It creates and runs a docker image with PHP 8.1
docker-compose run --rm php81 bash -c "rm composer.lock || true; composer install --no-interaction; bash"
run-php8.2:
@# Help: It creates and runs a docker image with PHP 8.2
docker-compose run --rm php82 bash -c "rm composer.lock || true; composer install --no-interaction; bash"
run: run-php7.4
run-php8.3:
@# Help: It creates and runs a docker image with PHP 8.3
docker-compose run --rm php83 bash -c "rm composer.lock || true; composer install --no-interaction; bash"
run: run-php8.1
@# Help: It creates and runs a docker image with the lowest supported PHP version

.PHONY: psalm psalm-update-baseline
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
},
"require": {
"php": "^7.4 | ^8.0"
"php": "^8.1"
},
"prefer-stable": true,
"archive": {
Expand Down
18 changes: 6 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
version: "3.8"

services:
php74: &base
php81: &base
build:
context: docker/
args:
PHP_IMAGE: php:7.4
PHP_IMAGE: php:8.1
XDEBUG: xdebug-3.1.5
volumes:
- .:/home/dev/lib
tty: true
user: dev
working_dir: /home/dev/lib
php80:
<<: *base
build:
context: docker/
args:
PHP_IMAGE: php:8.0
php81:
php82:
<<: *base
build:
context: docker/
args:
PHP_IMAGE: php:8.1
php82:
PHP_IMAGE: php:8.2
php83:
<<: *base
build:
context: docker/
args:
PHP_IMAGE: php:8.2
PHP_IMAGE: php:8.3
17 changes: 5 additions & 12 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

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

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74,
]);
};
])
->withPhpSets(php81: true)
->withTypeCoverageLevel(0);
8 changes: 2 additions & 6 deletions src/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@ interface Decoder
* @psalm-param Context $context
*
* @psalm-return Validation<A>
*
* @param mixed $i
*/
public function validate($i, Context $context): Validation;
public function validate(mixed $i, Context $context): Validation;

/**
* @psalm-param I $i
*
* @psalm-return Validation<A>
*
* @param mixed $i
*/
public function decode($i): Validation;
public function decode(mixed $i): Validation;

public function getName(): string;
}
4 changes: 1 addition & 3 deletions src/Decoders.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ public static function transformValidationSuccess(callable $f, Decoder $da): Dec
* @psalm-param T $l
*
* @psalm-return Decoder<mixed, T>
*
* @param mixed $l
*/
public static function literal($l): Decoder
public static function literal(mixed $l): Decoder
{
return new LiteralDecoder($l);
}
Expand Down
9 changes: 4 additions & 5 deletions src/Internal/Arrays/ListOfDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
*/
final class ListOfDecoder implements Decoder
{
/** @var Decoder<IT, T> */
private \Facile\PhpCodec\Decoder $elementDecoder;

/**
* @psalm-param Decoder<IT, T> $elementDecoder
*/
public function __construct(Decoder $elementDecoder)
public function __construct(
/** @var Decoder<IT, T> */
private readonly \Facile\PhpCodec\Decoder $elementDecoder
)
{
$this->elementDecoder = $elementDecoder;
}

public function validate($i, Context $context): Validation
Expand Down
6 changes: 1 addition & 5 deletions src/Internal/Combinators/ArrayPropsDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@
*/
final class ArrayPropsDecoder implements Decoder
{
/** @var PD */
private array $props;

/**
* @psalm-param PD $props
*/
public function __construct(array $props)
public function __construct(private readonly array $props)
{
$this->props = $props;
}

public function validate($i, Context $context): Validation
Expand Down
18 changes: 7 additions & 11 deletions src/Internal/Combinators/ComposeDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@
*/
final class ComposeDecoder implements Decoder
{
/** @var Decoder<A, B> */
private \Facile\PhpCodec\Decoder $db;
/** @var Decoder<IA, A> */
private \Facile\PhpCodec\Decoder $da;

/**
* @psalm-param Decoder<A, B> $db
* @psalm-param Decoder<IA, A> $da
*/
public function __construct(
Decoder $db,
Decoder $da
) {
$this->db = $db;
$this->da = $da;
/** @var Decoder<A, B> */
private readonly \Facile\PhpCodec\Decoder $db,
/** @var Decoder<IA, A> */
private readonly \Facile\PhpCodec\Decoder $da
)
{
}

/**
Expand All @@ -53,7 +49,7 @@ public function validate($i, Context $context): Validation
*
* @param mixed $aValue
*/
fn($aValue): Validation => $this->db->validate($aValue, $context),
fn(mixed $aValue): Validation => $this->db->validate($aValue, $context),
$this->da->validate($i, $context)
);
}
Expand Down
18 changes: 7 additions & 11 deletions src/Internal/Combinators/IntersectionDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@
*/
final class IntersectionDecoder implements Decoder
{
/** @var Decoder<IA, A> */
private \Facile\PhpCodec\Decoder $a;
/** @var Decoder<IB, B> */
private \Facile\PhpCodec\Decoder $b;

/**
* @psalm-param Decoder<IA, A> $a
* @psalm-param Decoder<IB, B> $b
*/
public function __construct(Decoder $a, Decoder $b)
public function __construct(
/** @var Decoder<IA, A> */
private readonly \Facile\PhpCodec\Decoder $a,
/** @var Decoder<IB, B> */
private readonly \Facile\PhpCodec\Decoder $b
)
{
$this->a = $a;
$this->b = $b;
}

public function validate($i, Context $context): Validation
Expand Down Expand Up @@ -97,12 +95,10 @@ public function getName(): string
*
* @psalm-return T1&T2
*
* @param mixed $a
* @param mixed $b
*
* @return array|object
*/
private static function intersectResults($a, $b)
private static function intersectResults(mixed $a, mixed $b)
{
if (\is_array($a) && \is_array($b)) {
/** @var T1&T2 */
Expand Down
8 changes: 2 additions & 6 deletions src/Internal/Combinators/LiteralDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ final class LiteralDecoder implements Decoder

/**
* @psalm-param T $literal
*
* @param mixed $literal
*/
public function __construct($literal)
public function __construct(mixed $literal)
{
$this->literal = $literal;
}
Expand All @@ -59,10 +57,8 @@ public function getName(): string

/**
* @psalm-param literable $x
*
* @param mixed $x
*/
private static function literalName($x): string
private static function literalName(mixed $x): string
{
if (\is_string($x)) {
return "'{$x}'";
Expand Down
4 changes: 1 addition & 3 deletions src/Internal/Combinators/MapDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ final class MapDecoder implements Decoder
{
/** @var callable(A):B */
private $f;
private string $name;

/**
* @psalm-param callable(A):B $f
*/
public function __construct(callable $f, string $name = 'map')
public function __construct(callable $f, private readonly string $name = 'map')
{
$this->f = $f;
$this->name = $name;
}

public function validate($i, Context $context): Validation
Expand Down
20 changes: 7 additions & 13 deletions src/Internal/Combinators/UnionDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,18 @@
*/
final class UnionDecoder implements Decoder
{
/** @var Decoder<IA, A> */
private \Facile\PhpCodec\Decoder $a;
/** @var Decoder<IB, B> */
private \Facile\PhpCodec\Decoder $b;
private int $indexBegin;

/**
* @psalm-param Decoder<IA, A> $a
* @psalm-param Decoder<IB, B> $b
*/
public function __construct(
Decoder $a,
Decoder $b,
int $indexBegin = 0
) {
$this->a = $a;
$this->b = $b;
$this->indexBegin = $indexBegin;
/** @var Decoder<IA, A> */
private readonly \Facile\PhpCodec\Decoder $a,
/** @var Decoder<IB, B> */
private readonly \Facile\PhpCodec\Decoder $b,
private readonly int $indexBegin = 0
)
{
}

public function validate($i, Context $context): Validation
Expand Down
9 changes: 2 additions & 7 deletions src/Internal/FunctionUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public static function nameFromProps(array $props): string
* @psalm-param I $input
*
* @psalm-return Validation<A>
*
* @param mixed $input
*/
public static function standardDecode(Decoder $decoder, $input): Validation
public static function standardDecode(Decoder $decoder, mixed $input): Validation
{
return $decoder->validate(
$input,
Expand All @@ -69,10 +67,7 @@ public static function destructureIn(callable $f): callable
return fn(array $params) => $f(...$params);
}

/**
* @param mixed $x
*/
public static function strigify($x): string
public static function strigify(mixed $x): string
{
if ($x === null) {
return 'null';
Expand Down
8 changes: 1 addition & 7 deletions src/Internal/Primitives/UndefinedDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@
*/
final class UndefinedDecoder implements Decoder
{
/** @var U */
private $default;

/**
* @psalm-param U $default
*
* @param mixed $default
*/
public function __construct($default)
public function __construct(private readonly mixed $default)
{
$this->default = $default;
}

public function validate($i, Context $context): Validation
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Undefined.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Facile\PhpCodec\Internal;

final class Undefined
final class Undefined implements \Stringable
{
public function __toString(): string
{
Expand Down
Loading
Loading