Issues (31)

src/Child/Dependencies.php (2 issues)

1
<?php
2
3
namespace Bdf\Form\Attribute\Child;
4
5
use Attribute;
6
use Bdf\Form\Attribute\AttributeForm;
7
use Bdf\Form\Attribute\ChildBuilderAttributeInterface;
8
use Bdf\Form\Attribute\Processor\CodeGenerator\AttributesProcessorGenerator;
9
use Bdf\Form\Attribute\Processor\GenerateConfiguratorStrategy;
10
use Bdf\Form\Child\ChildBuilderInterface;
11
12
/**
13
 * Add dependencies on other sibling elements
14
 *
15
 * This attribute is equivalent to call :
16
 * <code>
17
 * $builder->float('foo')->depends('bar', 'baz');
18
 * </code>
19
 *
20
 * Usage:
21
 * <code>
22
 * class MyForm extends AttributeForm
23
 * {
24
 *     #[Dependencies('bar', 'rab')]
25
 *     private FloatElement $foo;
26
 *     private IntegerElement $bar;
27
 *     private StringElement $rab;
28
 * }
29
 * </code>
30
 *
31
 * @implements ChildBuilderAttributeInterface<\Bdf\Form\ElementBuilderInterface>
32
 *
33
 * @see ChildBuilderInterface::depends() The called method
34
 */
35
#[Attribute(Attribute::TARGET_PROPERTY)]
36
final class Dependencies implements ChildBuilderAttributeInterface
37
{
38
    /**
39
     * @var list<string>
0 ignored issues
show
The type Bdf\Form\Attribute\Child\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
     * @readonly
41
     */
42
    private array $dependencies;
43
44
    /**
45
     * @param string ...$dependencies List of inputs names
46
     * @no-named-arguments
47
     */
48 3
    public function __construct(string ...$dependencies)
49
    {
50 3
        $this->dependencies = $dependencies;
0 ignored issues
show
Documentation Bug introduced by
It seems like $dependencies of type array<integer,string> is incompatible with the declared type Bdf\Form\Attribute\Child\list of property $dependencies.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 1
    public function applyOnChildBuilder(AttributeForm $form, ChildBuilderInterface $builder): void
57
    {
58 1
        $builder->depends(...$this->dependencies);
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 2
    public function generateCodeForChildBuilder(string $name, AttributesProcessorGenerator $generator, AttributeForm $form): void
65
    {
66 2
        $generator->line('$?->depends(...?);', [$name, $this->dependencies]);
67
    }
68
}
69