121 lines
4.7 KiB
YAML
121 lines
4.7 KiB
YAML
uuid:
|
|
- value: 9fe3fe14-044e-4dfa-bbcc-41dea612f05a
|
|
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:26+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: |
|
|
Which PHPStan level should you use?
|
|
created:
|
|
- value: '2023-11-28T00:00:00+00:00'
|
|
changed:
|
|
- value: '2025-05-11T09:00:26+00:00'
|
|
promote:
|
|
- value: false
|
|
sticky:
|
|
- value: false
|
|
default_langcode:
|
|
- value: true
|
|
revision_translation_affected:
|
|
- value: true
|
|
path:
|
|
- alias: /daily/2023/11/28/which-phpstan-level-should-you-use
|
|
langcode: en
|
|
body:
|
|
- value: |
|
|
<p>Which PHPStan level should you use?</p>
|
|
|
|
<p>PHPStan has different levels.</p>
|
|
|
|
<p>When you run it on your code, the errors you see will depend on what level you set.</p>
|
|
|
|
<p><a href="/daily/2023/11/27/finding-the-best-test-base">In yesterday's email</a>, the first example code block didn't generate an error until level 5 was used.</p>
|
|
|
|
<p>So, how do you know which level to use?</p>
|
|
|
|
<h2 id="for-greenfield-projects">For greenfield projects</h2>
|
|
|
|
<p>For new (greenfield) code, install and configure PHPStan before you write any code and have and have it run automatically as part of a CI pipeline.</p>
|
|
|
|
<p>If you work on a team, speak with the other members and decide how strict you want PHPStan to be.</p>
|
|
|
|
<p>Read the rule levels and decide which are the most valuable for your team.</p>
|
|
|
|
<p>If you haven't used PHPStan or static analysis before, maybe start with a lower level.</p>
|
|
|
|
<p>For me, typehints and return type checking are a must, though I like to use as high a level as possible.</p>
|
|
|
|
<p>The more information you can provide to PHPStan, the more it will understand your code, give better results and be more likely to find potential bugs or issues.</p>
|
|
|
|
<h2 id="for-brownfield-projects">For brownfield projects</h2>
|
|
|
|
<p>For existing (brownfield) code, start at the lowest level, which will give you the least number of errors.</p>
|
|
|
|
<p>Fix any errors, exclude any rules you want to ignore or generate a baseline containing any existing errors.</p>
|
|
|
|
<p>If you like, increase the level and repeat the process.</p>
|
|
|
|
<p>Keep increasing the level as long as you feel comfortable, and PHPStan gives you meaningful results.</p>
|
|
|
|
<p>Again, if you haven't used PHPStan or static analysis before, maybe stick with a lower level.</p>
|
|
|
|
<p>If you start with a lower level, you can increase it later.</p>
|
|
|
|
|
|
format: full_html
|
|
processed: |
|
|
<p>Which PHPStan level should you use?</p>
|
|
|
|
<p>PHPStan has different levels.</p>
|
|
|
|
<p>When you run it on your code, the errors you see will depend on what level you set.</p>
|
|
|
|
<p><a href="/daily/2023/11/27/finding-the-best-test-base">In yesterday's email</a>, the first example code block didn't generate an error until level 5 was used.</p>
|
|
|
|
<p>So, how do you know which level to use?</p>
|
|
|
|
<h2 id="for-greenfield-projects">For greenfield projects</h2>
|
|
|
|
<p>For new (greenfield) code, install and configure PHPStan before you write any code and have and have it run automatically as part of a CI pipeline.</p>
|
|
|
|
<p>If you work on a team, speak with the other members and decide how strict you want PHPStan to be.</p>
|
|
|
|
<p>Read the rule levels and decide which are the most valuable for your team.</p>
|
|
|
|
<p>If you haven't used PHPStan or static analysis before, maybe start with a lower level.</p>
|
|
|
|
<p>For me, typehints and return type checking are a must, though I like to use as high a level as possible.</p>
|
|
|
|
<p>The more information you can provide to PHPStan, the more it will understand your code, give better results and be more likely to find potential bugs or issues.</p>
|
|
|
|
<h2 id="for-brownfield-projects">For brownfield projects</h2>
|
|
|
|
<p>For existing (brownfield) code, start at the lowest level, which will give you the least number of errors.</p>
|
|
|
|
<p>Fix any errors, exclude any rules you want to ignore or generate a baseline containing any existing errors.</p>
|
|
|
|
<p>If you like, increase the level and repeat the process.</p>
|
|
|
|
<p>Keep increasing the level as long as you feel comfortable, and PHPStan gives you meaningful results.</p>
|
|
|
|
<p>Again, if you haven't used PHPStan or static analysis before, maybe stick with a lower level.</p>
|
|
|
|
<p>If you start with a lower level, you can increase it later.</p>
|
|
|
|
|
|
summary: null
|
|
field_daily_email_cta: { }
|