Last Updated: February 25, 2016
·
531
· emanueleminotto

Symfony 2 Configuration VS Object Calisthenics

I always have a PHPCS live validation of my code with Object Calisthenics rules enabled.
You know, it's hard but helps!

A boring warning always visible is the Symfony 2 Configuration.php where the rule #4 (use only object operator per line) can't be applied if we don't want to go against rule #6 (keep your classes small), so the great and incredible solution is... ignore this warning!

<?php

namespace Acme\Bundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
    /**
     * Generates the configuration tree builder.
     *
     * @return TreeBuilder The tree builder
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('acme_skeleton');

        // @codingStandardsIgnoreStart

        $rootNode
            ->children()
                ->scalarNode('enabled')
                    ->setInfo('Enable the container extension')
                    ->setDefault(true)
                ->end()
            ->end()
        ;

        // @codingStandardsIgnoreEnd
        return $treeBuilder;
    }
}

I suggest to use // @codingStandardsIgnore* only when a vendor's code force you to go against the rules, otherwise the rules are useless.