diff --git a/src/Core/RulesConditionBase.php b/src/Core/RulesConditionBase.php index 2f4ee3d8cfb830942af91d4bc6746fa6ef1b2bdc..86d64f856eacbcf03b1f3d7453c4460ef8397f3a 100644 --- a/src/Core/RulesConditionBase.php +++ b/src/Core/RulesConditionBase.php @@ -51,7 +51,7 @@ abstract class RulesConditionBase extends ConditionPluginBase implements RulesCo /** * {@inheritdoc} */ - public function negate($negate = TRUE) { + public function negate(bool $negate = TRUE): static { $this->configuration['negate'] = $negate; return $this; } diff --git a/src/Core/RulesConditionInterface.php b/src/Core/RulesConditionInterface.php index 64608c6f9affe7728820e66644133380718db28a..00248523966c193828fac7f3545a256d03e8c222 100644 --- a/src/Core/RulesConditionInterface.php +++ b/src/Core/RulesConditionInterface.php @@ -19,6 +19,6 @@ interface RulesConditionInterface extends ConditionInterface, ContextAwarePlugin * * @return $this */ - public function negate($negate = TRUE); + public function negate(bool $negate = TRUE): static; } diff --git a/src/Engine/ConditionExpressionContainer.php b/src/Engine/ConditionExpressionContainer.php index c1d51bcaf4ccf12466edd2321cbddc40cb877007..3d65b89e3abc5bef9fe28db856d363236a6a3f13 100644 --- a/src/Engine/ConditionExpressionContainer.php +++ b/src/Engine/ConditionExpressionContainer.php @@ -88,7 +88,7 @@ abstract class ConditionExpressionContainer extends ExpressionContainerBase impl /** * {@inheritdoc} */ - public function negate($negate = TRUE) { + public function negate(bool $negate = TRUE): static { $this->configuration['negate'] = $negate; return $this; } @@ -96,7 +96,7 @@ abstract class ConditionExpressionContainer extends ExpressionContainerBase impl /** * {@inheritdoc} */ - public function isNegated() { + public function isNegated(): bool { return !empty($this->configuration['negate']); } diff --git a/src/Engine/ConditionExpressionInterface.php b/src/Engine/ConditionExpressionInterface.php index c47ce1e55268052ec4210f4a212b3ce0fa22d773..3691d5af73302dd7d07eeb96253ae0e041c55be2 100644 --- a/src/Engine/ConditionExpressionInterface.php +++ b/src/Engine/ConditionExpressionInterface.php @@ -15,7 +15,7 @@ interface ConditionExpressionInterface extends ExpressionInterface { * * @return $this */ - public function negate($negate = TRUE); + public function negate(bool $negate = TRUE): static; /** * Determines whether condition result will be negated. @@ -23,6 +23,6 @@ interface ConditionExpressionInterface extends ExpressionInterface { * @return bool * Whether the condition result will be negated. */ - public function isNegated(); + public function isNegated(): bool; } diff --git a/src/Plugin/RulesExpression/ConditionExpression.php b/src/Plugin/RulesExpression/ConditionExpression.php index 6e9d88d1b5898b3cc374c85da76adbceecb82fc1..3873435cefd305f0dae2f27b0d53bfb28eb78554 100644 --- a/src/Plugin/RulesExpression/ConditionExpression.php +++ b/src/Plugin/RulesExpression/ConditionExpression.php @@ -147,7 +147,7 @@ class ConditionExpression extends ExpressionBase implements ConditionExpressionI /** * {@inheritdoc} */ - public function negate($negate = TRUE) { + public function negate(bool $negate = TRUE): static { $this->configuration['negate'] = $negate; return $this; } @@ -155,7 +155,7 @@ class ConditionExpression extends ExpressionBase implements ConditionExpressionI /** * {@inheritdoc} */ - public function isNegated() { + public function isNegated(): bool { return !empty($this->configuration['negate']); } diff --git a/tests/src/Kernel/Engine/MetadataAssertionTest.php b/tests/src/Kernel/Engine/MetadataAssertionTest.php index 239b7d23e29e1e68c681cd4700abc925e762b05e..03ec7453b6eada834c94e1697f4e3d03c8e6552f 100644 --- a/tests/src/Kernel/Engine/MetadataAssertionTest.php +++ b/tests/src/Kernel/Engine/MetadataAssertionTest.php @@ -101,7 +101,7 @@ class MetadataAssertionTest extends RulesKernelTestBase { * Tests asserted metadata is handled correctly in OR and AND containers. */ public function testAssertingWithLogicalOperations(): void { - // Add an nested AND and make sure it keeps working. + // Add a nested AND and make sure it keeps working. $rule = $this->expressionManager->createRule(); $and = $this->expressionManager->createAnd(); $and->addCondition('rules_entity_is_of_bundle', ContextConfig::create() @@ -119,7 +119,7 @@ class MetadataAssertionTest extends RulesKernelTestBase { ->checkIntegrity(); $this->assertCount(0, $violation_list); - // Add an nested OR and make sure it is ignored. + // Add a nested OR and make sure it is ignored. $rule = $this->expressionManager->createRule(); $or = $this->expressionManager->createOr(); $or->addCondition('rules_entity_is_of_bundle', ContextConfig::create() @@ -142,13 +142,15 @@ class MetadataAssertionTest extends RulesKernelTestBase { * Tests asserted metadata of negated conditions is ignored. */ public function testAssertingOfNegatedConditions(): void { - // Negate the condition only and make sure it is ignored. $rule = $this->expressionManager->createRule(); $rule->addCondition('rules_entity_is_of_bundle', ContextConfig::create() ->map('entity', 'node') ->setValue('type', 'node') ->setValue('bundle', 'page') - )->negate(TRUE); + ); + // Negate the condition only and make sure it is ignored. + $rule->getConditions()->getIterator()->current()->negate(TRUE); + $rule->addAction('rules_system_message', ContextConfig::create() ->map('message', 'node.field_text.value') ->setValue('type', 'status') @@ -158,7 +160,7 @@ class MetadataAssertionTest extends RulesKernelTestBase { ->checkIntegrity(); $this->assertCount(1, $violation_list); - // Add an negated AND and make sure it is ignored. + // Add a negated AND and make sure it is ignored. $rule = $this->expressionManager->createRule(); $and = $this->expressionManager->createAnd(); $and->addCondition('rules_entity_is_of_bundle', ContextConfig::create()