Skip to content
Closed
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
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@ on:
- cron: "0 0 * * *"

jobs:
php82:
name: PHP 8.2
php83:
name: PHP 8.3
runs-on: ubuntu-24.04
steps:
- name: checkout
uses: actions/checkout@v4
- name: composer test
uses: docker://ghcr.io/chubbyphp/ci-php82:latest
uses: docker://ghcr.io/chubbyphp/ci-php83:latest
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
php83:
name: PHP 8.3
php84:
name: PHP 8.4
runs-on: ubuntu-24.04
steps:
- name: checkout
uses: actions/checkout@v4
- name: composer test
uses: docker://ghcr.io/chubbyphp/ci-php83:latest
uses: docker://ghcr.io/chubbyphp/ci-php84:latest
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
php84:
name: PHP 8.4
php85:
name: PHP 8.5
runs-on: ubuntu-24.04
steps:
- name: checkout
uses: actions/checkout@v4
- name: composer test
uses: docker://ghcr.io/chubbyphp/ci-php84:latest
uses: docker://ghcr.io/chubbyphp/ci-php85:latest
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
Expand Down
4 changes: 1 addition & 3 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
/** @var array $config */
$config = require __DIR__ . '/vendor/chubbyphp/chubbyphp-dev-helper/phpcs.php';

// drop onces code is >= 8.0
unset($config['rules']['phpdoc_to_return_type']);

return (new PhpCsFixer\Config)
->setUnsupportedPhpVersionAllowed(true)
->setIndent($config['indent'])
->setLineEnding($config['lineEnding'])
->setRules($config['rules'])
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
}
],
"require": {
"php": "^8.2",
"php": "^8.3",
"psr/container": "^2.0.2"
},
"require-dev": {
"chubbyphp/chubbyphp-dev-helper": "dev-master",
"chubbyphp/chubbyphp-mock": "^2.0",
"infection/infection": "^0.29.13",
"php-coveralls/php-coveralls": "^2.7.0",
"chubbyphp/chubbyphp-mock": "^2.0.1",
"infection/infection": "^0.31.9",
"php-coveralls/php-coveralls": "^2.9",
"phpstan/extension-installer": "^1.4.3",
"phpstan/phpstan": "^2.1.6",
"phpunit/phpunit": "^11.5.10"
"phpstan/phpstan": "^2.1.32",
"phpunit/phpunit": "^12.4.5"
},
"autoload": {
"psr-4": { "Chubbyphp\\Container\\": "src/" }
Expand All @@ -45,7 +45,7 @@
}
},
"scripts": {
"fix:cs": "mkdir -p build && PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --cache-file=build/phpcs.cache",
"fix:cs": "mkdir -p build && vendor/bin/php-cs-fixer fix --cache-file=build/phpcs.cache",
"test": [
"@test:lint",
"@test:unit",
Expand All @@ -54,7 +54,7 @@
"@test:static-analysis",
"@test:cs"
],
"test:cs": "mkdir -p build && PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --cache-file=build/phpcs.cache",
"test:cs": "mkdir -p build && vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --cache-file=build/phpcs.cache",
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=100 --verbose --coverage=build/phpunit",
"test:integration": "vendor/bin/phpunit --testsuite=Integration --cache-directory=build/phpunit",
"test:lint": "mkdir -p build && find src tests -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l | tee build/phplint.log",
Expand Down
15 changes: 3 additions & 12 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ public function prototypeFactory(string $id, callable $factory): ContainerInterf
return $this;
}

/**
* @return mixed
*/
public function get(string $id)
public function get(string $id): mixed
{
if (isset($this->prototypeFactories[$id])) {
return $this->createFromPrototypeFactory($id);
Expand All @@ -106,10 +103,7 @@ public function has(string $id): bool
return isset($this->factories[$id]) || isset($this->prototypeFactories[$id]);
}

/**
* @return mixed
*/
private function createFromFactory(string $id)
private function createFromFactory(string $id): mixed
{
if (!isset($this->factories[$id])) {
throw NotFoundException::create($id);
Expand All @@ -122,10 +116,7 @@ private function createFromFactory(string $id)
}
}

/**
* @return mixed
*/
private function createFromPrototypeFactory(string $id)
private function createFromPrototypeFactory(string $id): mixed
{
try {
return ($this->prototypeFactories[$id])($this);
Expand Down
5 changes: 3 additions & 2 deletions src/Exceptions/ExistsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

final class ExistsException extends \LogicException implements ContainerExceptionInterface
{
public const TYPE_FACTORY = 'factory';
public const TYPE_PROTOTYPE_FACTORY = 'prototype factory';
public const string TYPE_FACTORY = 'factory';

public const string TYPE_PROTOTYPE_FACTORY = 'prototype factory';

private function __construct(string $message, int $code, ?\Throwable $previous = null)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ public function __construct(callable $previousFactory, callable $factory)
$this->factory = $factory;
}

/**
* @return mixed
*/
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container): mixed
{
return ($this->factory)($container, $this->previousFactory);
}
Expand Down
10 changes: 2 additions & 8 deletions src/MinimalContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ public function factory(string $id, callable $factory): ContainerInterface
return $this;
}

/**
* @return mixed
*/
public function get(string $id)
public function get(string $id): mixed
{
return $this->services[$id] ?? $this->services[$id] = $this->createFromFactory($id);
}
Expand All @@ -65,10 +62,7 @@ public function has(string $id): bool
return isset($this->factories[$id]);
}

