Skip to content

Conversation

neznaika0
Copy link
Contributor

Description

  • Fixed a bug where new DataCaster() caused the error TypeError: array_merge(): Argument #2 must be of type array, null given
  • Added a method check for castAs() and a test.
  • PHPDoc has been cleaned in BaseCast

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@neznaika0
Copy link
Contributor Author

The two checks conflict. What is the best way to fix it?
Update PHPDoc, add ignore, or remove exception?

@michalsn
Copy link
Member

michalsn commented Oct 3, 2025

Do you think this exception is necessary? The PHPDoc already makes it clear.

@neznaika0
Copy link
Contributor Author

neznaika0 commented Oct 3, 2025

phpDoc will not help if the user uses a different method (in notepad++).
Secondly, I've been thinking about it too. Then we can remove the exception and translation.

@michalsn
Copy link
Member

michalsn commented Oct 3, 2025

Then we can remove the exception and transfer.

I'm afraid I don't fully understand what you mean.

Since this isn't directly used by the end user, I'd stick with the PHPDoc. It has worked fine so far - unless there's a specific reason for adding this check?

@neznaika0
Copy link
Contributor Author

Sorry. Typo "translation".
Yes, it works. Then we have the dead code in the CastException. I decided that the check is necessary if an exception is planned. Or delete exception method.

@michalsn
Copy link
Member

michalsn commented Oct 3, 2025

This exception was previously used in the entity cast.

Let's hold off for now and hear what others think. If you feel it's more valuable to keep the exception and make the PHPDoc less strict, that's fine too.

@neznaika0 neznaika0 force-pushed the fix/datacaster-error branch from c3d4e15 to cb3d4bf Compare October 4, 2025 09:43
@paulbalandan paulbalandan changed the title fix: TypeError in DataCaster initialization fix: TypeError in DataCaster initialization Oct 5, 2025
* Convert handlers.
*
* @var array<string, class-string> [type => classname]
* @var array<string, class-string> [type => classname]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this also have the CastInterface and EnityCastInterface as above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we've decided on separate typing, I'm unsure about specifying the types...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now wondering if the framework should be the one adjusting for this missing support of phpDocumentor. I feel we are being redundant in our PHPDocs just because our API tool does not yet support a feature that is widely used now. Should this be a feature request to them (to support phpstan types and conditional returns?).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an alternative to phpDocumentor that would handle it better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a small project, I would ignore the duplication and rely on the phpstan. types.
Looking at symfony, they don't bother with this.
There is a slightly different option, which is more complex - to use a Value Object, DTO instead of an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants