Sneak Peek at Anorak

Over the last few months I've been working on my latest side project. I've already mentioned it on Twitter a couple of times, it's Anorak. This blog post explains why I'm working on Anorak and what it'll help developers achieve.

Anorak Logo


Over the last couple of years PHP has started to become a much more respected and recognised language due to work with:

  • The language itself (phpng, which will now be PHP 7)
  • Composer
  • Laravel (and of course other great frameworks)
  • PSR Fig

All of these great changes and packages are making PHP a far more enjoyable language to work with, however we still have some catching up to do! For instance, there is a service for Ruby code called Hound, which upon opening a Pull Request on GitHub, will check the code quality against Ruby standards and leave a comment where the standards haven't been met. This keeps all of the source code in a consistent standard without much manual intervention from the repository owners.

Anorak does exactly the same, but for PHP. It's really simple to get started with too!

Checking PHP code against user-defined standards actually happens to be a pretty complicated process. When I first started working on Anorak I immediately went to PHP_Codesniffer, however I quickly realised that it's a tough beast to work with, I spent too much time battling with the CLI output format and other little quirks.

Looking around a bit more I stumbled upon PHPCheckstyle. It was an almost perfect solution to my needs, the shortcomings were:

  1. It wasn't PSR-0 friendly, so I couldn't load it easily into my Laravel codebase.
  2. It too depended on an XML configuration.
  3. There was also no native PHP array output. All of the reporters were file based.

Thankfully this was easy to fix and a few hours later, after speaking with the current maintainer I got it imported to GitHub with the changes that I needed.

We're now on a path to rewriting PHPCheckstyle to do some awesome stuff:

  1. Full test suite. Test will accompany everything.
  2. More modularity. Checks are independent of each other. They'll simple implement any of three classes:
    1. ASTCheckInterface - providing the check with the full AST node tree
    2. FileCheckInterface - gives the check access to the file itself
    3. TokenCheckInterface - passes through a tokenized version of the file
  3. It should be a lot faster.
  4. Follows SemVer versioning.
  5. New reporters.
  6. Good built-in standards.
  7. No XML configuration files.

Due to the work required on PHPCheckstyle, Anorak is currently unavailable for signups. I want to be able to properly parse files and check against solid standards as a default. Whilst Anorak is currently able to do this, there are a few bugs that it's unable to handle due to the old version of PHPCheckstyle.

I feel that this is a blessing in disguise as it has given me a chance to make Anorak better as soon as it's released. Here is how:

  • The web design now looks really sweet!
  • I'm able to spend some time learning Angular.js and integrate that on the user-profile side of things.
  • It's given me time to play with some ideas that I can implement in Anorak.

All of this means that I'm now able to provide a really great service when it's ready.

Ok, that's great, but how do I use it?

I'm glad you asked. It's really simple!

  1. You login to Anorak via your GitHub account. We only store your email and GitHub account ID so that we can link up your repositories.
  2. In the background we sync your repositories.
  3. Once that's done, you then simply turn on the repository you want to monitor.
  4. Every time someone opens a new pull request that has modified a .php file we check the changes against PSR-1 standards by default.

Great, but I don't use PSR-1.

No problem. Anorak is really easy to setup to your own standards. You simply add a .anorak.yml file to the root of your project and you're able to override the settings.

For example, say you don't like PSR-1, you want to use PSR-2.

standards: "PSR-2"  

I mean, I like PSR-2, but I hate new line braces.

Hey, no worries. You can change that too.

standards: "PSR-2"

lines:  
  braceOnNewLine: false

Done.

It's important to note that these setting names may change in the future.

Awesome! Sign me up!

Unfortunately Anorak isn't quite ready for prime time, I'm still working out some things and developing PHPCheckstyle. In the mean time, sign up to the mailing list to get more information on Anorak as time progresses!


comments powered by Disqus