Skip to content

Commit

Permalink
refactor: remove deprecation & thrown exception & constructor defaults (
Browse files Browse the repository at this point in the history
#2375)

## Description

Refactor `FormModelDescriber`:
- Remove default values from constructor params
- The class is marked as internal so default params are not needed as we
can rely on DI
- Removed impossible deprecation `$mediaTypes` is not nullable
- Removed impossible exception `$formFactory` could never be `null`

## What type of PR is this? (check all applicable)
- [ ] Bug Fix
- [ ] Feature
- [x] Refactor
- [ ] Deprecation
- [ ] Breaking Change
- [ ] Documentation Update
- [ ] CI

## Checklist
- [x] I have made corresponding changes to the documentation (`docs/`)
- [x] I have made corresponding changes to the changelog
(`CHANGELOG.md`)
  • Loading branch information
DjordyKoert authored Nov 1, 2024
1 parent aa71130 commit 1023c9d
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/ModelDescriber/FormModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class FormModelDescriber implements ModelDescriberInterface, ModelRegistry
use ModelRegistryAwareTrait;
use SetsContextTrait;

private ?FormFactoryInterface $formFactory;
private FormFactoryInterface $formFactory;
private ?Reader $doctrineReader;

/**
Expand All @@ -49,34 +49,24 @@ final class FormModelDescriber implements ModelDescriberInterface, ModelRegistry
private bool $isFormCsrfExtensionEnabled;

/**
* @param string[]|null $mediaTypes
* @param string[] $mediaTypes
*/
public function __construct(
?FormFactoryInterface $formFactory = null,
?Reader $reader = null,
?array $mediaTypes = null,
bool $useValidationGroups = false,
bool $isFormCsrfExtensionEnabled = false
FormFactoryInterface $formFactory,
?Reader $reader,
array $mediaTypes,
bool $useValidationGroups,
bool $isFormCsrfExtensionEnabled
) {
$this->formFactory = $formFactory;
$this->doctrineReader = $reader;

if (null === $mediaTypes) {
$mediaTypes = ['json'];

trigger_deprecation('nelmio/api-doc-bundle', '4.1', 'Not passing media types to the constructor of %s is deprecated and won\'t be allowed in version 5.', self::class);
}
$this->mediaTypes = $mediaTypes;
$this->useValidationGroups = $useValidationGroups;
$this->isFormCsrfExtensionEnabled = $isFormCsrfExtensionEnabled;
}

public function describe(Model $model, OA\Schema $schema): void
{
if (null === $this->formFactory) {
throw new \LogicException('You need to enable forms in your application to use a form as a model.');
}

$class = $model->getType()->getClassName();

$annotationsReader = new AnnotationsReader(
Expand Down

0 comments on commit 1023c9d

Please sign in to comment.