Skip to content

Commit

Permalink
Merge pull request #66 from lucatume/php-84-compat
Browse files Browse the repository at this point in the history
solve PHP 8.4 deprecation issues
  • Loading branch information
lucatume authored Dec 14, 2024
2 parents 76c0c2a + d1aec79 commit f41fc28
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 36 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup PHP 5.6
- name: Setup PHP 7.1
uses: shivammathur/setup-php@v2
with:
php-version: 5.6
php-version: 7.1
- name: Install dependencies
uses: "ramsey/composer-install@v2"
- name: Run phpcs
run: make phpcs
phpstan:
name: phpstan on PHP 5.6
name: phpstan on PHP 7.1
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup PHP 5.6
- name: Setup PHP 7.1
uses: shivammathur/setup-php@v2
with:
php-version: 5.6
php-version: 7.1
- name: Install dependencies
uses: "ramsey/composer-install@v2"
- name: Run phpstan
run: make phpstan
phan:
name: phan on PHP 5.6
name: phan on PHP 7.1
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup PHP 5.6
- name: Setup PHP 7.1
uses: shivammathur/setup-php@v2
with:
php-version: 5.6
php-version: 7.1
- name: Install dependencies
uses: "ramsey/composer-install@v2"
- name: Run phan
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '5.6', '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:
- name: Checkout code
uses: actions/checkout@v3
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

### Changed

- Bumped minimum supported version to PHP 7.1.
- Fixed PHP 8.4 deprecation warnings.

## [3.3.7] 2024-04-26;

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
},
"require": {
"php": ">=5.6",
"php": ">=7.1",
"psr/container": "^1.0",
"ext-json": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion config/phan-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
// Note that the **only** effect of choosing `'5.6'` is to infer that functions removed in php 7.0 exist.
// (See `backward_compatibility_checks` for additional options)
// Automatically inferred from composer.json requirement for "php" of ">=5.6"
'target_php_version' => '5.6',
'target_php_version' => '7.1',

// If enabled, missing properties will be created when
// they are first seen. If false, we'll report an
Expand Down
18 changes: 9 additions & 9 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function container()

return static::$container;
}

