@@ -19,9 +19,13 @@ class BooleanInBooleanAndRule implements Rule
19
19
/** @var BooleanRuleHelper */
20
20
private $ helper ;
21
21
22
- public function __construct (BooleanRuleHelper $ helper )
22
+ /** @var bool */
23
+ private $ bleedingEdge ;
24
+
25
+ public function __construct (BooleanRuleHelper $ helper , bool $ bleedingEdge )
23
26
{
24
27
$ this ->helper = $ helper ;
28
+ $ this ->bleedingEdge = $ bleedingEdge ;
25
29
}
26
30
27
31
public function getNodeType (): string
@@ -33,21 +37,25 @@ public function processNode(Node $node, Scope $scope): array
33
37
{
34
38
$ originalNode = $ node ->getOriginalNode ();
35
39
$ messages = [];
40
+ $ nodeText = $ this ->bleedingEdge ? $ originalNode ->getOperatorSigil () : '&& ' ;
41
+ $ identifierType = $ originalNode instanceof Node \Expr \BinaryOp \BooleanAnd ? 'booleanAnd ' : 'logicalAnd ' ;
36
42
if (!$ this ->helper ->passesAsBoolean ($ scope , $ originalNode ->left )) {
37
43
$ leftType = $ scope ->getType ($ originalNode ->left );
38
44
$ messages [] = RuleErrorBuilder::message (sprintf (
39
- 'Only booleans are allowed in &&, %s given on the left side. ' ,
45
+ 'Only booleans are allowed in %s, %s given on the left side. ' ,
46
+ $ nodeText ,
40
47
$ leftType ->describe (VerbosityLevel::typeOnly ())
41
- ))->identifier (' booleanAnd .leftNotBoolean ' )->build ();
48
+ ))->identifier (sprintf ( ' %s .leftNotBoolean ', $ identifierType ) )->build ();
42
49
}
43
50
44
51
$ rightScope = $ node ->getRightScope ();
45
52
if (!$ this ->helper ->passesAsBoolean ($ rightScope , $ originalNode ->right )) {
46
53
$ rightType = $ rightScope ->getType ($ originalNode ->right );
47
54
$ messages [] = RuleErrorBuilder::message (sprintf (
48
- 'Only booleans are allowed in &&, %s given on the right side. ' ,
55
+ 'Only booleans are allowed in %s, %s given on the right side. ' ,
56
+ $ nodeText ,
49
57
$ rightType ->describe (VerbosityLevel::typeOnly ())
50
- ))->identifier (' booleanAnd .rightNotBoolean ' )->build ();
58
+ ))->identifier (sprintf ( ' %s .rightNotBoolean ', $ identifierType ) )->build ();
51
59
}
52
60
53
61
return $ messages ;
0 commit comments