78 lines
3 KiB
YAML
78 lines
3 KiB
YAML
uuid:
|
|
- value: 465add9b-a2c7-48f1-84de-966fbbd20c27
|
|
langcode:
|
|
- value: en
|
|
type:
|
|
- target_id: daily_email
|
|
target_type: node_type
|
|
target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7
|
|
revision_timestamp:
|
|
- value: '2025-05-11T09:00:14+00:00'
|
|
revision_uid:
|
|
- target_type: user
|
|
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
|
|
revision_log: { }
|
|
status:
|
|
- value: true
|
|
uid:
|
|
- target_type: user
|
|
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
|
|
title:
|
|
- value: 'Making PHPStan stricter'
|
|
created:
|
|
- value: '2024-05-05T00:00:00+00:00'
|
|
changed:
|
|
- value: '2025-05-11T09:00:14+00:00'
|
|
promote:
|
|
- value: false
|
|
sticky:
|
|
- value: false
|
|
default_langcode:
|
|
- value: true
|
|
revision_translation_affected:
|
|
- value: true
|
|
path:
|
|
- alias: /daily/2024/05/05/making-phpstan-stricter
|
|
langcode: en
|
|
body:
|
|
- value: |
|
|
<p>Continuing yesterday's thought on <a href="/daily/2024/05/04/strict-typing-in-php">strictness in PHP</a>, today I want to talk about adding more strictness to PHPStan.</p>
|
|
|
|
<p>Adding the <a href="https://github.com/phpstan/phpstan-strict-rules">PHPStan Strict Rules extension</a> makes PHPStan stricter by adding new, more opinionated rules.</p>
|
|
|
|
<p>For example:</p>
|
|
|
|
<ul>
|
|
<li>Require booleans in if, elseif, ternary operator, after !, and on both sides of && and ||.</li>
|
|
<li>Use the <code>$strict</code> parameter with <code>in_array</code>, <code>array_search</code>, <code>array_keys</code> and <code>base64_decode</code>.</li>
|
|
<li>Disallow empty().</li>
|
|
<li>Require calling parent constructor.</li>
|
|
</ul>
|
|
|
|
<p>You can enable and disable rules as needed but, like setting the PHPStan level, ideally I like to enable them all by default and see how strict I go.</p>
|
|
|
|
<p>It depends on the code being tested and the preference of the team, though I find the stricter the rules, the less bugs there are.</p>
|
|
|
|
|
|
format: full_html
|
|
processed: |
|
|
<p>Continuing yesterday's thought on <a href="/daily/2024/05/04/strict-typing-in-php">strictness in PHP</a>, today I want to talk about adding more strictness to PHPStan.</p>
|
|
|
|
<p>Adding the <a href="https://github.com/phpstan/phpstan-strict-rules">PHPStan Strict Rules extension</a> makes PHPStan stricter by adding new, more opinionated rules.</p>
|
|
|
|
<p>For example:</p>
|
|
|
|
<ul>
|
|
<li>Require booleans in if, elseif, ternary operator, after !, and on both sides of && and ||.</li>
|
|
<li>Use the <code>$strict</code> parameter with <code>in_array</code>, <code>array_search</code>, <code>array_keys</code> and <code>base64_decode</code>.</li>
|
|
<li>Disallow empty().</li>
|
|
<li>Require calling parent constructor.</li>
|
|
</ul>
|
|
|
|
<p>You can enable and disable rules as needed but, like setting the PHPStan level, ideally I like to enable them all by default and see how strict I go.</p>
|
|
|
|
<p>It depends on the code being tested and the preference of the team, though I find the stricter the rules, the less bugs there are.</p>
|
|
|
|
|
|
summary: null
|
|
field_daily_email_cta: { }
|