Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

David Négrier:
Type-Hint All The Things
Jul 05, 2017 @ 12:52:53

In this new post to his site David Négrier talks about "type hinting all the things" in response to a recent controversy around "clean code" and "visual debt" in PHP code.

Recently, a video about "visual debt" as sparked a lot of controversy in the PHP world. In this article, I'll present the best practices we are using at TheCodingMachine, and a brand new tool we use to enforce those best practices.

If you haven’t seen the video yet, you can have a look at it on Laracast. At some point, the video advocates to remove the type-hints because they are not needed by the program and are "visually polluting" the code.

He then breaks down his look at type hinting and the benefits they can provide into a few sections:

  • Type-hints are good
  • Type-hints have improved (… but there is still a long road to go)
  • Enforcing type-hints

He also covers some of their own best practices when it comes to type hinting in their code and shares a phpstan package that they use to enforce typing and formatting based on their own standards.

tagged: typehint bestpractice visualdebt package phpstan

Link: https://www.thecodingmachine.com/type-hint-all-the-things/

Ondrej Mirtes:
How I Got From 0 to 1 000 Stars on GitHub in Three Months With My Open Source Side Pr
Mar 08, 2017 @ 10:37:39

Ondrej Mirtes has offered some advice in this Medium.com post sharing some of his experience in the development and management of his PHPStan project (static analysis for bug detection).

Most developers have side projects. That's how we try out new things or make something that we miss on the market or in our dev stack. But most side projects end up unfinished and never actually see the light of day. And even if a developer builds up the courage to show his work to the public, he quickly finds out that just publishing a repository doesn't actually bring the masses to his doorstep.

At the beginning of last December, I released PHPStan? - ?static analysis tool for PHP that focuses on finding bugs. The project gained a lot of traction resulting in currently over 1 300 stars on GitHub and more than 30 000 downloads on Packagist.

He spends the rest of the article sharing the things he did to make sure that the project "didn't end up in the dustbin of history" and be successful. Topics include:

  • Build the hard stuff first
  • Serve market needs
  • Promotion
  • Ask for money

He ends with what he sees as the most important part of any good open source project - as a maintainer you need to "be nice". This means being responsive to incoming feedback, keeping in mind that people contribute/comment because they care about the project (and it's not usually about you).

tagged: opensource project advice phpstan needs promotion money nice

Link: https://medium.com/@ondrejmirtes/how-i-got-from-0-to-1-000-stars-on-github-in-three-months-with-my-open-source-side-project-8ffe4725146#.wihwnsy8u

Medium.com:
The Three Pillars of Static Analysis in PHP
Dec 12, 2016 @ 13:06:03

In this post over on Medium.com Ond?ej Mirtes looks at what he calls the "Three Pillars of Static Analysis in PHP" - three kinds of testing you can do to catch errors "at rest" in your codebase.

My credo is that everything that can be automated should be automated. Computers are really good at repeating tedious tasks and they don’t usually make mistakes while us squishy humans are defined by making mistakes everywhere we go.

[...] In the following article, I’d like to introduce three tools that will help you to find errors and inconsistencies in your codebase. If your build integrating these tools finishes successfully, you can be pretty sure your application is in a good shape.

His list of three tools covers checking for:

He covers some of the things the last option verifies and links to another introductory article about the tool to help you get started.

tagged: static analysis pillars lint codesniffer phpstan code

Link: https://medium.com/@ondrejmirtes/three-pillars-of-static-analysis-in-php-f3f5d7bfd61b#.etoa1rfkq

Medium.com:
PHPStan: Find Bugs In Your Code Without Writing Tests!
Dec 05, 2016 @ 13:25:38

In this post on Medium.com Ond?ej Mirtes introduces a tool that can be use to statically analyze your PHP application and locate bugs without the need for tests - PHPStan.

Keeping up with modern PHP practices leads to codebases where we can be sure about types of a lot of data, converging with statically typed languages, although the dynamic nature is still present. Modern PHP codebases are similar to the ones in languages people make much less fun of. Object-oriented code, dependency injection and usage of established design patterns are truly common nowadays.

Which led me to the idea of a static analysis tool for PHP that would substitute the role of the compiler from other languages. I’ve spent a lot of time working on it and I’ve been employing its various development versions checking our codebase for more than a year.

It’s called PHPStan, it’s open-source and free to use.

The post goes on to talk about some of the checks that PHPStan performs (with more information available in the project's README). He also talks about the performance of the tool, how to extend it and configuring it for "strictness". He ends the post by pointing out that, despite the title of the article, he still encourages writing tests, just making sure they're "meaningful ones" that test more than just syntax.

tagged: phpstan static analysis tool tests evaluation

Link: https://medium.com/@ondrejmirtes/phpstan-2939cd0ad0e3#.23491arlh