Home

Awesome

<img src="https://raw.githubusercontent.com/denzyldick/phanalist/main/docs/branding/banner-cropped.png"/>

Performant static analyzer for PHP, which is extremely easy to use. It helps you catch common mistakes in your PHP code.

Installation

The simplest way to install Phanalist is to use the installation script.

curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/denzyldick/phanalist/main/bin/init.sh | sh

It will automatically download the executable for your platform:

$ ~/phanalist -V
phanalist 1.0.0

There are also multiple other installation options.

Usage

To analyze your project sources, you just need to run phanalist:

~/phanalist

Example

Example

On the first run phanalist.yaml will be created with the default configurations. And it will be reused on all the following runs.

There are also a few additional parameters:

Configuration

The possible options are:

The default configuration file is:

enabled_rules: []
disable_rules: []
rules:
  E0007:
    check_constructor: true
    max_parameters: 5
  E0009:
    max_complexity: 10
  E0010:
    max_paths: 200
  E0012:
    include_namespaces:
      - "App\\Service\\"
      - "App\\Controller\\"
    exclude_namespaces: []

Rules

The following rules are available:

CodeNameDefault options
E0000Example rule
E0001Opening tag position
E0002Empty catch
E0003Method modifiers
E0004Uppercase constants
E0005Capitalized class name
E0006Property modifiers
E0007Method parameters countcheck_constructor: true, max_parameters: 5
E0008Return type signature
E0009Cyclomatic complexitymax_complexity: 10
E0010Npath complexitymax_complexity: 200
E0011Detect error supression symbol(@)
E0012Service compatibility with Shared Memory Modelinclude_namespaces: ["App\Service\"],<br/>exclude_namespaces: [],<br/>reset_interfaces: ["ResetInterface"]
E0013Private method not being used

Adding a new rule is a simple task, and this tutorial explains how to do it.

Articles

Read a series of chapters on https://dev.to/denzyldick to understand the project's internals. It is a great, easy-to-read introduction to this project.

  1. Write your own static analyzer for PHP.
  2. How I made it impossible to write spaghetti code.
  3. Detecting spaghetti code in AST of a PHP source code.
  4. Getting Symfony app ready for Swoole, RoadRunner, and FrankenPHP (no AI involved).
  5. Improve your CI output
  6. Why using unserialize in PHP is a bad idea