CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

fix: `TypeError` in `DataCaster` initialization

Open neznaika0 opened this issue 3 months ago • 6 comments

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:

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

neznaika0 avatar Oct 01 '25 18:10 neznaika0

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

neznaika0 avatar Oct 02 '25 10:10 neznaika0

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

michalsn avatar Oct 03 '25 08:10 michalsn

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.

neznaika0 avatar Oct 03 '25 08:10 neznaika0

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?

michalsn avatar Oct 03 '25 08:10 michalsn

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.

neznaika0 avatar Oct 03 '25 08:10 neznaika0

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.

michalsn avatar Oct 03 '25 08:10 michalsn

Thank you, @neznaika0

paulbalandan avatar Dec 11 '25 07:12 paulbalandan