PHP CodeSniffer: Ignoring rules

PHP CodeSniffer is a great tool for making sure all your code is consistent with a set of rules and guidelines. However, there are cases, when you need to ignore the rules for a particular code snippet. For example, when you are working with third-party frameworks or libraries.

CodeSniffer provides a number of ways to do this. Until today, the following worked well for me:

// @CodingStandardsIgnoreStart
echo "Here goes some code that breaks the rules";
// @CodingStandardsIgnoreEnd

This is particularly useful for code within functions and methods. But what if you need to ignore a particular rule for the whole file, especially in places like method names, which are difficult to surround by starting and ending annotation tags?

Here’s an example that worked for me (thanks to this comment for the solution):

<?php
/**
 * @phpcs:disable CakePHP.NamingConventions.ValidFunctionName.PublicWithUnderscore
 */

The only bit that you’d probably need now is an easy way to find the name of the rule from the CodeSniffer output. The usual output of “./vendor/bin/phpcs” looks like so:

FILE: src/Model/Table/KeysTable.php
-----------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------
 53 | ERROR | Public method name "KeysTable::_initializeSchema" must not be prefixed with underscore
-----------------------------------------------------------------------------------------------------

But if you run it with the “-s” flag (thanks to this comment), CodeSniffer will add sniff codes to all reports. Here’s the same example with “./vendor/bin/phpcs -s“:

FILE: src/Model/Table/KeysTable.php
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 53 | ERROR | Public method name "KeysTable::_initializeSchema" must not be prefixed with underscore
    |       | (CakePHP.NamingConventions.ValidFunctionName.PublicWithUnderscore)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------

And that’s the code sniff rule that you can add to the ignore annotation tag at the top of your file, like I’ve shown above.

P3.express – practical project management framework

When it comes to project management, there are many certifications, guidelines, and suggestions all over the web. But it’s often difficult to pick the right one. Some are overly complicated. Others are too simplistic and don’t cover even the whole project lifespan.

P3.express, however, looks good. It covers the project management process from the early days, when it’s not even clear if the project will proceed at all, to the tasks that need to happen after the project has been fully completed. The whole flow consists of 37 activities in 7 sections, with each one of the activities being well documented and explained.

This one is definitely worth a try. Especially if you ever felt like this:

API Platform – REST and GraphQL framework to build modern API-driven projects

API Platform is a framework for building API-driven projects. I came across this via this blog post that covers the recent release of v2.4. The list of features and components is quite extensive:

  • Read and write support for MongoDB
  • Read support for Elasticsearch
  • Message queues support via a number of brokers, including Amazon SQS
  • Server Push support for HTTP/2
  • Full compatibility with OpenAPI v3 (Swagger)
  • Automated admin interface and project documentation
  • A variety of components from the Symfony framework

I’m pretty sure that I’ll be taking this for a spin in the nearest future!

Stop Learning Frameworks

Stop Learning Frameworks” is exactly what I’ve been saying and doing for years.

Technology come and go, but it has a lot in common. Set priorities right. Invest 80% of your learning time in fundamentals. Leave 20% for frameworks, libraries and tools.

After 20 or so years working with technology, it always amazes me how most of the new and cool tech is actually another iteration on something that existed and has been used since forever.

Cloud computing, and even the newest hype of serverless architectures, are just another iteration on the ever-going problem of large and centralized versus small and decentralized (mainframes, PC, terminal servers and thin clients, and on, and on, and on).  NoSQL databases have a very familiar feeling to anyone who have worked with LDAP.  All the modern instant messengers iterate over the same problems (and often solutions) from the ancient protocols – NNTP, email (POP, IMAP, SMTP), IRC, and tools that implemented them for different purposes.  And on, and on it goes.

There isn’t enough time in the world to learn even a fraction of all that technology.  But focusing on the fundamentals helps a lot.  If there was one thing to add, I’d also prioritize open technologies and formats versus proprietary.  Open technologies survive the longest and tend to be reused a lot more.

Inflected – a port of ActiveSupport’s inflector to Node.js and the browser


For the last few years I have been heavily involved in building web applications with the CakePHP framework.  Apart from all the usual MVC, ORM, and so on, and so forth, features, I am a big fan of the CakePHP utilities.  And among all of them, my long time favorite is the Inflector class.

The Inflector class makes makes word transformations a breeze – camel-casing, snake-casing, plural, singular, and so on – work like a charm at least for the English language.  It’s also possible to use the same functionality for other languages, but that would require quite a bit of the linguistic expertise.

I’ve got so used to the inflections that I miss them every single time I have to step out of the CakePHP framework.  This doesn’t happen very often for me in the PHP domain, but JavaScript is a totally different story.

The other day I came across the inflected library, which brings most of the CakePHP’s Inflector to JavaScript, via either a Node.JS NPM package, or a simple inclusion of the JavaScript file to the page source and laying off all the hard work on to the browser.

I’m a lot happier with my universe now.