Skip to content

Commit

Permalink
chore: Update to psalm 5
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent4vx committed Mar 4, 2024
1 parent efd0010 commit e2ce62c
Show file tree
Hide file tree
Showing 32 changed files with 76 additions and 14 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"symfony/security-csrf": "~4.3|~5.0|~6.0",
"giggsey/libphonenumber-for-php": "~8.0",
"phpunit/phpunit": "~7.0|~8.0|~9.0",
"vimeo/psalm": "~4.20",
"vimeo/psalm": "~5.22",
"symfony/http-foundation": "~4.3|~5.0|~6.0",
"symfony/form": "~4.3|~5.0|~6.0"
},
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<psalm
errorLevel="3"
resolveFromConfigFile="true"
findUnusedBaselineEntry="false"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand Down
2 changes: 1 addition & 1 deletion src/Aggregate/ArrayChildBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function filterEmptyValues(bool $flag = true): self
return $this;
}

protected function provideEmptyValueFilter(): array
protected function provideEmptyValueFilter(RegistryInterface $registry): array
{
if (!$this->filterEmptyValues) {
return [];
Expand Down
1 change: 1 addition & 0 deletions src/Aggregate/ChildAggregateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @template T
* @extends ElementInterface<T>
* @extends ArrayAccess<string, ChildInterface>
* @extends IteratorAggregate<string, ChildInterface>
*/
interface ChildAggregateInterface extends ElementInterface, ArrayAccess, IteratorAggregate
{
Expand Down
6 changes: 5 additions & 1 deletion src/Aggregate/Collection/ChildrenCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
use Bdf\Form\Child\ChildInterface;
use Countable;
use Iterator;
use IteratorAggregate;

/**
* Collection of form child elements
* Handle dependency tree
*
* @extends IteratorAggregate<string, ChildInterface>
* @extends ArrayAccess<string, ChildInterface>
*/
interface ChildrenCollectionInterface extends \IteratorAggregate, ArrayAccess, Countable
interface ChildrenCollectionInterface extends IteratorAggregate, ArrayAccess, Countable
{
/**
* Add a child to the dependency tree
Expand Down
2 changes: 2 additions & 0 deletions src/Aggregate/Collection/DependencyIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Iterate over @see DependencyTree
*
* Iterate first on the last level, and go to lower levels, to root
*
* @implements Iterator<ChildInterface>
*/
final class DependencyIterator implements Iterator
{
Expand Down
3 changes: 3 additions & 0 deletions src/Aggregate/Collection/DependencyTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* add(E4(E2, E3)) -> lvl0(E1, E4), lvl1(E3), lvl2(E2) [E4 added to lvl0, E3 shift to lvl1, E2 shift to lvl2]
*
* The iterator of the dependency tree will iterate over "higher" dependencies before, and "root" children at the end
*
* @implements \ArrayAccess<string, ChildInterface>
* @implements \IteratorAggregate<string, ChildInterface>
*/
final class DependencyTree implements \ArrayAccess, \IteratorAggregate, \Countable, ChildrenCollectionInterface
{
Expand Down
1 change: 1 addition & 0 deletions src/Aggregate/Collection/Level.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* The dependency tree level
*
* @internal
* @implements IteratorAggregate<string, string[]>
*/
final class Level implements IteratorAggregate
{
Expand Down
2 changes: 2 additions & 0 deletions src/Aggregate/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
*
* @see Form
* @see CustomForm::configure()
*
* @extends AbstractElementBuilder<Form>
*/
class FormBuilder extends AbstractElementBuilder implements FormBuilderInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Aggregate/FormBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* $form = $builder->buildElement();
* </code>
*
* @implements ElementBuilderInterface<FormInterface>
* @extends ElementBuilderInterface<FormInterface>
*/
interface FormBuilderInterface extends ElementBuilderInterface
{
Expand Down
1 change: 1 addition & 0 deletions src/Aggregate/RootForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
* </code>
*
* @todo delegation trait
* @implements ChildAggregateInterface<mixed>
*/
final class RootForm implements RootElementInterface, ChildAggregateInterface
{
Expand Down
3 changes: 3 additions & 0 deletions src/Aggregate/View/ArrayElementView.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
* </code>
*
* @see ArrayElement::view()
*
* @implements IteratorAggregate<array-key, ElementViewInterface>
* @implements FieldSetViewInterface<ElementViewInterface>
*/
final class ArrayElementView implements IteratorAggregate, FieldViewInterface, FieldSetViewInterface, Countable
{
Expand Down
3 changes: 3 additions & 0 deletions src/Aggregate/View/FormView.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
* </code>
*
* @see Form::view()
*
* @implements IteratorAggregate<string, ElementViewInterface|ButtonViewInterface>
* @implements FieldSetViewInterface<ElementViewInterface|ButtonViewInterface>
*/
final class FormView implements IteratorAggregate, FieldSetViewInterface
{
Expand Down
1 change: 1 addition & 0 deletions src/Choice/LazzyChoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @deprecated Use LazyChoice
* @psalm-suppress InvalidExtendClass
* @psalm-suppress MissingTemplateParam
*/
final class LazzyChoice extends LazyChoice
{
Expand Down
1 change: 1 addition & 0 deletions src/Custom/CustomFormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @see CustomForm::configure()
*
* @mixin FormBuilderInterface
* @implements ElementBuilderInterface<CustomForm>
*/
class CustomFormBuilder implements ElementBuilderInterface
{
Expand Down
11 changes: 10 additions & 1 deletion src/Filter/FilterVar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
use Attribute;
use Bdf\Form\Child\ChildInterface;

use function filter_var;
use function is_array;
use function is_scalar;
use function str_replace;
use function strip_tags;

/**
* Adapt filter_var() to FilterInterface
* By default, configured to filter HTML values
Expand Down Expand Up @@ -60,6 +66,8 @@ public function filter($value, ChildInterface $input, $default)

private function apply($value)
{
$value = is_scalar($value) ? (string) $value : '';

if ($this->filter !== self::HTML_FILTER) {
return filter_var($value, $this->filter, $this->flags);
}
Expand All @@ -74,7 +82,8 @@ private function apply($value)

// Encode quotes
if (($this->flags & FILTER_FLAG_NO_ENCODE_QUOTES) === 0) {
$value = str_replace(['"', "'"], ['&#34;', '&#39;'], $value);
/** @psalm-suppress PossiblyInvalidCast */
$value = str_replace(['"', "'"], ['&#34;', '&#39;'], (string) $value);
}

return $value;
Expand Down
1 change: 1 addition & 0 deletions src/Leaf/BooleanStringElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class BooleanStringElement extends AbstractBooleanElement
*
* @return scalar|null
* @psalm-suppress ImplementedReturnTypeMismatch
* @psalm-suppress LessSpecificImplementedReturnType
*/
protected function sanitize($rawValue)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Leaf/Date/DateTimeElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ protected function toPhp($httpValue): ?DateTimeInterface
*/
protected function toHttp($phpValue)
{
// Because of legacy behavior, the raw value can be saved when a transformer failed
// So the raw string is kept as is
if (is_string($phpValue)) {
/** @psalm-suppress NoValue */
return $phpValue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Leaf/Date/DateTimeElementBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function format(string $format): self
* $builder->dateTime('eventDate')->timezone(new DateTimeZone('+0200');
* </code>
*
* @param string|DateTimeZone|null $timezone The timezone. If string is given, a new DateTimeZone will be created.
* @param non-empty-string|DateTimeZone|null $timezone The timezone. If string is given, a new DateTimeZone will be created.
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Leaf/Helper/EmailElementBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function useConstraint(array $options = []): self
/**
* @return \Symfony\Component\Validator\Constraint[]
*/
protected function createEmailConstraint(): array
protected function createEmailConstraint(RegistryInterface $registry): array
{
if (!$this->useConstraint) {
return [];
Expand Down
2 changes: 1 addition & 1 deletion src/Leaf/Helper/UrlElementBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function useConstraint(array $options = []): self
/**
* @return \Symfony\Component\Validator\Constraint[]
*/
protected function createUrlConstraint(): array
protected function createUrlConstraint(RegistryInterface $registry): array
{
if (!$this->useConstraint) {
return [];
Expand Down
2 changes: 1 addition & 1 deletion src/Leaf/NumberElementBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected function defaultTransformerExceptionConstraintOptions(): array
*/
abstract protected function numberTransformer(): TransformerInterface;

final protected function provideNumberTransformer(): array
final protected function provideNumberTransformer(RegistryInterface $registry): array
{
if (!$this->raw) {
return [$this->numberTransformer()];
Expand Down
2 changes: 1 addition & 1 deletion src/Leaf/Transformer/LocalizedNumberTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function getNumberFormatter(): NumberFormatter
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, $this->roundingMode);
}

$formatter->setAttribute(NumberFormatter::GROUPING_USED, $this->grouping);
$formatter->setAttribute(NumberFormatter::GROUPING_USED, (int) $this->grouping);

return $formatter;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Leaf/View/SelectHtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
/**
* Renderer for select element
* Should be used for element with choices
*
* @implements FieldViewRendererInterface<FieldViewInterface>
*/
final class SelectHtmlRenderer implements FieldViewRendererInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Leaf/View/SimpleFieldHtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

/**
* Default render for @see SimpleElementView
*
* @implements FieldViewRendererInterface<SimpleElementView>
*/
final class SimpleFieldHtmlRenderer implements FieldViewRendererInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Phone/PhoneChildBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function saveAsString(?int $format = PhoneNumberFormat::E164): self
/**
* @return PhoneNumberToStringTransformer[]
*/
protected function provideModelTransformer(): array
protected function provideModelTransformer(RegistryInterface $registry): array
{
if ($this->saveFormat === null) {
return [];
Expand Down
2 changes: 1 addition & 1 deletion src/Phone/PhoneElementBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected function createElement(ValueValidatorInterface $validator, Transformer
*
* @return Constraint[]
*/
protected function providePhoneConstraint(): array
protected function providePhoneConstraint(RegistryInterface $registry): array
{
if ($this->allowInvalidNumber) {
return [];
Expand Down
2 changes: 2 additions & 0 deletions src/RootElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*
* @method void set(string $flag, mixed $value) Define a flag value
* @method bool is(string $flag) Check if a flag is defined
*
* @extends ElementInterface<mixed>
*/
interface RootElementInterface extends ElementInterface
{
Expand Down
5 changes: 5 additions & 0 deletions src/View/FieldSetViewInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
* </code>
*
* @see \Bdf\Form\Aggregate\ChildAggregateInterface
*
* @template E
*
* @extends ArrayAccess<array-key, E>
* @extends Traversable<array-key, E>
*/
interface FieldSetViewInterface extends ElementViewInterface, ArrayAccess, Traversable
{
Expand Down
4 changes: 3 additions & 1 deletion src/View/RenderableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public function __call(string $name, array $arguments)
throw new ArgumentCountError('Missing the attribute value.');
}

return $this->set($name, $arguments[0]);
$this->set($name, $arguments[0]);

return $this;
}

/**
Expand Down
11 changes: 10 additions & 1 deletion tests/StaticAnalysis/ArrayElementConfigure.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@
use Bdf\Form\Aggregate\FormBuilderInterface;
use Bdf\Form\Custom\CustomForm;

/**
* @extends CustomForm<array>
*/
class ArrayElementConfigure extends CustomForm
{
/**
* {@inheritdoc}
*/
protected function configure(FormBuilderInterface $builder): void
{
$builder->array('values')->element(ArrayElement::class, function (ArrayElementBuilder $builder) {});
$builder->array('values')->element(
ArrayElement::class,
/**
* @param ArrayElementBuilder<mixed> $builder
*/
function (ArrayElementBuilder $builder) {}
);
}
}
3 changes: 3 additions & 0 deletions tests/StaticAnalysis/SubClassChildBuilderForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Bdf\Form\Aggregate\FormBuilderInterface;
use Bdf\Form\Custom\CustomForm;

/**
* @extends CustomForm<array>
*/
class SubClassChildBuilderForm extends CustomForm
{
/**
Expand Down

0 comments on commit e2ce62c

Please sign in to comment.