Skip to content

Commit 06caadc

Browse files
Handle PipeOperator
1 parent 06ae0bd commit 06caadc

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/Rules/Operators/PipeOperatorRule.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public function processNode(Node $node, Scope $scope): array
5454
RuleErrorBuilder::message(sprintf(
5555
'Parameter #1%s of callable on the right side of pipe operator is passed by reference.',
5656
$parameter->getName() !== '' ? ' $' . $parameter->getName() : '',
57-
))->identifier('pipe.byRef')
57+
))
58+
->line($node->right->getStartLine())
59+
->identifier('pipe.byRef')
5860
->build(),
5961
];
6062
}

tests/PHPStan/Rules/Operators/PipeOperatorRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,14 @@ public function testRule(): void
3535
]);
3636
}
3737

38+
public function testBug14150(): void
39+
{
40+
$this->analyse([__DIR__ . '/data/bug-14150.php'], [
41+
[
42+
'Parameter #1 $s of callable on the right side of pipe operator is passed by reference.',
43+
17,
44+
],
45+
]);
46+
}
47+
3848
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php // lint >= 8.5
2+
3+
namespace Bug14150PipeOperator;
4+
5+
class Foo
6+
{
7+
8+
/**
9+
* @param callable(string): string $cb
10+
*/
11+
public function doFoo(callable $cb): void
12+
{
13+
$a = 'hello';
14+
$a |> $cb
15+
|> $cb
16+
|> $cb
17+
|> self::doBar(...);
18+
}
19+
20+
public static function doBar(string &$s): void
21+
{
22+
23+
}
24+
25+
}

0 commit comments

Comments
 (0)