A private method is never called in its class
What it finds
A private method that nothing in its class calls: only the class can call it, so it is dead code, or the call that was meant to reach it goes elsewhere. Calls through strings, as in callbacks like [$this, 'name'], count as calls. Classes with __call, or that use traits or include templates, which can call the method too, are left alone, and so are traits, whose private methods belong to the classes that use them, and PHP's magic methods.
From the rule's source, unused_private_method.rs.
<?phpclass Report{ public function render() { return $this->header() . array_map([$this, 'row'], [1]); } private function header() { return 'h'; } private function row($r) { return $r; } private function footer()tx0 reports: the private method footer is never called { return 'f'; } private function __clone() { }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/php:unused-private-method" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/php:unused-private-method] reason="..."tx0 explain tx0/php:unused-private-method shows the same in the terminal. Found a false positive? Report it.