Skip to content

Commit

Permalink
chore: php-cs-fixer run
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Sep 16, 2024
1 parent 2778926 commit f1155a2
Show file tree
Hide file tree
Showing 41 changed files with 185 additions and 103 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
composer.lock
vendor
.phpunit.cache
var
var
.php-cs-fixer.cache
tools
4 changes: 4 additions & 0 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="php-cs-fixer" version="^3.64.0" installed="3.64.0" location="./tools/php-cs-fixer" copy="false"/>
</phive>
40 changes: 40 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/config')
->in(__DIR__ . '/tests')

;

$config = new PhpCsFixer\Config();
return $config->setRules([
'@PER-CS2.0' => true,
'@PER-CS2.0:risky' => true,
'fully_qualified_strict_types' => true,
'global_namespace_import' => [
'import_classes' => false,
'import_constants' => false,
'import_functions' => false,
],
'no_unneeded_import_alias' => true,
'no_unused_imports' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha',
'imports_order' => ['class', 'function', 'const']
],
'declare_strict_types' => true,
'native_function_invocation' => ['include' => ['@compiler_optimized']],
'header_comment' => [
'header' => <<<EOF
This file is part of rekalogika/reconstitutor package.
(c) Priyadi Iman Nurcahyo <https://rekalogika.dev>
For the full copyright and license information, please view the LICENSE file
that was distributed with this source code.
EOF,
]
])
->setFinder($finder)
;
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ psalm:

.PHONY: phpunit
phpunit:
vendor/bin/phpunit
vendor/bin/phpunit

.PHONY: php-cs-fixer
php-cs-fixer: tools/php-cs-fixer
$< fix --config=.php-cs-fixer.dist.php --verbose --allow-risky=yes

.PHONY: tools/php-cs-fixer
tools/php-cs-fixer:
phive install php-cs-fixer
1 change: 1 addition & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Rekalogika\Reconstitutor\Resolver\AttributeReconstitutorResolver;
use Rekalogika\Reconstitutor\Resolver\ClassReconstitutorResolver;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_iterator;

Expand Down
16 changes: 8 additions & 8 deletions config/services_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,52 @@

$services->alias(
'test.' . ClassReconstitutorResolver::class,
ClassReconstitutorResolver::class
ClassReconstitutorResolver::class,
)->public();

$services->alias(
'test.' . AttributeReconstitutorResolver::class,
AttributeReconstitutorResolver::class
AttributeReconstitutorResolver::class,
)->public();

$services->alias(
'test.' . ReconstitutorProcessor::class,
ReconstitutorProcessor::class
ReconstitutorProcessor::class,
)->public();

$services->alias(
'test.' . DoctrineListener::class,
DoctrineListener::class
DoctrineListener::class,
)->public();

if (class_exists(EntityReconstitutor::class)) {
$services->set(EntityReconstitutor::class)
->args([
__DIR__ . '/../var/storage.txt'
__DIR__ . '/../var/storage.txt',
])
->tag('rekalogika.reconstitutor.class');
}

if (class_exists(InterfaceReconstitutor::class)) {
$services->set(InterfaceReconstitutor::class)
->args([
__DIR__ . '/../var/storage.txt'
__DIR__ . '/../var/storage.txt',
])
->tag('rekalogika.reconstitutor.class');
}

if (class_exists(SuperclassReconstitutor::class)) {
$services->set(SuperclassReconstitutor::class)
->args([
__DIR__ . '/../var/storage.txt'
__DIR__ . '/../var/storage.txt',
])
->tag('rekalogika.reconstitutor.class');
}

