-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Comparison BIT_AND #238
base: 2.0.x
Are you sure you want to change the base?
Comparison BIT_AND #238
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your PR. Can you please also elaborate which use-case you ran into that made you create this PR?
{ | ||
$expr = $this->builder->bitAnd('b', 4); | ||
|
||
self::assertInstanceOf(Comparison::class, $expr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instance check shouldn't be needed in the test. It is a relict for past PHP versions when a return type couldn't be used.
self::assertTrue($closure(new TestObject('4'))); | ||
self::assertTrue($closure(new TestObject(5))); | ||
self::assertTrue($closure(new TestObject('5'))); | ||
self::assertFalse($closure(new TestObject(2))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a few more false cases like 8
or 11
. Be sure that there are also false-cases with a string-number like in your true-cases.
I have a collection of objects with a status field, which can hold different "combined values". e.g. class Item {
const IS_EXPORTED = 1;
const IS_PAYMENT = 2;
const IS_CANCELED = 4;
$status = 3;
$statusAsArray = [1, 2];
}
$expressionBuilder->bitAnd('status', Item::IS_PAYMENT + Item::IS_CANCELED);
$expressionBuilder->in('statusAsArray', [Item::IS_PAYMENT, Item::IS_CANCELED]) ; "bitAnd" would be similar to "in" and "bitNotAnd" to "notIn". While writing these lines, i'm not sure if this is just an "edge"-use-case in my legacy code or a good addition for this project :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know about the edge case, but I know that some doctrine/collections classes have a lot of methods which is why I don't know if it makes sense to introduce new ones or if the future of collections will need a different architecture. This needs more reviewers. @doctrine/doctrinecore
Instead of performing bitwise operations on a collection, why not have all bits as separate fields? This way, applied to a collection in the DB, the filter could use an index. |
I was missing a "bit and" comparison for building criteria expression on bit mask fields.
e.g bit mask:
1: imported
2: canceled
4: deleted
8: ...
foo = 5 (1+4)
$expressionBuilder->bitAnd('foo', 1) // true
$expressionBuilder->bitAnd('foo', 5) // true
$expressionBuilder->bitAnd('foo', 2) // false
Implementation and tests included.