/**
* @return mixed
*/
private function createFromFactory(string $id)
private function createFromFactory(string $id): mixed
{
if (!isset($this->factories[$id])) {
throw NotFoundException::create($id);
Expand Down
5 changes: 1 addition & 4 deletions src/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ final class Parameter
*/
public function __construct(private $parameter) {}

/**
* @return mixed
*/
public function __invoke()
public function __invoke(): mixed
{
return $this->parameter;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
use Chubbyphp\Container\Exceptions\ContainerException;
use Chubbyphp\Container\Exceptions\ExistsException;
use Chubbyphp\Container\Exceptions\NotFoundException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;

/**
* @covers \Chubbyphp\Container\Container
*
* @internal
*/
#[CoversClass(Container::class)]
final class ContainerTest extends TestCase
{
/**
Expand Down Expand Up @@ -120,7 +120,7 @@ public function testFactoryReplace(): void
{
$container = new Container();

$container->factory('id', static function (): void {
$container->factory('id', static function (): never {
throw new \Exception('should not be called!');
});

Expand Down Expand Up @@ -249,7 +249,7 @@ public function testPrototypeFactoryReplace(): void
{
$container = new Container();

$container->prototypeFactory('id', static function (): void {
$container->prototypeFactory('id', static function (): never {
throw new \Exception('should not be called!');
});

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Exceptions/ContainerExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace Chubbyphp\Tests\Container\Unit\Exceptions;

use Chubbyphp\Container\Exceptions\ContainerException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @covers \Chubbyphp\Container\Exceptions\ContainerException
*
* @internal
*/
#[CoversClass(ContainerException::class)]
final class ContainerExceptionTest extends TestCase
{
public function testConstruct(): void
Expand Down
9 changes: 4 additions & 5 deletions tests/Unit/Exceptions/ExistsExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
namespace Chubbyphp\Tests\Container\Unit\Exceptions;

use Chubbyphp\Container\Exceptions\ExistsException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
* @covers \Chubbyphp\Container\Exceptions\ExistsException
*
* @internal
*/
#[CoversClass(ExistsException::class)]
final class ExistsExceptionTest extends TestCase
{
public function testConstruct(): void
Expand All @@ -22,9 +23,7 @@ public function testConstruct(): void
new ExistsException('test', 0);
}

/**
* @dataProvider provideCreateCases
*/
#[DataProvider('provideCreateCases')]
public function testCreate(string $type): void
{
$exception = ExistsException::create('id', $type);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Exceptions/NotFoundExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace Chubbyphp\Tests\Container\Unit\Exceptions;

use Chubbyphp\Container\Exceptions\NotFoundException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @covers \Chubbyphp\Container\Exceptions\NotFoundException
*
* @internal
*/
#[CoversClass(NotFoundException::class)]
final class NotFoundExceptionTest extends TestCase
{
public function testConstruct(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Chubbyphp\Container\Factory;
use Chubbyphp\Mock\MockMethod\WithReturn;
use Chubbyphp\Mock\MockObjectBuilder;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;

/**
* @covers \Chubbyphp\Container\Factory
*
* @internal
*/
#[CoversClass(Factory::class)]
final class FactoryTest extends TestCase
{
public function testInvoke(): void
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/MinimalContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Chubbyphp\Container\Exceptions\ContainerException;
use Chubbyphp\Container\Exceptions\NotFoundException;
use Chubbyphp\Container\MinimalContainer;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;

/**
* @covers \Chubbyphp\Container\MinimalContainer
*
* @internal
*/
#[CoversClass(MinimalContainer::class)]
final class MinimalContainerTest extends TestCase
{
/**
Expand Down Expand Up @@ -104,7 +104,7 @@ public function testFactoryReplace(): void
{
$container = new MinimalContainer();

$container->factory('id', static function (): void {
$container->factory('id', static function (): never {
throw new \Exception('should not be called!');
});

Expand Down
9 changes: 4 additions & 5 deletions tests/Unit/ParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
namespace Chubbyphp\Tests\Container\Unit;

use Chubbyphp\Container\Parameter;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
* @covers \Chubbyphp\Container\Parameter
*
* @internal
*/
#[CoversClass(Parameter::class)]
final class ParameterTest extends TestCase
{
/**
* @dataProvider provideInvokeCases
*/
#[DataProvider('provideInvokeCases')]
public function testInvoke(mixed $data): void
{
$parameter = new Parameter($data);
Expand Down