if (class_exists(AttributeReconstitutor::class)) {
$services->set(AttributeReconstitutor::class)
->args([
__DIR__ . '/../var/storage.txt'
__DIR__ . '/../var/storage.txt',
])
->tag('rekalogika.reconstitutor.attribute');
}
Expand Down
5 changes: 3 additions & 2 deletions src/AbstractAttributeReconstitutor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/reconstitutor package.
*
Expand All @@ -18,8 +20,7 @@
/**
* @extends AbstractReconstitutor<object>
*/
abstract class AbstractAttributeReconstitutor extends AbstractReconstitutor
implements
abstract class AbstractAttributeReconstitutor extends AbstractReconstitutor implements
DirectPropertyAccessorAwareInterface,
AttributeReconstitutorInterface
{
Expand Down
5 changes: 3 additions & 2 deletions src/AbstractClassReconstitutor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/reconstitutor package.
*
Expand All @@ -20,8 +22,7 @@
* @extends AbstractReconstitutor<T>
* @implements ClassReconstitutorInterface<T>
*/
abstract class AbstractClassReconstitutor extends AbstractReconstitutor
implements ClassReconstitutorInterface, DirectPropertyAccessorAwareInterface
abstract class AbstractClassReconstitutor extends AbstractReconstitutor implements ClassReconstitutorInterface, DirectPropertyAccessorAwareInterface
{
use DirectPropertyAccessorAwareTrait;

Expand Down
21 changes: 7 additions & 14 deletions src/AbstractReconstitutor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/reconstitutor package.
*
Expand All @@ -17,24 +19,15 @@
/**
* @template T of object
*/
abstract class AbstractReconstitutor
implements DirectPropertyAccessorAwareInterface
abstract class AbstractReconstitutor implements DirectPropertyAccessorAwareInterface
{
use DirectPropertyAccessorAwareTrait;

public function onCreate(object $object): void
{
}
public function onCreate(object $object): void {}

public function onLoad(object $object): void
{
}
public function onLoad(object $object): void {}

public function onSave(object $object): void
{
}
public function onSave(object $object): void {}

public function onRemove(object $object): void
{
}
public function onRemove(object $object): void {}
}
2 changes: 2 additions & 0 deletions src/Contract/AttributeReconstitutorInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/reconstitutor package.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Contract/ClassReconstitutorInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/reconstitutor package.
*
Expand Down
4 changes: 3 additions & 1 deletion src/Contract/DirectPropertyAccessorAwareInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/reconstitutor package.
*
Expand All @@ -16,6 +18,6 @@
interface DirectPropertyAccessorAwareInterface
{
public function setDirectPropertyAccessor(
DirectPropertyAccessor $propertyAccessor
DirectPropertyAccessor $propertyAccessor,
): void;
}
4 changes: 3 additions & 1 deletion src/Contract/DirectPropertyAccessorAwareTrait.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/reconstitutor package.
*
Expand All @@ -18,7 +20,7 @@ trait DirectPropertyAccessorAwareTrait
private DirectPropertyAccessor $propertyAccessor;

public function setDirectPropertyAccessor(
DirectPropertyAccessor $propertyAccessor
DirectPropertyAccessor $propertyAccessor,
): void {
$this->propertyAccessor = $propertyAccessor;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Contract/ReconstitutorInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/reconstitutor package.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Contract/ReconstitutorResolverInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/reconstitutor package.
*
Expand Down
16 changes: 8 additions & 8 deletions src/DependencyInjection/AttributeReconstitutorPass.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/reconstitutor package.
*
Expand All @@ -19,10 +21,8 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;


class AttributeReconstitutorPass implements CompilerPassInterface
{

public function process(ContainerBuilder $container): void
{
$reconstitutorResolver = $container
Expand All @@ -42,32 +42,32 @@ public function process(ContainerBuilder $container): void
foreach ($attributeReconstitutors as $id => $service) {
$definition = $container->getDefinition($id);
$reconstitutorClass = $definition->getClass();
assert(is_string($reconstitutorClass));
assert(class_exists($reconstitutorClass));
\assert(\is_string($reconstitutorClass));
\assert(class_exists($reconstitutorClass));

if (!$r = $container->getReflectionClass($reconstitutorClass)) {
throw new \InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $reconstitutorClass, $id));
throw new \InvalidArgumentException(\sprintf('Class "%s" used for service "%s" cannot be found.', $reconstitutorClass, $id));
}

if ($r->isInterface()) {
continue;
}

if (!$r->isSubclassOf(AttributeReconstitutorInterface::class)) {
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, AttributeReconstitutorInterface::class));
throw new \InvalidArgumentException(\sprintf('Service "%s" must implement interface "%s".', $id, AttributeReconstitutorInterface::class));
}

$reconstitutorClass = $r->name;
$targetClass = $reconstitutorClass::getAttributeClass();

if (!$r = $container->getReflectionClass($targetClass)) {
throw new \InvalidArgumentException(sprintf('Class "%s" used by reconstitutor "%s" cannot be found.', $targetClass, $reconstitutorClass));
throw new \InvalidArgumentException(\sprintf('Class "%s" used by reconstitutor "%s" cannot be found.', $targetClass, $reconstitutorClass));
}

if (is_a($reconstitutorClass, DirectPropertyAccessorAwareInterface::class, true)) {
$definition->addMethodCall(
'setDirectPropertyAccessor',
[$directPropertyAccessor]
[$directPropertyAccessor],
);
}

Expand Down
16 changes: 8 additions & 8 deletions src/DependencyInjection/ClassReconstitutorPass.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/reconstitutor package.
*
Expand All @@ -19,10 +21,8 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;


class ClassReconstitutorPass implements CompilerPassInterface
{

public function process(ContainerBuilder $container): void
{
$reconstitutorResolver = $container
Expand All @@ -42,28 +42,28 @@ public function process(ContainerBuilder $container): void
foreach ($classReconstitutors as $id => $service) {
$definition = $container->getDefinition($id);
$reconstitutorClass = $definition->getClass();
assert(is_string($reconstitutorClass));
assert(class_exists($reconstitutorClass));
\assert(\is_string($reconstitutorClass));
\assert(class_exists($reconstitutorClass));

if (!$r = $container->getReflectionClass($reconstitutorClass)) {
throw new \InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $reconstitutorClass, $id));
throw new \InvalidArgumentException(\sprintf('Class "%s" used for service "%s" cannot be found.', $reconstitutorClass, $id));
}

if (!$r->isSubclassOf(ClassReconstitutorInterface::class)) {
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, ClassReconstitutorInterface::class));
throw new \InvalidArgumentException(\sprintf('Service "%s" must implement interface "%s".', $id, ClassReconstitutorInterface::class));
}

$reconstitutorClass = $r->name;
$targetClass = $reconstitutorClass::getClass();

if (!$r = $container->getReflectionClass($targetClass)) {
throw new \InvalidArgumentException(sprintf('Class "%s" used by reconstitutor "%s" cannot be found.', $targetClass, $reconstitutorClass));
throw new \InvalidArgumentException(\sprintf('Class "%s" used by reconstitutor "%s" cannot be found.', $targetClass, $reconstitutorClass));
}

if (is_a($reconstitutorClass, DirectPropertyAccessorAwareInterface::class, true)) {
$definition->addMethodCall(
'setDirectPropertyAccessor',
[$directPropertyAccessor]
[$directPropertyAccessor],
);
}

Expand Down
Loading

0 comments on commit f1155a2

Please sign in to comment.