Skip to content

Commit

Permalink
Change return types from $this to self so that psalm infers inher…
Browse files Browse the repository at this point in the history
…ited templates

Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Nov 24, 2023
1 parent 93c2673 commit a29ef60
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public function getLabelAttributes(): array
*
* Implementation will decide if this will overwrite or merge.
*
* @return $this
* @return self
* @throws Exception\InvalidArgumentException
*/
public function setLabelOptions(iterable $arrayOrTraversable)
Expand Down
2 changes: 1 addition & 1 deletion src/Fieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ public function bindValues(array $values = [], ?array $validationGroup = null)
/**
* Set if this fieldset is used as a base fieldset
*
* @return $this
* @return self
*/
public function setUseAsBaseFieldset(bool $useAsBaseFieldset)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public function useInputFilterDefaults(): bool
/**
* Set flag indicating whether or not to prefer the form input filter over element and fieldset defaults
*
* @return $this
* @return self<TFilteredValues>
*/
public function setPreferFormInputFilter(bool $preferFormInputFilter)
{
Expand Down
4 changes: 2 additions & 2 deletions src/LabelAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getLabel(): ?string;
* Set the attributes to use with the label
*
* @param array<string, scalar|null> $labelAttributes
* @return $this
* @return self
*/
public function setLabelAttributes(array $labelAttributes);

Expand All @@ -38,7 +38,7 @@ public function getLabelAttributes(): array;
*
* Implementation will decide if this will overwrite or merge.
*
* @return $this
* @return self
*/
public function setLabelOptions(iterable $arrayOrTraversable);

Expand Down
16 changes: 16 additions & 0 deletions test/StaticAnalysis/FormTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,20 @@ public function getDataWithValuesNormalized(): string

return $data['string'];
}

/** @return non-empty-string */
public function testThatFluidReturnTypesPreserveTemplatesForSetPreferFormInputFilter(): string
{
$form = new ExampleForm();
return $form->setPreferFormInputFilter(true)
->getData(FormInterface::VALUES_AS_ARRAY)['string'];
}

/** @return non-empty-string */
public function testThatFluidReturnTypesPreserveTemplatesForSetWrapElements(): string
{
$form = new ExampleForm();
return $form->setWrapElements(true)
->getData(FormInterface::VALUES_AS_ARRAY)['string'];
}
}

0 comments on commit a29ef60

Please sign in to comment.