Squiz Labs Blog - The latest news from the R&D division of Squiz®

Subscribe to our RSS feeds

Analysis of Coding Conventions

Coding standards tend to vary between projects. Even projects that use the same written standard can vary in a number of ways as standards tend to leave a lot of room to apply your own coding style in various areas. To get a better idea of what coding styles PHP developers are using, I used PHP_CodeSniffer to analyse and report on a number of big and small public PHP projects hosted on Github.

The result of the analysis is here: http://squizlabs.github.io/PHP_CodeSniffer/analysis/

There are currently 63 projects being analysed, with trend data recorded for about the last 8 months. The report currently lists 42 different coding style conventions ranging from "how many spaces surround the concat operator" to the classic "tabs or spaces for line indent". The coding conventions are listed from most contentious to least contentious. So the ones at the top show the most variations between projects while the ones at the bottom are generally accepted by all projects.

Each coding convention provides a list of projects that use each of the style variations within it. Clicking on any of those projects will take you to a project-specific report showing the coding conventions used within it and how often the same style is followed within the project. So you can take a look at the coding conventions for CakePHP, Drupal, Symfony2 or even PHP_CodeSniffer itself. 

How did you pick the projects to analyse?

A combination of popular PHP projects on Github, projects that I've used, and projects that have received some attention while the report was being built.

Can you include my project in the report?

If it is a public PHP project on Github, I sure can. All the repositories that are being analysed are listed in the repos.json file.

For each one, I need to know the name of the project, the URL (organisation/repository), the path in the project where PHP_CodeSniffer should start analysing code (default: /), any files or directories that should be ignored (default: none), and a list of additional PHP file extensions to check beyond .php and .inc (default: none). Here is an example:

    "name": "My Project",
    "url": "squizlabs/my-project",
    "path": "src",
    "ignore": "3rdparty/*,includes/*",
    "extensions": "phtml,module"

There are also 63 other examples in the repos.json file to take a look at. Submit a PR or send me a gist on Twitter. If you have no idea what the values should be, get me the Github URL and I'll figure it out for you.

How is the report generated?

From version 2.0.0a2, PHP_CodeSniffer collects metrics about the code it is checking. These are used to determine coding conventions and can be displayed using --report=info. The coding convention report uses a custom PHP_CodeSniffer report that outputs these metrics as a JSON file instead of to the screen. To save a lot of time, a custom coding standard is used to limit checks to just the sniffs that generate the metrics that the report wants to use. Some ugly custom wrapper scripts deal with updating the repostories, keeping trend data for each coding convention, and generating the HTML reports. The whole thing runs through HHVM to make it as fast as possible.

Stay up to date on all PHP_CodeSniffer changes, including new features and releases, by subscribing to the RSS feed or following me on Twitter.

Squiz Matrix Newsletter #481

This week we have a great new feature to report, new Maintenance Mode functions within Squiz Matrix. Continue reading below for more information on all this exciting new development.  

Squiz Matrix Maintenance Mode

Due for release in version 

This feature introduces a new Maintenance Mode within Squiz Matrix, that when enabled, will disable the functionality of specified assets on the front-end, instead printing a maintenance message for your users.

The Maintenance Mode configuration settings can be accessed on the System Maintenance screen of your Squiz Matrix system. 

The Maintenance Mode Settings 

The Maintenance Mode settings allow you to enable Maintenance Mode and modify the associated messages that will be displayed to your users.

Additional fields allow you to modify the affected asset types and root nodes, as well as any root nodes to exclude. By default, Maintenance Mode will affect all Asset BuilderAccount Manager, Custom Form and Checkout Page assets and any associated child asset types.

A Notify status is also available, that can be used prior to undergoing maintenance, notifying your users that site functions will soon be deactivated. This can give users the chance to finish their work, submissions, etc.

The Maintenance Mode Enabled Message

This new Maintenance Mode feature has been added to assist in the system upgrade process, where previously, these assets types would have to be manually edited before an upgrade could start. By effectively automating this process, the upgrading of systems should be more efficient and safer.

Squiz Matrix Newsletter #480

This week we have two new features to report, including new spam prevention tools on the Account Manager Page. Continue reading below for more information on all this week's developments.  

Spam Prevention Tools Extended to Account Manager Page

Due for release in version 

