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

Use easy coding standard. #63

Merged
merged 5 commits into from
Feb 11, 2023
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ jobs:

- name: Run phpunit
run: composer test

- name: Run easy coding standard
run: composer cs-check
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@
"doctrine/orm": "^2.5",
"php-coveralls/php-coveralls": "^2.0",
"symfony/yaml": "^4.0 | ^5.0 | ^6.0",
"friendsofphp/php-cs-fixer": "^3.4",
"phpstan/phpstan": "^1.3",
"phpspec/prophecy-phpunit": "^2.0",
"laminas/laminas-hydrator": "^4.2",
"laminas/laminas-validator": "^2.14",
"laminas/laminas-filter": "^2.11",
"laminas/laminas-form": "^3.0",
"laminas/laminas-inputfilter": "^2.12",
"bnf/phpstan-psr-container": "^1.0"
"bnf/phpstan-psr-container": "^1.0",
"symplify/easy-coding-standard": "^11.2",
"doctrine/annotations": "^2.0"
},
"extra": {
"zf": {
Expand All @@ -73,6 +74,8 @@
}
},
"scripts": {
"cs-check": "ecs check",
"cs-fix": "ecs check --fix",
"phpstan": "./vendor/bin/phpstan analyse -c phpstan.neon",
"test": "vendor/bin/phpunit --no-coverage",
"test-with-coverage": "vendor/bin/phpunit --coverage-clover=build/coverage.xml",
Expand Down
38 changes: 20 additions & 18 deletions config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<?php

declare(strict_types=1);

return [
'service_manager' => [
'factories' => [
\Reinfi\DependencyInjection\Config\ModuleConfig::class => \Reinfi\DependencyInjection\Config\Factory\ModuleConfigFactory::class,
\Reinfi\DependencyInjection\Service\Extractor\AnnotationExtractor::class => \Reinfi\DependencyInjection\Service\Extractor\Factory\AnnotationExtractorFactory::class,
\Reinfi\DependencyInjection\Service\Extractor\AttributeExtractor::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
\Reinfi\DependencyInjection\Service\Extractor\YamlExtractor::class => \Reinfi\DependencyInjection\Service\Extractor\Factory\YamlExtractorFactory::class,
\Reinfi\DependencyInjection\Service\InjectionService::class => \Reinfi\DependencyInjection\Service\Factory\InjectionServiceFactory::class,
\Reinfi\DependencyInjection\Service\CacheService::class => \Reinfi\DependencyInjection\Service\Factory\CacheServiceFactory::class,
\Reinfi\DependencyInjection\Service\ConfigService::class => \Reinfi\DependencyInjection\Service\Factory\ConfigServiceFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiringService::class => \Reinfi\DependencyInjection\Service\Factory\AutoWiringServiceFactory::class,
\Reinfi\DependencyInjection\Service\Extractor\ExtractorInterface::class => \Reinfi\DependencyInjection\Service\Extractor\Factory\ExtractorFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\ResolverService::class => \Reinfi\DependencyInjection\Service\AutoWiring\Factory\ResolverServiceFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\LazyResolverService::class => \Reinfi\DependencyInjection\Service\AutoWiring\Factory\LazyResolverServiceFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\Resolver\ContainerResolver::class => \Reinfi\DependencyInjection\Service\AutoWiring\Resolver\Factory\ContainerResolverFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\Resolver\ContainerInterfaceResolver::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\Resolver\PluginManagerResolver::class => \Reinfi\DependencyInjection\Service\AutoWiring\Resolver\Factory\PluginManagerResolverFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\Resolver\RequestResolver::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\Resolver\ResponseResolver::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\Resolver\TranslatorResolver::class => \Reinfi\DependencyInjection\Service\AutoWiring\Resolver\Factory\TranslatorResolverFactory::class,
'factories' => [
\Reinfi\DependencyInjection\Config\ModuleConfig::class => \Reinfi\DependencyInjection\Config\Factory\ModuleConfigFactory::class,
\Reinfi\DependencyInjection\Service\Extractor\AnnotationExtractor::class => \Reinfi\DependencyInjection\Service\Extractor\Factory\AnnotationExtractorFactory::class,
\Reinfi\DependencyInjection\Service\Extractor\AttributeExtractor::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
\Reinfi\DependencyInjection\Service\Extractor\YamlExtractor::class => \Reinfi\DependencyInjection\Service\Extractor\Factory\YamlExtractorFactory::class,
\Reinfi\DependencyInjection\Service\InjectionService::class => \Reinfi\DependencyInjection\Service\Factory\InjectionServiceFactory::class,
\Reinfi\DependencyInjection\Service\CacheService::class => \Reinfi\DependencyInjection\Service\Factory\CacheServiceFactory::class,
\Reinfi\DependencyInjection\Service\ConfigService::class => \Reinfi\DependencyInjection\Service\Factory\ConfigServiceFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiringService::class => \Reinfi\DependencyInjection\Service\Factory\AutoWiringServiceFactory::class,
\Reinfi\DependencyInjection\Service\Extractor\ExtractorInterface::class => \Reinfi\DependencyInjection\Service\Extractor\Factory\ExtractorFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\ResolverService::class => \Reinfi\DependencyInjection\Service\AutoWiring\Factory\ResolverServiceFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\LazyResolverService::class => \Reinfi\DependencyInjection\Service\AutoWiring\Factory\LazyResolverServiceFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\Resolver\ContainerResolver::class => \Reinfi\DependencyInjection\Service\AutoWiring\Resolver\Factory\ContainerResolverFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\Resolver\ContainerInterfaceResolver::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\Resolver\PluginManagerResolver::class => \Reinfi\DependencyInjection\Service\AutoWiring\Resolver\Factory\PluginManagerResolverFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\Resolver\RequestResolver::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\Resolver\ResponseResolver::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\Resolver\TranslatorResolver::class => \Reinfi\DependencyInjection\Service\AutoWiring\Resolver\Factory\TranslatorResolverFactory::class,
\Reinfi\DependencyInjection\Service\AutoWiring\Resolver\BuildInTypeWithDefaultResolver::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,

\Reinfi\DependencyInjection\Command\CacheWarmupCommand::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
Expand Down
26 changes: 26 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $configurator): void {
// make ECS 16x faster
$configurator->parallel();

$configurator->paths([
__DIR__ . '/config/',
__DIR__ . '/src/',
__DIR__ . '/test/',
]);

// import SetList here in the end of ecs. is on purpose
// to avoid overridden by existing Skip Option in current config
$configurator->import(SetList::PSR_12);
$configurator->import(SetList::COMMON);
$configurator->import(SetList::NAMESPACES);
$configurator->import(SetList::CLEAN_CODE);

$configurator->lineEnding("\n");
};
30 changes: 11 additions & 19 deletions src/AbstractFactory/Config/InjectConfigAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,10 @@ class InjectConfigAbstractFactory implements AbstractFactoryInterface
{
private const MATCH_PATTERN = '/^Config\.(.*)$/';

/**
* @var array
*/
private array $matches = [];

/**
* @inheritDoc
*/
public function canCreate(
ContainerInterface $container,
$requestedName
): bool {
return preg_match(
self::MATCH_PATTERN,
$requestedName,
$this->matches
) === 1;
}

/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
*
* @return mixed|object|null
*/
Expand All @@ -51,4 +32,15 @@ public function __invoke(

return $configService->resolve($this->matches[1]);
}

public function canCreate(
ContainerInterface $container,
$requestedName
): bool {
return preg_match(
self::MATCH_PATTERN,
$requestedName,
$this->matches
) === 1;
}
}
25 changes: 10 additions & 15 deletions src/AbstractFactory/FallbackAutoWiringFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Reinfi\DependencyInjection\AbstractFactory;
Expand All @@ -19,23 +20,8 @@
class FallbackAutoWiringFactory implements AbstractFactoryInterface
{
/**
* @param ContainerInterface $container
* @param class-string $requestedName
*
* @return bool
*/
public function canCreate(
ContainerInterface $container,
$requestedName
): bool {
return class_exists($requestedName);
}

/**
* @param ContainerInterface $container
* @param class-string $requestedName
* @param array|null $options
*
* @return mixed
*/
public function __invoke(
Expand All @@ -46,4 +32,13 @@ public function __invoke(
return (new AutoWiringFactory())($container, $requestedName, $options);
}

/**
* @param class-string $requestedName
*/
public function canCreate(
ContainerInterface $container,
$requestedName
): bool {
return class_exists($requestedName);
}
}
13 changes: 2 additions & 11 deletions src/Annotation/AbstractInjectPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ abstract class AbstractInjectPluginManager extends AbstractAnnotation

private string $name;

/**
* @var array|null
*/
private ?array $options = null;

/**
* @param array $values
*/
public function __construct(array $values)
{
if (!isset($values['value'])) {
if (! isset($values['value'])) {
if (isset($values['options'])) {
$this->options = $values['options'];
}
Expand All @@ -40,15 +34,12 @@ public function __construct(array $values)
$this->name = $values['value'];
}

/**
* @inheritDoc
*/
public function __invoke(ContainerInterface $container)
{
$container = $this->determineContainer($container);
$pluginManagerImplementation = $container->get(static::PLUGIN_MANAGER);

if (!$pluginManagerImplementation instanceof AbstractPluginManager) {
if (! $pluginManagerImplementation instanceof AbstractPluginManager) {
throw InjectionNotPossibleException::fromUnknownPluginManager(static::PLUGIN_MANAGER);
}

Expand Down
3 changes: 0 additions & 3 deletions src/Annotation/Inject.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ final class Inject implements AnnotationInterface
*/
public $value;

/**
* @inheritDoc
*/
public function __invoke(ContainerInterface $container)
{
return $container->get($this->value);
Expand Down
13 changes: 1 addition & 12 deletions src/Annotation/InjectConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,10 @@
*/
final class InjectConfig extends AbstractAnnotation
{
/**
* @var string
*/
private string $configPath;

/**
* @var bool
*/
private bool $asArray = false;

/**
* @param array $values
*/
public function __construct(array $values)
{
if (isset($values['asArray'])) {
Expand All @@ -37,9 +28,7 @@ public function __construct(array $values)

$this->configPath = $values['value'];
}
/**
* @inheritDoc
*/

public function __invoke(ContainerInterface $container)
{
$container = $this->determineContainer($container);
Expand Down
3 changes: 0 additions & 3 deletions src/Annotation/InjectConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ final class InjectConstant implements AnnotationInterface
*/
public $value;

/**
* @inheritDoc
*/
public function __invoke(ContainerInterface $container)
{
return constant($this->value);
Expand Down
3 changes: 0 additions & 3 deletions src/Annotation/InjectContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
*/
final class InjectContainer implements AnnotationInterface
{
/**
* @inheritDoc
*/
public function __invoke(ContainerInterface $container)
{
return $container;
Expand Down
2 changes: 0 additions & 2 deletions src/Annotation/InjectControllerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Reinfi\DependencyInjection\Annotation;

use Attribute;

/**
* @package Reinfi\DependencyInjection\Annotation
*
Expand Down
13 changes: 3 additions & 10 deletions src/Annotation/InjectDoctrineRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ final class InjectDoctrineRepository extends AbstractAnnotation

private string $entity;

/**
* @param array $values
*/
public function __construct(array $values)
{
if (!isset($values['value'])) {
if (! isset($values['value'])) {
if (isset($values['em']) || isset($values['entityManager'])) {
$this->entityManager = $values['entityManager'] ?? $values['em'];
}
Expand All @@ -34,22 +31,18 @@ public function __construct(array $values)
return;
}


$this->entity = $values['value'];
}

/**
* @inheritDoc
*/
public function __invoke(ContainerInterface $container)
{
$container = $this->determineContainer($container);

$entityManager = $container->get($this->entityManager);

if (
!is_object($entityManager)
|| !method_exists($entityManager, 'getRepository')
! is_object($entityManager)
|| ! method_exists($entityManager, 'getRepository')
) {
throw new AutoWiringNotPossibleException($this->entity);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Annotation/InjectParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Reinfi\DependencyInjection\Annotation;

use Psr\Container\ContainerInterface;
use Laminas\ServiceManager\AbstractPluginManager;
use Psr\Container\ContainerInterface;

/**
* @package Reinfi\DependencyInjection\Annotation
Expand All @@ -20,9 +20,6 @@ final class InjectParent implements AnnotationInterface
*/
public $value;

/**
* @inheritDoc
*/
public function __invoke(ContainerInterface $container)
{
if ($container instanceof AbstractPluginManager) {
Expand Down
8 changes: 1 addition & 7 deletions src/Attribute/AbstractInjectPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ abstract class AbstractInjectPluginManager extends AbstractAttribute

private string $name;

/**
* @var array|null
*/
private ?array $options;

public function __construct(string $name, ?array $options = null)
Expand All @@ -28,15 +25,12 @@ public function __construct(string $name, ?array $options = null)
$this->options = $options;
}

/**
* @inheritDoc
*/
public function __invoke(ContainerInterface $container)
{
$container = $this->determineContainer($container);
$pluginManagerImplementation = $container->get(static::PLUGIN_MANAGER);

if (!$pluginManagerImplementation instanceof AbstractPluginManager) {
if (! $pluginManagerImplementation instanceof AbstractPluginManager) {
throw InjectionNotPossibleException::fromUnknownPluginManager(static::PLUGIN_MANAGER);
}

Expand Down
3 changes: 0 additions & 3 deletions src/Attribute/Inject.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ public function __construct(string $value)
$this->value = $value;
}

/**
* @inheritDoc
*/
public function __invoke(ContainerInterface $container)
{
return $container->get($this->value);
Expand Down
Loading