From e0116df511f815d00d19476f00087aa2650b940f Mon Sep 17 00:00:00 2001 From: Tim Rohaly <tr@202830.no-reply.drupal.org> Date: Mon, 23 Dec 2024 17:57:46 -0800 Subject: [PATCH] Issue #3495750 by tr: Type hint negate() --- src/Core/RulesConditionBase.php | 2 +- src/Core/RulesConditionInterface.php | 2 +- src/Engine/ConditionExpressionContainer.php | 4 ++-- src/Engine/ConditionExpressionInterface.php | 4 ++-- src/Plugin/RulesExpression/ConditionExpression.php | 4 ++-- tests/src/Kernel/Engine/MetadataAssertionTest.php | 12 +++++++----- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Core/RulesConditionBase.php b/src/Core/RulesConditionBase.php index 2f4ee3d8..86d64f85 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 64608c6f..00248523 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 c1d51bca..3d65b89e 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 c47ce1e5..3691d5af 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 6e9d88d1..3873435c 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 239b7d23..03ec7453 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() -- GitLab