Skip to content

Commit

Permalink
refactor: remove deprecation & thrown exception & constructor defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Nov 1, 2024
1 parent aa71130 commit 8e0df09
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 8e0df09

Please sign in to comment.