/**
* Sets the container instance the Application should use as a Service Locator.
*
Expand All @@ -54,7 +54,7 @@ public static function setContainer(Container $container)
{
static::$container = $container;
}

/**
* Sets a variable on the container.
*
Expand Down Expand Up @@ -99,7 +99,7 @@ public static function offsetSet($offset, $value)
*
* @throws ContainerException If there's any issue reflecting on the class, interface or the implementation.
*/
public static function singleton($id, $implementation = null, array $afterBuildMethods = null)
public static function singleton($id, $implementation = null, ?array $afterBuildMethods = null)
{
static::container()->singleton($id, $implementation, $afterBuildMethods);
}
Expand Down Expand Up @@ -311,7 +311,7 @@ public static function register($serviceProviderClass, ...$alias)
*
* @throws ContainerException If there's an issue while trying to bind the implementation.
*/
public static function bind($id, $implementation = null, array $afterBuildMethods = null)
public static function bind($id, $implementation = null, ?array $afterBuildMethods = null)
{
static::container()->bind($id, $implementation, $afterBuildMethods);
}
Expand Down Expand Up @@ -346,7 +346,7 @@ public static function boot()
* @return void This method does not return any value.
* @throws ContainerException
*/
public static function singletonDecorators($id, $decorators, array $afterBuildMethods = null)
public static function singletonDecorators($id, $decorators, ?array $afterBuildMethods = null)
{
static::container()->singletonDecorators($id, $decorators, $afterBuildMethods);
}
Expand All @@ -367,7 +367,7 @@ public static function singletonDecorators($id, $decorators, array $afterBuildMe
* @return void This method does not return any value.
* @throws ContainerException If there's any issue binding the decorators.
*/
public static function bindDecorators($id, array $decorators, array $afterBuildMethods = null)
public static function bindDecorators($id, array $decorators, ?array $afterBuildMethods = null)
{
static::container()->bindDecorators($id, $decorators, $afterBuildMethods);
}
Expand Down Expand Up @@ -471,7 +471,7 @@ public static function callback($id, $method)
* The callable will be a closure on PHP 5.3+ or a lambda function on PHP 5.2.
*
* @param string|class-string|mixed $id The fully qualified name of a class or an interface.
* @param array<mixed> $buildArgs An array of arguments that should be used to build the
* @param array<mixed>|null $buildArgs An array of arguments that should be used to build the
* instance; note that any argument will be resolved using
* the container itself and bindings will apply.
* @param string[]|null $afterBuildMethods An array of methods that should be called on the built
Expand All @@ -480,9 +480,9 @@ public static function callback($id, $method)
* @return callable A callable function that will return an instance of the specified class when
* called.
*/
public static function instance($id, array $buildArgs = [], array $afterBuildMethods = null)
public static function instance($id, ?array $buildArgs = [], ?array $afterBuildMethods = null)
{
return static::container()->instance($id, $buildArgs, $afterBuildMethods);
return static::container()->instance($id, $buildArgs ?? [], $afterBuildMethods);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Builders/CallableBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CallableBuilder implements BuilderInterface, ReinitializableBuilderInterfa
public function __construct(
Container $container,
callable $callable,
array $afterBuildMethods = null,
?array $afterBuildMethods = null,
...$buildArgs
) {
$this->container = $container;
Expand Down Expand Up @@ -86,7 +86,7 @@ public function build()
*
* @return void This method does not return any value.
*/
public function reinit(array $afterBuildMethods = null, ...$buildArgs)
public function reinit(?array $afterBuildMethods = null, ...$buildArgs)
{
$this->afterBuildMethods = $afterBuildMethods ?: [];
$this->buildArgs = $buildArgs;
Expand Down
4 changes: 2 additions & 2 deletions src/Builders/ClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ClassBuilder implements BuilderInterface, ReinitializableBuilderInterface
*
* @throws NotFoundException If the class does not exist.
*/
public function __construct($id, Resolver $resolver, $className, array $afterBuildMethods = null, ...$buildArgs)
public function __construct($id, Resolver $resolver, $className, ?array $afterBuildMethods = null, ...$buildArgs)
{
if (!class_exists($className)) {
throw new NotFoundException(
Expand Down Expand Up @@ -236,7 +236,7 @@ protected function resolveParameter(Parameter $parameter)
/**
* {@inheritdoc}
*/
public function reinit(array $afterBuildMethods = null, ...$buildArgs)
public function reinit(?array $afterBuildMethods = null, ...$buildArgs)
{
$this->afterBuildMethods = $afterBuildMethods;
$this->buildArgs = $buildArgs;
Expand Down
2 changes: 1 addition & 1 deletion src/Builders/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(Container $container, Resolver $resolver)
*
* @throws NotFoundException If a builder cannot find its implementation target.
*/
public function getBuilder($id, $implementation = null, array $afterBuildMethods = null, ...$buildArgs)
public function getBuilder($id, $implementation = null, ?array $afterBuildMethods = null, ...$buildArgs)
{
if ($implementation === null) {
$implementation = $id;
Expand Down
2 changes: 1 addition & 1 deletion src/Builders/ReinitializableBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ interface ReinitializableBuilderInterface
*
* @return void This method does not return any value.
*/
public function reinit(array $afterBuildMethods = null, ...$buildArgs);
public function reinit(?array $afterBuildMethods = null, ...$buildArgs);
}
6 changes: 3 additions & 3 deletions src/Builders/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function setWhenNeedsGive($whenClass, $needsClass, BuilderInterface $buil
* build arguments.
* @throws NotFoundException If the id is a string that does not resolve to an existing, concrete, class.
*/
public function resolveWithArgs($id, array $afterBuildMethods = null, ...$buildArgs)
public function resolveWithArgs($id, ?array $afterBuildMethods = null, ...$buildArgs)
{
if (! is_string($id)) {
return $id;
Expand All @@ -197,7 +197,7 @@ public function resolveWithArgs($id, array $afterBuildMethods = null, ...$buildA
*
* @throws NotFoundException If the id is a string that is not bound and is not an existing, concrete, class.
*/
public function resolve($id, array $buildLine = null)
public function resolve($id, ?array $buildLine = null)
{
if ($buildLine !== null) {
$this->buildLine = $buildLine;
Expand Down Expand Up @@ -271,7 +271,7 @@ private function resolveBound($id)
* @throws NotFoundException If trying to clone the builder for a non existing id or an id that does not map to a
* concrete class name.
*/
private function cloneBuilder($id, array $afterBuildMethods = null, ...$buildArgs)
private function cloneBuilder($id, ?array $afterBuildMethods = null, ...$buildArgs)
{
if (isset($this->bindings[$id]) && $this->bindings[$id] instanceof BuilderInterface) {
$builder = clone $this->bindings[$id];
Expand Down
16 changes: 10 additions & 6 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function offsetSet($offset, $value)
* @return void This method does not return any value.
* @throws ContainerException If there's any issue reflecting on the class, interface or the implementation.
*/
public function singleton($id, $implementation = null, array $afterBuildMethods = null)
public function singleton($id, $implementation = null, ?array $afterBuildMethods = null)
{
if ($implementation === null) {
$implementation = $id;
Expand Down Expand Up @@ -459,6 +459,7 @@ public function register($serviceProviderClass, ...$alias)
$provider->register();
} else {
$provided = $provider->provides();
// @phpstan-ignore-next-line
if (!is_array($provided) || count($provided) === 0) {
throw new ContainerException(
"Service provider '{$serviceProviderClass}' is marked as deferred" .
Expand Down Expand Up @@ -526,7 +527,7 @@ private function getDeferredProviderMakeClosure(ServiceProvider $provider, $id)
*
* @throws ContainerException If there's an issue while trying to bind the implementation.
*/
public function bind($id, $implementation = null, array $afterBuildMethods = null)
public function bind($id, $implementation = null, ?array $afterBuildMethods = null)
{
if ($implementation === null) {
$implementation = $id;
Expand Down Expand Up @@ -574,7 +575,7 @@ public function boot()
* @return void This method does not return any value.
* @throws ContainerException
*/
public function singletonDecorators($id, $decorators, array $afterBuildMethods = null, $afterBuildAll = false)
public function singletonDecorators($id, $decorators, ?array $afterBuildMethods = null, $afterBuildAll = false)
{
$this->resolver->singleton(
$id,
Expand All @@ -600,7 +601,7 @@ public function singletonDecorators($id, $decorators, array $afterBuildMethods =
private function getDecoratorBuilder(
array $decorators,
$id,
array $afterBuildMethods = null,
?array $afterBuildMethods = null,
$afterBuildAll = false
) {
$decorator = array_pop($decorators);
Expand Down Expand Up @@ -639,7 +640,7 @@ private function getDecoratorBuilder(
* @return void This method does not return any value.
* @throws ContainerException If there's any issue binding the decorators.
*/
public function bindDecorators($id, array $decorators, array $afterBuildMethods = null, $afterBuildAll = false)
public function bindDecorators($id, array $decorators, ?array $afterBuildMethods = null, $afterBuildAll = false)
{
$this->resolver->bind($id, $this->getDecoratorBuilder($decorators, $id, $afterBuildMethods, $afterBuildAll));
}
Expand Down Expand Up @@ -748,13 +749,15 @@ public function callback($id, $method)
{
$callbackIdPrefix = is_object($id) ? spl_object_hash($id) : $id;

// @phpstan-ignore-next-line
if (!is_string($callbackIdPrefix)) {
$typeOfId = gettype($id);
throw new ContainerException(
"Callbacks can only be built on ids, class names or objects; '{$typeOfId}' is neither."
);
}

// @phpstan-ignore-next-line
if (!is_string($method)) {
throw new ContainerException("Callbacks second argument must be a string method name.");
}
Expand Down Expand Up @@ -818,7 +821,7 @@ protected function isStaticMethod($object, $method)
* @return callable|Closure A callable function that will return an instance of the specified class when
* called.
*/
public function instance($id, array $buildArgs = [], array $afterBuildMethods = null)
public function instance($id, array $buildArgs = [], ?array $afterBuildMethods = null)
{
return function () use ($id, $afterBuildMethods, $buildArgs) {
if (is_string($id)) {
Expand Down Expand Up @@ -878,6 +881,7 @@ public function getProvider($providerId)
*/
public function isBound($id)
{
// @phpstan-ignore-next-line
return is_string($id) && $this->resolver->isBound($id);
}

Expand Down
2 changes: 1 addition & 1 deletion src/NestedParseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NestedParseError extends \Exception
* @param string $type The type of the entity being loaded.
* @param string $name The name of the entity being loaded.
*/
public function __construct($message = "", $code = 0, Throwable $previous = null, $type = '', $name = '')
public function __construct($message = "", $code = 0, ?Throwable $previous = null, $type = '', $name = '')
{
parent::__construct($message, $code, $previous);
$this->type = $type;
Expand Down

0 comments on commit f41fc28

Please sign in to comment.