Skip to content

Commit

Permalink
PHP 8.3 update
Browse files Browse the repository at this point in the history
  • Loading branch information
tuqqu committed Jan 22, 2024
1 parent bcd236b commit 56763b3
Show file tree
Hide file tree
Showing 51 changed files with 119 additions and 84 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3
ini-values: memory_limit=-1
tools: composer:v2

Expand All @@ -37,7 +37,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3
ini-values: memory_limit=-1
tools: composer:v2

Expand Down
13 changes: 6 additions & 7 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

declare(strict_types=1);

const CONFIG = new PhpCsFixer\Config();
const RULES = [
'@PER' => true,
const config = new PhpCsFixer\Config();
const rules = [
'@PER-CS' => true,
'strict_param' => true,
'single_import_per_statement' => false,
'no_unused_imports' => true,
'array_syntax' => ['syntax' => 'short'],
'single_line_empty_body' => true,
Expand All @@ -18,11 +17,11 @@
],
];

CONFIG->setRules(RULES);
CONFIG->setFinder(PhpCsFixer\Finder::create()
config->setRules(rules);
config->setFinder(PhpCsFixer\Finder::create()
->in(__DIR__ . '/bin')
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
);

return CONFIG;
return config;
4 changes: 2 additions & 2 deletions bin/go-php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ enum Flag: string
case Goroot = 'goroot';
case Gopath = 'gopath';

private const FLAGS_WITH_VALUE = [
private const array FLAGS_WITH_VALUE = [
self::Goroot,
self::Gopath,
];

private const FLAGS_WITHOUT_VALUE = [
private const array FLAGS_WITHOUT_VALUE = [
self::Help,
self::Version,
self::Eval,
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
}
],
"require": {
"php": "^8.2",
"php": "^8.3",
"tuqqu/go-parser": "^0.5.1"
},
"require-dev": {
"symfony/var-dumper": "^6",
"friendsofphp/php-cs-fixer": "^3.22",
"phpunit/phpunit": "^10",
"vimeo/psalm": "^5.13"
"friendsofphp/php-cs-fixer": "^3.48",
"phpunit/phpunit": "^10.5",
"vimeo/psalm": "^5.20"
},
"bin": [
"bin/go-php"
Expand Down
2 changes: 1 addition & 1 deletion src/Builtin/BuiltinFunc/Append.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function name(): string
public function __invoke(Argv $argv): SliceValue
{
assert_argc($this, $argv, 2, true);
assert_arg_value($argv[0], SliceValue::class, SliceValue::NAME);
assert_arg_value($argv[0], SliceValue::class);

/** @var SliceValue $slice */
$slice = $argv[0]->value->clone();
Expand Down
2 changes: 1 addition & 1 deletion src/Builtin/BuiltinFunc/Copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __invoke(Argv $argv): IntValue
$dst = $argv[0];
$src = $argv[1];

assert_arg_value($dst, SliceValue::class, SliceValue::NAME);
assert_arg_value($dst, SliceValue::class);

// As a special case, if the destination's type is []byte,
// copy also accepts a source argument with type string.
Expand Down
2 changes: 1 addition & 1 deletion src/Builtin/BuiltinFunc/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(
public function __invoke(Argv $argv): VoidValue
{
assert_argc($this, $argv, 2);
assert_arg_value($argv[0], MapValue::class, MapValue::NAME);
assert_arg_value($argv[0], MapValue::class);

$m = $argv[0]->value;
$key = $argv[1]->value;
Expand Down
2 changes: 1 addition & 1 deletion src/Builtin/BuiltinFunc/Imag.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(
public function __invoke(Argv $argv): FloatNumber
{
assert_argc($this, $argv, 1);
assert_arg_value($argv[0], ComplexNumber::class, ComplexNumber::NAME);
assert_arg_value($argv[0], ComplexNumber::class);

return $argv[0]->value->imag();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Builtin/BuiltinFunc/Make.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
public function __invoke(Argv $argv): SliceValue|MapValue
{
assert_argc($this, $argv, 2, true);
assert_arg_value($argv[0], TypeValue::class, 'type');
assert_arg_value($argv[0], TypeValue::class);

/** @var TypeValue $type */
$type = $argv[0]->value;
Expand Down Expand Up @@ -81,7 +81,7 @@ public function __invoke(Argv $argv): SliceValue|MapValue

if (isset($argv[1])) {
// we do not use this value, just validating it
assert_arg_value($argv[1], IntNumber::class, IntNumber::NAME);
assert_arg_value($argv[1], IntNumber::class);
assert_index_positive($argv[1]->value->unwrap());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Builtin/BuiltinFunc/New_.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
public function __invoke(Argv $argv): PointerValue
{
assert_argc($this, $argv, 1);
assert_arg_value($argv[0], TypeValue::class, 'type');
assert_arg_value($argv[0], TypeValue::class);

$type = $argv[0]->value;

Expand Down
2 changes: 1 addition & 1 deletion src/Builtin/BuiltinFunc/Real.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(
public function __invoke(Argv $argv): FloatNumber
{
assert_argc($this, $argv, 1);
assert_arg_value($argv[0], ComplexNumber::class, ComplexNumber::NAME);
assert_arg_value($argv[0], ComplexNumber::class);

return $argv[0]->value->real();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Builtin/StdBuiltinProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

class StdBuiltinProvider implements BuiltinProvider
{
protected const IOTA_START = 0;
protected const int IOTA_START = 0;

public function __construct(
private readonly OutputStream $stderr,
Expand Down
2 changes: 1 addition & 1 deletion src/CallStackCollectorDebugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

final class CallStackCollectorDebugger implements Debugger
{
public const DEFAULT_STACK_TRACE_DEPTH = 128;
public const int DEFAULT_STACK_TRACE_DEPTH = 128;

/** @var list<InvokableCall|PanicError> */
private array $stackTrace = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Env/EnvMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class EnvMap
{
public const NAMESPACE_TOP = '';
public const string NAMESPACE_TOP = '';

/** @var array<string, array<string, EnvValue>> */
private array $values = [];
Expand Down
6 changes: 2 additions & 4 deletions src/Env/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

final class Environment
{
public const BLANK_IDENT = '_';
public const string BLANK_IDENT = '_';

public readonly string $blankIdent;
private readonly EnvMap $envMap;
Expand All @@ -25,12 +25,10 @@ final class Environment

private function __construct(?self $enclosing, string $blankIdent)
{
$this->envMap = new EnvMap();
$this->registeredMethods = new MethodSet();

$this->enclosing = $enclosing;
$this->blankIdent = $blankIdent;

$this->envMap = new EnvMap();
$this->envMap->add(new EnvValue($this->blankIdent, new BlankValue()));
}

Expand Down
4 changes: 2 additions & 2 deletions src/EnvVarSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class EnvVarSet
{
public const DEFAULT_GOROOT = '/usr/local/go';
public const DEFAULT_GOPATH = '~/go';
public const string DEFAULT_GOROOT = '/usr/local/go';
public const string DEFAULT_GOPATH = '~/go';

public function __construct(
public readonly string $goroot = self::DEFAULT_GOROOT,
Expand Down
2 changes: 1 addition & 1 deletion src/Error/InternalError.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function unreachable(object|string|null $context): self
$context === null => '',
};

return new self('unreachable' . $context ? sprintf(': %s', $context) : '');
return new self('unreachable' . ($context ? sprintf(': %s', $context) : ''));
}

public static function unexpectedValue(mixed $value, ?string $expected = null): self
Expand Down
4 changes: 2 additions & 2 deletions src/Error/RuntimeError.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ protected static function wrongFuncArity(
"%s\nhave (%s)\nwant (%s)",
$type,
implode(', ', array_map(
static fn (GoValue $value): string => $value->type()->name(),
static fn(GoValue $value): string => $value->type()->name(),
$values,
)),
$params,
Expand Down Expand Up @@ -715,7 +715,7 @@ protected static function tupleTypeToString(TupleValue $tuple): string
implode(
', ',
array_map(
static fn (GoValue $value): string => $value->type()->name(),
static fn(GoValue $value): string => $value->type()->name(),
$tuple->values,
),
),
Expand Down
2 changes: 1 addition & 1 deletion src/GoType/Converter/StringConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

final class StringConverter
{
private const INVALID_RANGE_CHAR = "\u{FFFD}";
private const string INVALID_RANGE_CHAR = "\u{FFFD}";

public static function convert(GoValue $value): BaseString
{
Expand Down
4 changes: 2 additions & 2 deletions src/GoType/NamedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
*/
enum NamedType: string implements BasicType
{
public const Rune = self::Int32;
public const Byte = self::Uint8;
public const self Rune = self::Int32;
public const self Byte = self::Uint8;

// signed integer types
case Int = 'int';
Expand Down
2 changes: 1 addition & 1 deletion src/GoType/WrappedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function zeroValue(): WrappedValue
*/
public function valueCallback(): callable
{
return fn (GoValue $value): WrappedValue => new WrappedValue($value, $this);
return fn(GoValue $value): WrappedValue => new WrappedValue($value, $this);
}

public function convert(AddressableValue $value): WrappedValue
Expand Down
5 changes: 5 additions & 0 deletions src/GoValue/AddressableValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/
interface AddressableValue extends GoValue
{
/**
* Constant name of the value.
*/
public const string NAME = 'value';

/**
* Must be called wherever the value becomes stored (e.g. in a variable).
*/
Expand Down
2 changes: 1 addition & 1 deletion src/GoValue/Array/ArrayValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class ArrayValue implements Hashable, Sliceable, Sequence, AddressableValu
{
use AddressableTrait;

public const NAME = 'array';
public const string NAME = 'array';

/** @var UnderlyingArray<V> */
private UnderlyingArray $values;
Expand Down
2 changes: 1 addition & 1 deletion src/GoValue/Complex/ComplexNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class ComplexNumber implements Hashable, Castable, Sealable, Addressabl
use SealableTrait;
use AddressableTrait;

public const NAME = 'complex';
public const string NAME = 'complex';

public static function fromSimpleNumber(SimpleNumber $number): static
{
Expand Down
4 changes: 3 additions & 1 deletion src/GoValue/Float/FloatNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use GoPhp\GoValue\Sealable;
use GoPhp\GoValue\SimpleNumber;
use GoPhp\Operator;
use Override;

use function sprintf;

Expand All @@ -21,7 +22,7 @@
*/
abstract class FloatNumber extends SimpleNumber
{
final public const NAME = 'float';
final public const string NAME = 'float';

protected float $value;

Expand All @@ -35,6 +36,7 @@ public function unwrap(): float
return $this->value;
}

#[Override]
public function toString(): string
{
return sprintf('%f', $this->value);
Expand Down
2 changes: 1 addition & 1 deletion src/GoValue/Func/FuncValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class FuncValue implements RecoverableInvokable, AddressableValue
use AddressableTrait;
use SealableTrait;

public const NAME = 'func';
public const string NAME = 'func';

private function __construct(
public ?Func $innerFunc,
Expand Down
22 changes: 21 additions & 1 deletion src/GoValue/GoValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,44 @@
use GoPhp\Operator;

/**
* @template T
* @template T of mixed (the underlying PHP value)
*/
interface GoValue
{
/**
* Unary operation on a value.
*/
public function operate(Operator $op): self;

/**
* Binary operation on two values. Value on the left hand side is $this.
*/
public function operateOn(Operator $op, self $rhs): self;

/**
* Mutates the value on the left hand side with the value on the right hand side.
*/
public function mutate(Operator $op, self $rhs): void;

/**
* Unwraps the value, returning the underlying PHP value.
*
* @return T
*/
public function unwrap(): mixed;

/**
* Returns a new value that is a copy of the current value.
*/
public function copy(): self;

/**
* Returns the type of the value.
*/
public function type(): GoType;

/**
* Returns the string representation of the value.
*/
public function toString(): string;
}
3 changes: 2 additions & 1 deletion src/GoValue/Hashable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace GoPhp\GoValue;

/**
* @template H = scalar
* @psalm-type Hash = string|int|float|bool
* @template H = Hash
*/
interface Hashable
{
Expand Down
Loading

0 comments on commit 56763b3

Please sign in to comment.