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

Updated to doctrine-coding-standard v12 #765

Merged
merged 1 commit into from
Dec 30, 2024
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"require-dev": {
"doctrine/annotations": "^2.0.0",
"doctrine/coding-standard": "^9.0.0",
"doctrine/coding-standard": "^12.0.0",
"doctrine/data-fixtures": "^1.5.2",
"doctrine/migrations": "^3.8.0",
"laminas/laminas-cache-storage-adapter-filesystem": "^2.0",
Expand Down
15 changes: 4 additions & 11 deletions src/CliConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ class CliConfigurator
'doctrine.migrations_cmd.uptodate',
];

private ContainerInterface $container;

public function __construct(ContainerInterface $container)
public function __construct(private ContainerInterface $container)
{
$this->container = $container;
}

public function configure(Application $cli): void
Expand All @@ -84,9 +81,7 @@ public function configure(Application $cli): void
}
}

/**
* @return array<string,Helper>
*/
/** @return array<string,Helper> */
private function getHelpers(EntityManagerInterface $objectManager): array
{
return [
Expand All @@ -102,7 +97,7 @@ private function createObjectManagerInputOption(): InputOption
null,
InputOption::VALUE_OPTIONAL,
'The name of the object manager to use.',
$this->defaultObjectManagerName
$this->defaultObjectManagerName,
);
}

Expand All @@ -117,9 +112,7 @@ private function getObjectManagerName(): string
return $arguments->getParameterOption('--object-manager');
}

