Backend Development 7 min read

Improving PHP Code Quality with PHING, PHPCS, PHPCPD, and Phan

This article explains how to set up a PHP project with Composer, PHING, and a suite of quality‑checking tools—including PHPCS for coding standards, PHPCPD for duplicate detection, and Phan for deep static analysis—to automatically enforce code quality and reduce manual review effort.

360 Tech Engineering
360 Tech Engineering
360 Tech Engineering
Improving PHP Code Quality with PHING, PHPCS, PHPCPD, and Phan

In this guide we assume familiarity with PHP 7.1, Composer, and PSR‑4 autoloading, and we demonstrate how to create a build.xml file for PHING to run quality checks.

Prerequisite : Install PHING as a development dependency.

$ php composer.phar require --dev phing/phing

Create a basic build.xml file in the project root.

1. Static code analysis : Use PHING to run tools automatically.

2. Code style checking with PHP_CodeSniffer (PHPCS). Install and add a target to build.xml :

$ php composer.phar require --dev squizlabs/php_codesniffer

Running ./bin/phing will now report any PSR‑1/PSR‑2 violations.

3. Duplicate code detection using PHPCPD. Install and add a target:

$ php composer.phar require --dev sebastian/phpcpd

PHPCPD will list cloned code fragments and duplicated lines.

4. Deep static analysis with Phan. Install Phan and its configuration:

$ php composer.phar require --dev phan/phan
'7.1',
  'directory_list' => ['src', 'vendor/symfony/console'],
  'exclude_analysis_directory_list' => ['vendor/'],
];

Add a Phan target to build.xml :

Running the build will now also report type mismatches and other static analysis errors, e.g., incorrect @phpdoc types.

Conclusion : By integrating PHING with PHPCS, PHPCPD, and Phan, you obtain three fully automated tools that enforce coding standards, detect duplicate code, and perform deep static analysis, dramatically reducing manual code‑review time and improving runtime reliability.

code qualityPHPstatic analysisPHINGPhanPHPCPDphpcs
360 Tech Engineering
Written by

360 Tech Engineering

Official tech channel of 360, building the most professional technology aggregation platform for the brand.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.