diff --git a/src/Expression/Boolean/Andx.php b/src/Expression/Boolean/Andx.php index d5b93f64..5f2d9125 100644 --- a/src/Expression/Boolean/Andx.php +++ b/src/Expression/Boolean/Andx.php @@ -10,6 +10,7 @@ use Arkitect\Rules\Violation; use Arkitect\Rules\ViolationMessage; use Arkitect\Rules\Violations; +use Arkitect\Shared\String\IndentationHelper; final class Andx implements Expression { @@ -28,7 +29,7 @@ public function describe(ClassDescription $theClass, string $because = ''): Desc $expressionsDescriptions[] = $expression->describe($theClass, $because)->toString(); } $expressionsDescriptionsString = "(\n" - .implode("\nAND\n", array_unique(array_map('trim', $expressionsDescriptions))) + .IndentationHelper::indent(implode("\nAND\n", array_unique(array_map('trim', $expressionsDescriptions)))) ."\n)"; return new Description($expressionsDescriptionsString, $because); diff --git a/src/Expression/Boolean/Not.php b/src/Expression/Boolean/Not.php index 0619178e..eea802db 100644 --- a/src/Expression/Boolean/Not.php +++ b/src/Expression/Boolean/Not.php @@ -23,7 +23,7 @@ public function __construct(Expression $expression) public function describe(ClassDescription $theClass, string $because = ''): Description { - return new Description('NOT ('.$this->expression->describe($theClass)->toString().')', $because); + return new Description('NOT '.$this->expression->describe($theClass)->toString(), $because); } public function evaluate(ClassDescription $theClass, Violations $violations, string $because = ''): void diff --git a/src/Expression/Boolean/Orx.php b/src/Expression/Boolean/Orx.php index 34b43ec8..5d76bf15 100644 --- a/src/Expression/Boolean/Orx.php +++ b/src/Expression/Boolean/Orx.php @@ -9,6 +9,7 @@ use Arkitect\Rules\Violation; use Arkitect\Rules\ViolationMessage; use Arkitect\Rules\Violations; +use Arkitect\Shared\String\IndentationHelper; final class Orx implements Expression { @@ -26,7 +27,9 @@ public function describe(ClassDescription $theClass, string $because = ''): Desc foreach ($this->expressions as $expression) { $expressionsDescriptions[] = $expression->describe($theClass, $because)->toString(); } - $expressionsDescriptionsString = implode("\nOR\n", array_unique($expressionsDescriptions))."\n"; + $expressionsDescriptionsString = "(\n" + .IndentationHelper::indent(implode("\nOR\n", array_unique($expressionsDescriptions))) + ."\n)"; return new Description($expressionsDescriptionsString, $because); } diff --git a/src/Shared/String/IndentationHelper.php b/src/Shared/String/IndentationHelper.php new file mode 100644 index 00000000..5c1113b0 --- /dev/null +++ b/src/Shared/String/IndentationHelper.php @@ -0,0 +1,13 @@ +count()); $this->assertEquals( - "(\nshould implement SomeInterface\nbecause reasons\nAND\nshould extend SomeClass\nbecause reasons\n)\nbecause reasons", + "(\n" + ." should implement SomeInterface\n" + ." because reasons\n" + ." AND\n" + ." should extend SomeClass\n" + ." because reasons\n" + .")\n" + .'because reasons', $violationError ); $this->assertEquals( @@ -117,10 +124,13 @@ public function test_it_should_not_pass_the_rule(): void ."should extend SomeClass\n" ."from the rule\n" ."(\n" - ."should implement SomeInterface\nbecause reasons\n" - ."AND\n" - ."should extend SomeClass\nbecause reasons\n" - .")\nbecause reasons", + ." should implement SomeInterface\n" + ." because reasons\n" + ." AND\n" + ." should extend SomeClass\n" + ." because reasons\n" + .")\n" + .'because reasons', $violations->get(0)->getError() ); } diff --git a/tests/Unit/Expressions/Boolean/NotTest.php b/tests/Unit/Expressions/Boolean/NotTest.php index 3eade606..fc0f9f99 100644 --- a/tests/Unit/Expressions/Boolean/NotTest.php +++ b/tests/Unit/Expressions/Boolean/NotTest.php @@ -35,7 +35,7 @@ public function test_it_should_return_violation_error(): void self::assertNotEquals(0, $violations->count()); $this->assertEquals( - "NOT (HappyIsland should be an interface)\nbecause we want to add this rule for our software", + "NOT HappyIsland should be an interface\nbecause we want to add this rule for our software", $violationError ); } diff --git a/tests/Unit/Expressions/ForClasses/NotDependsOnTheseExpressionsTest.php b/tests/Unit/Expressions/ForClasses/NotDependsOnTheseExpressionsTest.php index 86787f1d..05c36648 100644 --- a/tests/Unit/Expressions/ForClasses/NotDependsOnTheseExpressionsTest.php +++ b/tests/Unit/Expressions/ForClasses/NotDependsOnTheseExpressionsTest.php @@ -85,13 +85,13 @@ public function test_it_should_see_violations_only_outside_exclusions(): void ); self::assertStringContainsString( <<