-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
General code cleanup #28
base: master
Are you sure you want to change the base?
Conversation
If the return value is `null`, it will return `null` anyway. If the method doesn't exist, it will throw an `Error` because of the undefined method.
Regarding the Could we add a test that passes an The change does make sense to me, I'd just like to confirm everything works as intended. I think the reason I went with those particular types is that they were used by Laravel collections. But in retrospect |
The new version does — the old version doesn't. Meaning there were cases the logic handled that aren't covered by our tests. |
Bit unrelated to this PR but I just randomly noticed one issue in the code and it could be fixed here if you want to address it. Essentially, if you use the enum MyBackedEnum: int
{
use From; // for fromName()
case FOO = 1;
} And you do: public static function from(string $case): static (at least Intelephense thinks this). Where the Do you think we should just change the signature to |
Uh, this is an odd one. Honestly, I'd probably move out Ghetto-fixing it with adding the |
Yeah but it'd just fail, which is kinda expected. The I mentioned that my LSP complains (but only in some projects...?) when I pass the backed value (int) to So I think we have to make the types the same either way.
The caller is always pure because if it's a backed enum, our trait method will be ignored in favor of the native |
Fair enough, let's just change the signature then. Should I proceed with it?
Perhaps this happens in projects where |
I tried that, and the error is shown in my IDE, but apparently, Pest (or indirectly PHPUnit) doesn't seem to care about it - the tests pass even with seemingly invalid values. Likely because the tests are running not directly from the test file itself, but from an underlying layer of PHPUnit which is not strict. Honestly, I have absolutely no idea how to fix this. In a production environment with <?php
declare(strict_types=1);
enum MyEnum
{
use \ArchTech\Enums\From;
case HELLO;
case WORLD;
}
MyEnum::from(1); In any way, extending the method signature to |
Well, |
For some reason I always forget that backend enums won't actually use the I can commit the changed tests, let me know if you want them in this PR. Also, I can change the method signature for |
.gitignore
with.idea
(for IntelliJ IDEs) and.phpunit.cache
(for tests)Added proper typing tois()
andisNot()
- probably BC, even though it'd never make sense to pass anything other than an Enum due to===
check as$this
will always be anUnitEnum
(either pure or backed, both extend this interface), so anything other than anUnitEnum
will yield a false resultif this is not the desired behavior and we want users to be able to pass impossible-to-be-true values, I can revert this changemoved to [2.x] Narrow argument type for is/isNot #30