Back in our v4.16.2 release of Squiz Matrix, we introduced three new spam prevention options on the Custom Form and Asset Builder assets. These tools have now been extended to the Account Manager Page.

  • Google reCAPTCHA: allows you to implement Google's free reCAPTCHA anti-bot service, which also servers to digitize books, newspapers and old time radio shows.
  • Honeypot Question: enables the creation of a honeypot or dummy question. This is used to identify spam bots who fill in the field, that would otherwise be left blank by regular users.
  • Submission Time Threshold: uses the time taken between the form load and form submission to help identify possible spam bots, based on a set minimum time.

Each of these new spam prevention options are available for configuration on the Details screen of Account Manager Page assets.

The Google reCAPTCHA settings on the Account Manager Page 

These new options have been added to compliment the existing spam prevention options available on the Account Manager asset, by providing more accessible anti-spam alternatives. 

Improved Modifier Support on Metadata Field Keywords

Due for release in version 

Metadata field keywords allow you to reference the value of a metadata field within another field on the same asset.


While these keywords have always supported the use of keyword modifiers, modifiers did not previously work correctly in cases where the metadata field value contained a keyword replacement. This was due to the modifier being applied before the keyword in the metadata value was replaced.

This feature improves modifier support on these metadata field keywords, to also support modifiers in these cases.

Take the following example: We have a date metadata field with the value %asset_created%. We want to take this value and use it in another metadata field on the asset, modifying the format of the date. The following keyword format will now work correctly:


Squiz Matrix Newsletter #479

We were right back into it after the Queen's Birthday long weekend, releasing version of Squiz Matrix on Tuesday. This was a micro release, containing eight bug fixes.

As always, you can head to the Release Information page of the Squiz Matrix User Manual Library to view our release schedule, as well as find patch notes on all our past versions of Matrix.


This week we have one new feature to report, a new config option to restrict the file types to be served over the system's static URL. Continue reading below for more information on all this week's developments.

New Config Option to Restrict the File Types Available Over a Static URL

Due for release in version 

A new field has been added to Squiz Matrix's System Configuration settings, allowing you to set the file extension types that will be not be served via static URL (as set in the System Static URL field).

This means that any specified file types will not use the system's static root domain ( i.e www.example.com), instead using Matrix's system root URL. Any file types not specified will be served via the static URL.

The Restricted File Extensions via Static Root Domain field can be configured on the System Configuration screen of your system.

Restricted File Extensions via Static Root Domain Field 

In this field, enter a comma-separated list of file type extensions, to restrict from being served via static URL, for example:


This feature has been added to address browser issues associated with certain file types (e.g. PDF files), when served over multiple domains, triggering a potential security concern. By allowing you to specify the file types restricted from being served via the system's static URL, this issue can now be resolved. 

Squiz Matrix Newsletter #478

This week kicked off with new releases of Squiz Matrix. Versions 4.18.7 and were made available Monday, both containing an array of bug fixes.

For more information on these releases, check out the release blog post, here on the Squiz Labs blog.

To view the release schedule for Squiz Matrix, head to the Release Information page on the Squiz Matrix User Manual Library, where you can also find patch notes on all our past releases.


This week we have one new feature to report, a new SOAP function to query the metadata of assets within your system. Continue reading below for more information on this new development.

New SOAP Function to Search Metadata

Due for release in version 

Squiz Matrix's SOAP API Metadata Service asset manages the metadata functions of the system's SOAP Server, including setting and regenerating metadata.

This feature introduces a new MetadataSearch function on this service to return assets matching a set metadata query.

This function takes the following parameters: 

  • FieldID: the ID of the metadata field to search the specified value on.
  • FieldValue: the metadata value to search for.
  • SearchFieldDefaultValue: whether or not to include default values in the search. This parameter is optional.
  • ExactMatch: whether or not the search requires an exact match. This parameter is optional.
  • ResultFormat: the format to output the result of the search, e.g. %asset_name% (#%asset_assetid%). This parameter is optional; leaving this blank will return an array of matching asset IDs.

The format of the MetadataSearch function is as follows: 


The response body of the MetadataSearch functon is as follows:


This new function has been added to provide an alternative to the simple searching metadata on the existing SOAP API Search Service functions. These search functions work in a similar manner to Matrix's Search Page asset, using the system's index tables to return results. On larger systems, this process could potentially be slower to return these results. This new function should provide faster searching of metadata on the SOAP Server, instead directly querying the database to return any assets found.

Squiz Labs

R & D division of Squiz Pty Ltd

Open source web experience management solutions

Squiz Labs is the research and development division of Squiz, the company behind the Squiz Suite of web experience management and development tools.

Our PHP and JavaScript developers are responsible for producing innovative enterprise-quality software while our interface designers and testing team ensure our products both look great and are easy to use.