Automate review using PHPStan: require methods that do not inspect $this to be static
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3589137. -->
Reported by: [wim leers](https://www.drupal.org/user/99777)
Related to !1082
>>>
<h3 id="overview">Overview</h3>
<p>A very common piece of review feedback:</p>
<pre>private function testSomething($a, $b) {<br> // do something that looks only at $a and $b, not $this<br>}</pre><p>
should be</p>
<pre>private static function testSomething($a, $b) {<br> // do something that looks only at $a and $b, not $this<br>}</pre><h3 id="proposed-resolution">Proposed resolution</h3>
<p>Looked at the PHPStan extensions linked in <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3578767" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3578767</a></span>, and searched the web. Could not find any.</p>
<p>Hence: new PHPStan rule that detects non-static methods that are not using $this. These methods should be converted to become static. Documented best practice at <a href="https://web.archive.org/web/20260215134806/https://www.drupal4hu.com/node/416.html">https://web.archive.org/web/20260215134806/https://www.drupal4hu.com/node/416.html</a></p>
<p>Summary of changes in MR description: !1082.</p>
<h3 id="ui-changes">User interface changes</h3>
<p>None.</p>
issue