Skip to content
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

Implement logical or expression #387

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

akondas
Copy link

@akondas akondas commented May 28, 2023

Motivation

Allow to define logical expressions which will help with more advanced or complex expressions. Class name is not perfect but Or is keyword hence can't be used directly as class name. Orx was inspired by doctrine project.

If we are fine with that approach then I can implement more (like and).


public function evaluate(ClassDescription $theClass, Violations $violations, string $because): void
{
foreach ($this->expressions as $expression) {
Copy link

Choose a reason for hiding this comment

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

question: Could we throw a logicalException or violation if none or only one expression is used? And if so, add a test method 🙏

Copy link
Author

Choose a reason for hiding this comment

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

okay 🖖

Copy link
Author

Choose a reason for hiding this comment

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

added with tests

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm actually not sure this is a good idea.
If we want to build automations on top of this, we will want to instantiate this with a list of expressions that are somehow inferred.
This list might have something or might be empty, in which case I think it should be irrelevant and therefore should not fail, essentially being ignored.

WDYT?

/** @var Expression[] */
private $expressions;

public function __construct(array $expressions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we do public function __construct(Expression ...$expressions)?

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