As developers, we all want to write clean, efficient, and bug-free code. However, it’s easy to make mistakes, especially in a dynamically-typed language like PHP. That’s where static code analysis tools come in handy – they can help you catch common mistakes and improve the quality of your code.

Recently, a new static code analyzer for PHP called Phanalist has been released. What sets it apart from other analyzers is that it’s written in Rust – a language known for its performance, safety, and concurrency features. With Phanalist, you can catch common mistakes in your PHP code, such as missing access modifiers, incorrectly named classes, and undefined method calls, among others. In this article, we’ll take a closer look at Phanalist and see how it can help you write better PHP code.

Phanlist features

Phanalist is designed to help catch common mistakes in PHP code. Currently, it checks for the following issues:

  • Methods without modifiers (private, public & protected)
  • Classes that start with a lowercase letter
  • Calls to undefined methods
  • Methods that return a value without defining a return type
  • Constants that have all letters in lowercase
  • Parameters without any type
  • Correct location for the PHP opening tag

Note that this is not an exhaustive list, and the checks may change over time as the project evolves.

Work in progress:

Phanalist is a relatively new project, and as such, it is still a work in progress. The developer has plans to add more features in the future, including checks for extending undefined classes. Additionally, the project may evolve to include additional checks based on user feedback and contributions from the community.

Technology

Phanalist is written in Rust, a systems programming language that offers better performance and memory safety compared to other languages commonly used for writing static analyzers. By leveraging Rust’s features, Phanalist is able to provide fast and accurate analysis of PHP code, making it a valuable tool for developers looking to improve their code quality.

To use Phanalist, you’ll first need to install the Rust toolchain. Once installed, you can download the Phanalist project and run cargo build. This command will compile the source code and create an executable located inside the target/debug folder. You can then run this executable inside your PHP project to start analyzing your code.

Alternatively, you can use the Docker container provided by Phanalist. Simply run the Docker image inside your PHP project using the following command:

$ docker run -v $(pwd):/var/src ghcr.io/denzyldick/phanalist:latest

This command will mount your current directory inside the container and run Phanalist to analyze your code.

Overall, Phanalist is a promising new tool for PHP developers who want to catch common mistakes and improve the quality of their code. Its use of Rust as the implementation language provides improved performance and safety, while its growing list of checks and planned features make it a tool worth checking out.

Comparison with other PHP static analyzers

Phanalist is not the only PHP static analyzer available. There are several other popular tools in the market, including PHPStan and Psalm. Here’s a brief comparison of Phanalist with these tools:

Features and Capabilities

Like Phanalist, both PHPStan and Psalm are capable of detecting a range of issues in PHP code. However, there are some differences in the types of issues each tool is particularly good at catching.

PHPStan is particularly well-suited for catching type-related issues in PHP code. It supports PHP 7 and above, and can detect issues such as undefined variables, incorrect method calls, and missing return types.

Psalm, on the other hand, is a bit more flexible in terms of what it can detect. It supports PHP 5.6 and above, and can detect a range of issues such as invalid argument types, incorrect method calls, and unused code.

Phanalist is still a work in progress, but currently supports a limited set of checks, such as methods without modifiers, lowercase class names, and incorrect PHP opening tags. However, more features are planned for the future.

Performance and Safety

One of the key advantages of Phanalist is that it is written in Rust, a systems programming language that prioritizes performance and safety. Rust’s memory safety features and lack of garbage collection make it a good choice for building tools like static analyzers.

PHPStan and Psalm, on the other hand, are both written in PHP. While this makes them more accessible to PHP developers who may not be familiar with Rust, it also means they may be slower and less safe than Phanalist.

Integration with Other Tools

All three tools offer integration with popular IDEs like Visual Studio Code, as well as with build systems like Composer and Travis CI. However, the exact level of integration may vary.

PHPStan and Psalm both have plugins available for popular frameworks like Symfony and Laravel, which can help to catch issues specific to those frameworks. It’s unclear whether Phanalist will offer similar plugins in the future.

Overall, while Phanalist is still a young project with limited features, its use of Rust and focus on performance and safety make it a promising addition to the world of PHP static analysis.

Conclusion

In conclusion, Phanalist is a promising new static code analyzer for PHP that offers several benefits over other similar tools. With a focus on catching common mistakes and enforcing good coding practices, Phanalist can help developers improve the quality and reliability of their PHP code. Additionally, being written in Rust, Phanalist offers better performance and safety than other languages commonly used for writing static analyzers.

While the project is still a work in progress, it already includes several useful checks, and more features are planned for future releases. If you’re interested in using Phanalist for your PHP development, you can compile and run it locally or in a Docker container. And if you’re feeling adventurous, you can even contribute to the project by submitting bug reports, feature requests, or code improvements.

Of course, Phanalist is not the only PHP static analyzer available today. Other popular tools like PHPStan and Psalm also offer their own unique features and capabilities. When choosing a tool, it’s important to consider your specific needs and requirements, as well as the strengths and weaknesses of each option.

In any case, we encourage you to give Phanalist a try and see for yourself how it can help you improve your PHP code. Happy coding!

More information at https://github.com/denzyldick/phanalist

LEAVE A REPLY

Please enter your comment!
Please enter your name here