Skip to content

Commit

Permalink
Type hint array|RedirectResponse return types instead of using @phpst…
Browse files Browse the repository at this point in the history
…an-ignore return.type.
  • Loading branch information
mstenta committed Feb 25, 2025
1 parent 46bc5d5 commit 45fe134
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,12 @@ public function getConfirmText() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL) {
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL): array|RedirectResponse {

// If we don't have an entity type or list of entities, redirect.
$this->entityType = $this->entityTypeManager->getDefinition($entity_type_id);
$this->entities = $this->tempStore->get($this->user->id() . ':' . $entity_type_id);
if (empty($entity_type_id) || empty($this->entities)) {
// Ignore PHPstan error for incorrect return type.
// Forms can return a RedirectResponse.
// @phpstan-ignore return.type
return new RedirectResponse($this->getCancelUrl()
->setAbsolute()
->toString());
Expand Down
5 changes: 1 addition & 4 deletions modules/core/flag/src/Form/EntityFlagActionForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,10 @@ public function getConfirmText() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL) {
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL): array|RedirectResponse {
$this->entityType = $this->entityTypeManager->getDefinition($entity_type_id);
$this->entities = $this->tempStore->get($this->user->id() . ':' . $entity_type_id);
if (empty($entity_type_id) || empty($this->entities)) {
// Ignore PHPstan error for incorrect return type.
// Forms can return a RedirectResponse.
// @phpstan-ignore return.type
return new RedirectResponse($this->getCancelUrl()
->setAbsolute()
->toString());
Expand Down
5 changes: 1 addition & 4 deletions modules/core/log/src/Form/AssetAddLogActionForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,10 @@ public function getConfirmText() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
public function buildForm(array $form, FormStateInterface $form_state): array|RedirectResponse {
$this->entityType = $this->entityTypeManager->getDefinition('asset');
$this->entities = $this->tempStore->get((string) $this->user->id());
if (!$this->entityType || empty($this->entities)) {
// Ignore PHPstan error for incorrect return type.
// Forms can return a RedirectResponse.
// @phpstan-ignore return.type
return new RedirectResponse($this->getCancelUrl()
->setAbsolute()
->toString());
Expand Down
5 changes: 1 addition & 4 deletions modules/core/owner/src/Form/AssignActionForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function getConfirmText() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, ?string $entity_type = NULL) {
public function buildForm(array $form, FormStateInterface $form_state, ?string $entity_type = NULL): array|RedirectResponse {

// Only allow asset and log entities.
if (!in_array($entity_type, ['asset', 'log'])) {
Expand All @@ -148,9 +148,6 @@ public function buildForm(array $form, FormStateInterface $form_state, ?string $
// If there are no entities, or if the entity type definition didn't load,
// redirect the user to the cancel URL.
if (!$this->entityType || empty($this->entities)) {
// Ignore PHPstan error for incorrect return type.
// Forms can return a RedirectResponse.
// @phpstan-ignore return.type
return new RedirectResponse($this->getCancelUrl()
->setAbsolute()
->toString());
Expand Down
5 changes: 1 addition & 4 deletions modules/core/parent/src/Form/AssetParentActionForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function getConfirmText() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
public function buildForm(array $form, FormStateInterface $form_state): array|RedirectResponse {

// Check if asset IDs were provided in the asset query param.
if ($asset_ids = $this->request->get('asset')) {
Expand All @@ -154,9 +154,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {

$this->entityType = $this->entityTypeManager->getDefinition('asset');
if (!$this->entityType || empty($this->entities)) {
// Ignore PHPstan error for incorrect return type.
// Forms can return a RedirectResponse.
// @phpstan-ignore return.type
return new RedirectResponse($this->getCancelUrl()
->setAbsolute()
->toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,10 @@ public function getConfirmText() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
public function buildForm(array $form, FormStateInterface $form_state): array|RedirectResponse {
$this->entityType = $this->entityTypeManager->getDefinition('log');
$this->entities = $this->tempStore->get((string) $this->user->id());
if (!$this->entityType || empty($this->entities)) {
// Ignore PHPstan error for incorrect return type.
// Forms can return a RedirectResponse.
// @phpstan-ignore return.type
return new RedirectResponse($this->getCancelUrl()
->setAbsolute()
->toString());
Expand Down

0 comments on commit 45fe134

Please sign in to comment.