Closed perruche closed 3 years ago
@perruche This is interesting. The error message references, singular class name, FieldBuilder
::addFields rather than plural FieldBuilders
::addFields though your posted code snippet only has the plural version. Unfortunately for this instance, both class names do exist in the code base, but only the plural version has the addFields
method. If there is more to the snippet, I'd be happy to look at it if you post it.
I triple check my local code to make sure i only have plural FieldBuilders
which is the case.
There is more code in my local code with more fields and field groups, but no differences from the snippet above 😞
Not sure why PHPStan is reading the correct class
Thanks for the help tho
I dug a bit into this issue, and it seems that adding the methods throwing a warning to the doc block of the FieldBuilder
(singular) class does the trick for PHPStan:
diff --git a/src/FieldBuilder.php b/src/FieldBuilder.php
index 2460728..22fe301 100644
--- a/src/FieldBuilder.php
+++ b/src/FieldBuilder.php
@@ -5,6 +5,7 @@ namespace StoutLogic\AcfBuilder;
/**
* Builds configurations for an ACF Field
* @method FieldBuilder addField(string $name, string $type, array $args = [])
+ * @method FieldBuilder addFields(FieldsBuilder|array $fields)
* @method FieldBuilder addChoiceField(string $name, string $type, array $args = [])
* @method FieldBuilder addText(string $name, array $args = [])
* @method FieldBuilder addTextarea(string $name, array $args = [])
@@ -34,6 +35,7 @@ namespace StoutLogic\AcfBuilder;
* @method FieldBuilder addTab(string $label, array $args = [])
* @method FieldBuilder addRange(string $name, array $args = [])
* @method FieldBuilder addMessage(string $label, string $message, array $args = [])
+ * @method FieldBuilder addRelationship(string $name, array $args = [])
* @method GroupBuilder addGroup(string $name, array $args = [])
* @method GroupBuilder endGroup()
* @method RepeaterBuilder addRepeater(string $name, array $args = [])
As FieldBuilder
can delegate a method call to its parent context by extending ParentDelegationBuilder
, I think that the addFields
method can be safely added to the doc block. Though I am not very familiar with all the internals of the builders, so I might be wrong.
Hello,
First thanks a lot for this wonderful lib, it's a pleasure to work with it.
I am getting a PHPStan Error which should not be, while using composing fields.
addFields
is the only method that is throwing this errorA code snippet of the implementation :