/**
* @return string[]
*/
/** @return string[] */
private function getAvailableCommands(): array
{
if (class_exists(VersionCommand::class)) {
Expand Down
19 changes: 5 additions & 14 deletions src/Collector/MappingCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@
*/
public const PRIORITY = 10;

protected string $name;

protected ?ClassMetadataFactory $classMetadataFactory = null;
protected ClassMetadataFactory|null $classMetadataFactory = null;

/** @var ClassMetadata[] indexed by class name */
protected array $classes = [];

public function __construct(ClassMetadataFactory $classMetadataFactory, string $name)
public function __construct(ClassMetadataFactory $classMetadataFactory, protected string $name)

Check warning on line 30 in src/Collector/MappingCollector.php

View check run for this annotation

Codecov / codecov/patch

src/Collector/MappingCollector.php#L30

Added line #L30 was not covered by tests
{
$this->classMetadataFactory = $classMetadataFactory;
$this->name = $name;
}

public function getName(): string
Expand Down Expand Up @@ -67,9 +64,7 @@
return empty($this->classes);
}

/**
* @return array{name: string, classes: ClassMetadata[]}
*/
/** @return array{name: string, classes: ClassMetadata[]} */
public function __serialize(): array
{
return [
Expand All @@ -78,18 +73,14 @@
];
}

/**
* @param array{name: string, classes: ClassMetadata[]} $data
*/
/** @param array{name: string, classes: ClassMetadata[]} $data */
public function __unserialize(array $data): void
{
$this->name = $data['name'];
$this->classes = $data['classes'];
}

/**
* @return ClassMetadata[]
*/
/** @return ClassMetadata[] */
public function getClasses(): array
{
return $this->classes;
Expand Down
12 changes: 2 additions & 10 deletions src/Collector/SQLLoggerCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ class SQLLoggerCollector implements CollectorInterface, AutoHideInterface
*/
public const PRIORITY = 10;

protected DebugStack $sqlLogger;

protected string $name;

public function __construct(DebugStack $sqlLogger, string $name)
public function __construct(protected DebugStack $sqlLogger, protected string $name)
{
$this->sqlLogger = $sqlLogger;
$this->name = $name;
}

public function getName(): string
Expand All @@ -55,9 +49,7 @@ public function getQueryCount(): int
return count($this->sqlLogger->queries);
}

/**
* @return mixed[]
*/
/** @return mixed[] */
public function getQueries(): array
{
return $this->sqlLogger->queries;
Expand Down
4 changes: 1 addition & 3 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
*/
final class ConfigProvider
{
/**
* @return mixed[]
*/
/** @return mixed[] */
public function __invoke(): array
{
$config = include __DIR__ . '/../config/module.config.php';
Expand Down
73 changes: 24 additions & 49 deletions src/Form/Annotation/DoctrineAnnotationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@

class DoctrineAnnotationListener extends AbstractListenerAggregate
{
protected ObjectManager $objectManager;

public function __construct(ObjectManager $objectManager)
public function __construct(protected ObjectManager $objectManager)
{
$this->objectManager = $objectManager;
}

/**
Expand All @@ -33,45 +30,43 @@ public function attach(EventManagerInterface $events, $priority = 1)
{
$this->listeners[] = $events->attach(
EntityBasedFormBuilder::EVENT_CONFIGURE_FIELD,
[$this, 'handleFilterField']
[$this, 'handleFilterField'],
);
$this->listeners[] = $events->attach(
EntityBasedFormBuilder::EVENT_CONFIGURE_FIELD,
[$this, 'handleTypeField']
[$this, 'handleTypeField'],
);
$this->listeners[] = $events->attach(
EntityBasedFormBuilder::EVENT_CONFIGURE_FIELD,
[$this, 'handleValidatorField']
[$this, 'handleValidatorField'],
);
$this->listeners[] = $events->attach(
EntityBasedFormBuilder::EVENT_CONFIGURE_FIELD,
[$this, 'handleRequiredField']
[$this, 'handleRequiredField'],
);
$this->listeners[] = $events->attach(
EntityBasedFormBuilder::EVENT_EXCLUDE_FIELD,
[$this, 'handleExcludeField']
[$this, 'handleExcludeField'],
);
$this->listeners[] = $events->attach(
EntityBasedFormBuilder::EVENT_CONFIGURE_ASSOCIATION,
[$this, 'handleToOne']
[$this, 'handleToOne'],
);
$this->listeners[] = $events->attach(
EntityBasedFormBuilder::EVENT_CONFIGURE_ASSOCIATION,
[$this, 'handleToMany']
[$this, 'handleToMany'],
);
$this->listeners[] = $events->attach(
EntityBasedFormBuilder::EVENT_CONFIGURE_ASSOCIATION,
[$this, 'handleRequiredAssociation']
[$this, 'handleRequiredAssociation'],
);
$this->listeners[] = $events->attach(
EntityBasedFormBuilder::EVENT_EXCLUDE_ASSOCIATION,
[$this, 'handleExcludeAssociation']
[$this, 'handleExcludeAssociation'],
);
}

/**
* @internal
*/
/** @internal */
public function handleToOne(EventInterface $event): void
{
$metadata = $event->getParam('metadata');
Expand All @@ -84,9 +79,7 @@ public function handleToOne(EventInterface $event): void
$this->mergeAssociationOptions($event->getParam('elementSpec'), $mapping['targetEntity']);
}

/**
* @internal
*/
/** @internal */
public function handleToMany(EventInterface $event): void
{
$metadata = $event->getParam('metadata');
Expand All @@ -106,19 +99,15 @@ public function handleToMany(EventInterface $event): void
$elementSpec['spec']['attributes']['multiple'] = true;
}

/**
* @internal
*/
/** @internal */
public function handleExcludeAssociation(EventInterface $event): bool
{
$metadata = $event->getParam('metadata');

return $metadata && $metadata->isAssociationInverseSide($event->getParam('name'));
}

/**
* @internal
*/
/** @internal */
public function handleExcludeField(EventInterface $event): bool
{
$metadata = $event->getParam('metadata');
Expand All @@ -128,9 +117,7 @@ public function handleExcludeField(EventInterface $event): bool
$metadata->generatorType === ClassMetadata::GENERATOR_TYPE_IDENTITY;
}

/**
* @internal
*/
/** @internal */
public function handleFilterField(EventInterface $event): void
{
$metadata = $event->getParam('metadata');
Expand Down Expand Up @@ -165,9 +152,7 @@ public function handleFilterField(EventInterface $event): void
}
}

/**
* @internal
*/
/** @internal */
public function handleRequiredAssociation(EventInterface $event): void
{
$metadata = $event->getParam('metadata');
Expand Down Expand Up @@ -206,9 +191,7 @@ public function handleRequiredAssociation(EventInterface $event): void
}
}

/**
* @internal
*/
/** @internal */
public function handleRequiredField(EventInterface $event): void
{
$this->prepareEvent($event);
Expand All @@ -223,9 +206,7 @@ public function handleRequiredField(EventInterface $event): void
$inputSpec['required'] = ! $metadata->isNullable($event->getParam('name'));
}

/**
* @internal
*/
/** @internal */
public function handleTypeField(EventInterface $event): void
{
$metadata = $event->getParam('metadata');
Expand Down Expand Up @@ -281,9 +262,7 @@ public function handleTypeField(EventInterface $event): void
$elementSpec['spec']['type'] = $type;
}

/**
* @internal
*/
/** @internal */
public function handleValidatorField(EventInterface $event): void
{
$mapping = $this->getFieldMapping($event);
Expand Down Expand Up @@ -333,10 +312,8 @@ public function handleValidatorField(EventInterface $event): void
}
}

/**
* @return mixed[]|null
*/
protected function getFieldMapping(EventInterface $event): ?array
/** @return mixed[]|null */
protected function getFieldMapping(EventInterface $event): array|null
{
$metadata = $event->getParam('metadata');
if ($metadata && $metadata->hasField($event->getParam('name'))) {
Expand All @@ -346,10 +323,8 @@ protected function getFieldMapping(EventInterface $event): ?array
return null;
}

/**
* @return mixed[]|null
*/
protected function getAssociationMapping(EventInterface $event): ?array
/** @return mixed[]|null */
protected function getAssociationMapping(EventInterface $event): array|null
{
$metadata = $event->getParam('metadata');
if ($metadata && $metadata->hasAssociation($event->getParam('name'))) {
Expand All @@ -367,7 +342,7 @@ protected function mergeAssociationOptions(ArrayObject $elementSpec, string $tar
'object_manager' => $this->objectManager,
'target_class' => $targetEntity,
],
$options
$options,
);

$elementSpec['spec']['options'] = $options;
Expand Down
13 changes: 4 additions & 9 deletions src/Form/Annotation/EntityBasedFormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,23 @@

protected AbstractBuilder $builder;

protected ObjectManager $objectManager;

/**
* Constructor. Ensures ObjectManager is present.
*/
public function __construct(ObjectManager $objectManager, ?AbstractBuilder $builder = null)
public function __construct(protected ObjectManager $objectManager, AbstractBuilder|null $builder = null)
{
if (! class_exists(AbstractBuilder::class)) {
throw new RuntimeException(sprintf(
'Usage of %s requires laminas-form 3.0.0 or newer, which currently is not installed.',
self::class
self::class,

Check warning on line 45 in src/Form/Annotation/EntityBasedFormBuilder.php

View check run for this annotation

Codecov / codecov/patch

src/Form/Annotation/EntityBasedFormBuilder.php#L45

Added line #L45 was not covered by tests
));
}

$this->objectManager = $objectManager;
$this->builder = $builder ?? new LaminasAnnotationBuilder();
$this->builder = $builder ?? new LaminasAnnotationBuilder();
(new DoctrineAnnotationListener($this->objectManager))->attach($this->builder->getEventManager());
}

/**
* @return AbstractBuilder the form builder from laminas-form
*/
/** @return AbstractBuilder the form builder from laminas-form */
public function getBuilder(): AbstractBuilder
{
return $this->builder;
Expand Down
4 changes: 2 additions & 2 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static function (EventInterface $event): void {
->get(CliConfigurator::class)
->configure($event->getTarget());
},
1
1,
);

// Initialize logger collector in DeveloperTools
Expand All @@ -54,7 +54,7 @@ static function (EventInterface $event): void {
static function ($event): void {
$container = $event->getTarget()->getParam('ServiceManager');
$container->get('doctrine.sql_logger_collector.orm_default');
}
},
);
}

Expand Down
Loading