Mezzio Example: Psalm Introduction


What is Psalm?

Psalm is a static analysis tool for PHP that helps you identify problems with your code. If you use it, you’ll become a better coder. I promise.

Learn more about Psalm

Here’s a great read – the story of the origins of Psalm at Vimeo and the value it provided the team.

https://psalm.dev/articles/fixing-code-that-aint-broken

In this post, I’ll show a basic setup for static analysis with Psalm in Mezzio applications.

Configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0"?>
<psalm
        errorLevel="1"
        cacheDirectory="data/cache/.psalm_cache"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="https://getpsalm.org/schema/config"
        xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
    <projectFiles>
        <directory name="src"/>
        <directory name="test"/>
        <ignoreFiles>
            <directory name="config"/>
            <directory name="vendor"/>
        </ignoreFiles>
    </projectFiles>
    <plugins>
        <pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
    </plugins>
</psalm>

Changes Required for Psalm Error Level 1

It’s probably easiest to read the diff here:

https://github.com/marcguyer/mezzio-doctrine-oauth2-example/commit/b1b781a85eeef46c4f7168ea0670219dd40753af

What’s Next?

The next post in this series adds Doctrine Entity classes and tests. We’ll create only those models necessary for a baseline OAuth2 implementation.


Series: Mezzio Example

  1. Mezzio Example: Introduction
  2. Mezzio Example: Functional and Unit Testing
  3. Mezzio Example: Psalm Introduction
  4. Mezzio Example: Doctrine Entities and Repositories
comments powered by Disqus