Skip to content
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
48 changes: 48 additions & 0 deletions .github/workflows/cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: cs fixer

on:
pull_request_target:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

jobs:
fix:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.4
tools: composer:v2
coverage: none

- name: Install Composer dependencies
uses: "ramsey/composer-install@v3"

- name: Run Rector
run: compose

- name: Run PHP CS Fixer
run: composer php-cs-fixer

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Apply PHP CS Fixer and Rector changes (CI)"
file_pattern: '*.php'
disable_globbing: true
24 changes: 0 additions & 24 deletions .github/workflows/rector.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ composer.phar
/phpunit.phar
/phpunit.xml
/.phpunit.cache

# PHP CS Fixer
/.php-cs-fixer.cache
20 changes: 20 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

$finder = (new Finder())->in([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

return (new Config())
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@PER-CS2.0' => true,
'no_unused_imports' => true,
])
->setFinder($finder);
85 changes: 0 additions & 85 deletions .styleci.yml

This file was deleted.

3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"psr/container": "^1.0 || ^2.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.69",
"maglnet/composer-require-checker": "^4.7.1",
"phpunit/phpunit": "^10.5.45",
"rector/rector": "^2.0.9",
Expand Down Expand Up @@ -57,6 +58,8 @@
}
},
"scripts": {
"php-cs-fixer": "php-cs-fixer fix",
"rector": "rector",
"test": "phpunit --testdox --no-interaction",
"test-watch": "phpunit-watcher watch"
}
Expand Down
8 changes: 5 additions & 3 deletions docs/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ The code is statically analyzed with [Psalm](https://psalm.dev/). To run static

## Code style

Use [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or
use either newest or any specific version of PHP:
Package used [PHP CS Fixer](https://cs.symfony.com/) to maintain [PER CS 2.0](https://www.php-fig.org/per/coding-style/)
code style and [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or use either
newest or any specific version of PHP:

```shell
./vendor/bin/rector
composer php-cs-fixer
composer rector
```

## Dependencies
Expand Down
19 changes: 9 additions & 10 deletions src/ArrayDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ final class ArrayDefinition implements DefinitionInterface
private function __construct(
private string $class,
private array $constructorArguments,
private array $methodsAndProperties
) {
}
private array $methodsAndProperties,
) {}

/**
* @param ContainerInterface|null $referenceContainer Container to resolve references with.
Expand All @@ -72,7 +71,7 @@ public static function fromConfig(array $config): self
return new self(
$config[self::CLASS_NAME],
$config[self::CONSTRUCTOR] ?? [],
self::getMethodsAndPropertiesFromConfig($config)
self::getMethodsAndPropertiesFromConfig($config),
);
}

Expand Down Expand Up @@ -142,7 +141,7 @@ public function resolve(ContainerInterface $container): object
$resolvedConstructorArguments = $this->resolveFunctionArguments(
$container,
DefinitionExtractor::fromClassName($class),
$this->getConstructorArguments()
$this->getConstructorArguments(),
);

/** @psalm-suppress MixedMethodCall */
Expand Down Expand Up @@ -182,7 +181,7 @@ public function resolve(ContainerInterface $container): object
private function resolveFunctionArguments(
ContainerInterface $container,
array $dependencies,
array $arguments
array $arguments,
): array {
$isIntegerIndexed = $this->isIntegerIndexed($arguments);
$dependencyIndex = 0;
Expand All @@ -209,7 +208,7 @@ private function resolveFunctionArguments(
$arguments[$variadicKey] = DefinitionResolver::resolve(
$container,
$this->referenceContainer,
$arguments[$variadicKey]
$arguments[$variadicKey],
);
}

Expand All @@ -220,8 +219,8 @@ private function resolveFunctionArguments(
throw new InvalidArgumentException(
sprintf(
'Named argument for a variadic parameter should be an array, "%s" given.',
gettype($arguments[$variadicKey])
)
gettype($arguments[$variadicKey]),
),
);
}
} else {
Expand Down Expand Up @@ -262,7 +261,7 @@ private function isIntegerIndexed(array $arguments): bool
}
if ($hasIntegerIndex && $hasStringIndex) {
throw new InvalidConfigException(
'Arguments indexed both by name and by position are not allowed in the same array.'
'Arguments indexed both by name and by position are not allowed in the same array.',
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/CallableDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public function resolve(ContainerInterface $container): mixed
{
try {
$reflection = new ReflectionFunction(
$this->prepareClosure($this->callable, $container)
$this->prepareClosure($this->callable, $container),
);
} catch (ReflectionException) {
throw new NotInstantiableException(
'Can not instantiate callable definition. Got ' . var_export($this->callable, true)
'Can not instantiate callable definition. Got ' . var_export($this->callable, true),
);
}

Expand Down
11 changes: 5 additions & 6 deletions src/DefinitionStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ final class DefinitionStorage
*/
public function __construct(
private array $definitions = [],
private readonly bool $useStrictMode = false
) {
}
private readonly bool $useStrictMode = false,
) {}

/**
* @param ContainerInterface $delegateContainer Container to fall back to when dependency is not found.
Expand Down Expand Up @@ -113,7 +112,7 @@ private function isResolvable(string $id, array $building): bool
throw new CircularReferenceException(sprintf(
'Circular reference to "%s" detected while building: %s.',
$id,
implode(', ', array_keys($building))
implode(', ', array_keys($building)),
));
}

Expand Down Expand Up @@ -212,8 +211,8 @@ private function isResolvable(string $id, array $building): bool
sprintf(
'Circular reference to "%s" detected while building: %s.',
$id,
implode(', ', array_keys($building))
)
implode(', ', array_keys($building)),
),
);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Exception/CircularReferenceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
* `CircularReferenceException` is thrown when DI configuration contains self-references of any level and thus could not
* be resolved.
*/
final class CircularReferenceException extends NotInstantiableException
{
}
final class CircularReferenceException extends NotInstantiableException {}
4 changes: 1 addition & 3 deletions src/Exception/InvalidConfigException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
/**
* `InvalidConfigException` is thrown when definition configuration is not valid.
*/
final class InvalidConfigException extends Exception implements ContainerExceptionInterface
{
}
final class InvalidConfigException extends Exception implements ContainerExceptionInterface {}
4 changes: 1 addition & 3 deletions src/Exception/NotInstantiableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@
* `NotInstantiableException` represents an exception caused by incorrect dependency injection container or factory
* configuration or usage.
*/
class NotInstantiableException extends Exception implements ContainerExceptionInterface
{
}
class NotInstantiableException extends Exception implements ContainerExceptionInterface {}
1 change: 0 additions & 1 deletion src/Helpers/ArrayDefinitionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Yiisoft\Definitions\Helpers;

use Yiisoft\Definitions\ArrayDefinition;

use Yiisoft\Definitions\Exception\InvalidConfigException;

use function is_array;
Expand Down
6 changes: 3 additions & 3 deletions src/Helpers/DefinitionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class DefinitionResolver
public static function resolveArray(
ContainerInterface $container,
?ContainerInterface $referenceContainer,
array $definitions
array $definitions,
): array {
$result = [];
foreach ($definitions as $key => $definition) {
Expand All @@ -53,7 +53,7 @@ public static function resolveArray(
public static function resolve(
ContainerInterface $container,
?ContainerInterface $referenceContainer,
mixed $definition
mixed $definition,
): mixed {
if ($definition instanceof DefinitionInterface) {
$container = $referenceContainer !== null && $definition instanceof ReferenceInterface
Expand All @@ -79,7 +79,7 @@ public static function ensureResolvable(mixed $value): array|ReferenceInterface|
if ($value instanceof DefinitionInterface) {
throw new InvalidConfigException(
'Only references are allowed in constructor arguments, a definition object was provided: ' .
var_export($value, true)
var_export($value, true),
);
}

Expand Down
Loading
Loading