From f1155a27ddba829076fe312da39a60ecdc1934b6 Mon Sep 17 00:00:00 2001
From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com>
Date: Mon, 16 Sep 2024 14:42:15 +0700
Subject: [PATCH] chore: php-cs-fixer run
---
.gitignore | 4 +-
.phive/phars.xml | 4 ++
.php-cs-fixer.dist.php | 40 +++++++++++++++++++
Makefile | 10 ++++-
config/services.php | 1 +
config/services_test.php | 16 ++++----
src/AbstractAttributeReconstitutor.php | 5 ++-
src/AbstractClassReconstitutor.php | 5 ++-
src/AbstractReconstitutor.php | 21 ++++------
.../AttributeReconstitutorInterface.php | 2 +
src/Contract/ClassReconstitutorInterface.php | 2 +
.../DirectPropertyAccessorAwareInterface.php | 4 +-
.../DirectPropertyAccessorAwareTrait.php | 4 +-
src/Contract/ReconstitutorInterface.php | 2 +
.../ReconstitutorResolverInterface.php | 2 +
.../AttributeReconstitutorPass.php | 16 ++++----
.../ClassReconstitutorPass.php | 16 ++++----
.../RekalogikaReconstitutorExtension.php | 4 +-
src/Doctrine/DoctrineListener.php | 6 +--
src/ReconstitutorProcessor.php | 8 ++--
src/RekalogikaReconstitutorBundle.php | 2 +
.../AttributeReconstitutorResolver.php | 10 ++---
src/Resolver/ClassReconstitutorResolver.php | 14 +++----
tests/IntegrationTest.php | 6 ++-
tests/Model/AbstractStub.php | 6 +--
tests/Model/Entity.php | 6 +--
tests/Model/EntityExtendingAbstractStub.php | 6 +--
.../Model/EntityImplementingStubInterface.php | 6 +--
tests/Model/EntityTrait.php | 2 +
tests/Model/EntityWithAttribute.php | 6 +--
tests/Model/EntityWithAttributeSubclass.php | 6 +--
tests/Model/StubAttribute.php | 6 +--
tests/Model/StubInterface.php | 6 +--
.../AbstractTestClassReconstitutor.php | 2 +
.../Reconstitutor/AttributeReconstitutor.php | 4 +-
tests/Reconstitutor/CommonTrait.php | 12 +++---
tests/Reconstitutor/EntityReconstitutor.php | 2 +
.../Reconstitutor/InterfaceReconstitutor.php | 2 +
.../Reconstitutor/SuperclassReconstitutor.php | 2 +
tests/ReconstitutorKernel.php | 6 +--
tests/ReconstitutorTest.php | 4 +-
41 files changed, 185 insertions(+), 103 deletions(-)
create mode 100644 .phive/phars.xml
create mode 100644 .php-cs-fixer.dist.php
diff --git a/.gitignore b/.gitignore
index 7f07e6f..5a6d7d4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
composer.lock
vendor
.phpunit.cache
-var
\ No newline at end of file
+var
+.php-cs-fixer.cache
+tools
\ No newline at end of file
diff --git a/.phive/phars.xml b/.phive/phars.xml
new file mode 100644
index 0000000..2b1f5c8
--- /dev/null
+++ b/.phive/phars.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
new file mode 100644
index 0000000..331cc22
--- /dev/null
+++ b/.php-cs-fixer.dist.php
@@ -0,0 +1,40 @@
+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' => <<
+
+For the full copyright and license information, please view the LICENSE file
+that was distributed with this source code.
+EOF,
+ ]
+ ])
+ ->setFinder($finder)
+;
diff --git a/Makefile b/Makefile
index b15a5e0..e3d4eca 100644
--- a/Makefile
+++ b/Makefile
@@ -11,4 +11,12 @@ psalm:
.PHONY: phpunit
phpunit:
- vendor/bin/phpunit
\ No newline at end of file
+ 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
\ No newline at end of file
diff --git a/config/services.php b/config/services.php
index 6534ab4..6a0c8d6 100644
--- a/config/services.php
+++ b/config/services.php
@@ -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;
diff --git a/config/services_test.php b/config/services_test.php
index ac7d2bf..0fee423 100644
--- a/config/services_test.php
+++ b/config/services_test.php
@@ -26,28 +26,28 @@
$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');
}
@@ -55,7 +55,7 @@
if (class_exists(InterfaceReconstitutor::class)) {
$services->set(InterfaceReconstitutor::class)
->args([
- __DIR__ . '/../var/storage.txt'
+ __DIR__ . '/../var/storage.txt',
])
->tag('rekalogika.reconstitutor.class');
}
@@ -63,7 +63,7 @@
if (class_exists(SuperclassReconstitutor::class)) {
$services->set(SuperclassReconstitutor::class)
->args([
- __DIR__ . '/../var/storage.txt'
+ __DIR__ . '/../var/storage.txt',
])
->tag('rekalogika.reconstitutor.class');
}
@@ -71,7 +71,7 @@
if (class_exists(AttributeReconstitutor::class)) {
$services->set(AttributeReconstitutor::class)
->args([
- __DIR__ . '/../var/storage.txt'
+ __DIR__ . '/../var/storage.txt',
])
->tag('rekalogika.reconstitutor.attribute');
}
diff --git a/src/AbstractAttributeReconstitutor.php b/src/AbstractAttributeReconstitutor.php
index 461f9b2..bf256d6 100644
--- a/src/AbstractAttributeReconstitutor.php
+++ b/src/AbstractAttributeReconstitutor.php
@@ -1,5 +1,7 @@
*/
-abstract class AbstractAttributeReconstitutor extends AbstractReconstitutor
-implements
+abstract class AbstractAttributeReconstitutor extends AbstractReconstitutor implements
DirectPropertyAccessorAwareInterface,
AttributeReconstitutorInterface
{
diff --git a/src/AbstractClassReconstitutor.php b/src/AbstractClassReconstitutor.php
index a8ade09..c6b5a33 100644
--- a/src/AbstractClassReconstitutor.php
+++ b/src/AbstractClassReconstitutor.php
@@ -1,5 +1,7 @@
* @implements ClassReconstitutorInterface
*/
-abstract class AbstractClassReconstitutor extends AbstractReconstitutor
-implements ClassReconstitutorInterface, DirectPropertyAccessorAwareInterface
+abstract class AbstractClassReconstitutor extends AbstractReconstitutor implements ClassReconstitutorInterface, DirectPropertyAccessorAwareInterface
{
use DirectPropertyAccessorAwareTrait;
diff --git a/src/AbstractReconstitutor.php b/src/AbstractReconstitutor.php
index 6e68672..7a5d505 100644
--- a/src/AbstractReconstitutor.php
+++ b/src/AbstractReconstitutor.php
@@ -1,5 +1,7 @@
propertyAccessor = $propertyAccessor;
}
diff --git a/src/Contract/ReconstitutorInterface.php b/src/Contract/ReconstitutorInterface.php
index 982791b..38a0592 100644
--- a/src/Contract/ReconstitutorInterface.php
+++ b/src/Contract/ReconstitutorInterface.php
@@ -1,5 +1,7 @@
$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()) {
@@ -54,20 +54,20 @@ public function process(ContainerBuilder $container): void
}
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],
);
}
diff --git a/src/DependencyInjection/ClassReconstitutorPass.php b/src/DependencyInjection/ClassReconstitutorPass.php
index fb2cb20..a2a36de 100644
--- a/src/DependencyInjection/ClassReconstitutorPass.php
+++ b/src/DependencyInjection/ClassReconstitutorPass.php
@@ -1,5 +1,7 @@
$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],
);
}
diff --git a/src/DependencyInjection/RekalogikaReconstitutorExtension.php b/src/DependencyInjection/RekalogikaReconstitutorExtension.php
index 7e535af..b6c1c3b 100644
--- a/src/DependencyInjection/RekalogikaReconstitutorExtension.php
+++ b/src/DependencyInjection/RekalogikaReconstitutorExtension.php
@@ -1,5 +1,7 @@
load('services.php');
diff --git a/src/Doctrine/DoctrineListener.php b/src/Doctrine/DoctrineListener.php
index def8d8d..01b0e48 100644
--- a/src/Doctrine/DoctrineListener.php
+++ b/src/Doctrine/DoctrineListener.php
@@ -1,5 +1,7 @@
$resolvers
*/
- public function __construct(private iterable $resolvers)
- {
- }
+ public function __construct(private iterable $resolvers) {}
/**
* @return iterable>
diff --git a/src/RekalogikaReconstitutorBundle.php b/src/RekalogikaReconstitutorBundle.php
index afa4412..3bd565c 100644
--- a/src/RekalogikaReconstitutorBundle.php
+++ b/src/RekalogikaReconstitutorBundle.php
@@ -1,5 +1,7 @@
> $classMap
*/
- public function __construct(private array $classMap)
- {
- }
+ public function __construct(private array $classMap) {}
public function getReconstitutors(object $object): iterable
{
- $class = get_class($object);
+ $class = \get_class($object);
if (isset($this->cache[$class])) {
return $this->cache[$class];
- }
+ }
$reconstitutors = [];
diff --git a/src/Resolver/ClassReconstitutorResolver.php b/src/Resolver/ClassReconstitutorResolver.php
index 6559f26..3988836 100644
--- a/src/Resolver/ClassReconstitutorResolver.php
+++ b/src/Resolver/ClassReconstitutorResolver.php
@@ -1,5 +1,7 @@
>> $classMap
*/
- public function __construct(private array $classMap)
- {
- }
+ public function __construct(private array $classMap) {}
/**
* @return array
*/
private static function getAllClasses(object $object): array
{
- $classes = \array_merge(
+ $classes = array_merge(
[\get_class($object)],
class_parents($object),
- class_implements($object)
+ class_implements($object),
);
- return \array_unique($classes);
+ return array_unique($classes);
}
/**
@@ -51,7 +51,7 @@ public function getReconstitutors(object $object): iterable
continue;
}
- $reconstitutors = \array_merge($reconstitutors, $this->classMap[$class]);
+ $reconstitutors = array_merge($reconstitutors, $this->classMap[$class]);
}
return $reconstitutors;
diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php
index 4d71775..27d96aa 100644
--- a/tests/IntegrationTest.php
+++ b/tests/IntegrationTest.php
@@ -1,5 +1,7 @@
assertInstanceOf(
ClassReconstitutorResolver::class,
- $classReconstitutorResolver
+ $classReconstitutorResolver,
);
$attributeReconstitutorResolver = $container
@@ -36,7 +38,7 @@ public function testServiceWiring(): void
$this->assertInstanceOf(
AttributeReconstitutorResolver::class,
- $attributeReconstitutorResolver
+ $attributeReconstitutorResolver,
);
}
}
diff --git a/tests/Model/AbstractStub.php b/tests/Model/AbstractStub.php
index ea62a55..e245b4a 100644
--- a/tests/Model/AbstractStub.php
+++ b/tests/Model/AbstractStub.php
@@ -1,5 +1,7 @@
get($object, 'attribute');
- assert(is_string($value));
+ \assert(\is_string($value));
file_put_contents($this->fileStorage, $value);
}
@@ -31,7 +31,7 @@ public function onLoad(object $object): void
$value = null;
} else {
$value = file_get_contents($this->fileStorage);
- assert(is_string($value));
+ \assert(\is_string($value));
}
$this->set($object, 'attribute', $value);
diff --git a/tests/Reconstitutor/EntityReconstitutor.php b/tests/Reconstitutor/EntityReconstitutor.php
index cfcebbd..ac932c4 100644
--- a/tests/Reconstitutor/EntityReconstitutor.php
+++ b/tests/Reconstitutor/EntityReconstitutor.php
@@ -1,5 +1,7 @@
assertTrue(class_exists($entityClass));
- $entity = new $entityClass;
+ $entity = new $entityClass();
$entity->setAttribute('foo');
$processor->onSave($entity);