for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
<?php
declare(strict_types = 1);
namespace Innmind\CommandBusBundle\DependencyInjection\Compiler;
use Innmind\CommandBusBundle\Exception\LogicException;
use Symfony\Component\DependencyInjection\{
ContainerBuilder,
Compiler\CompilerPassInterface
};
final class RegisterHandlersPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
$ids = $container->findTaggedServiceIds('innmind_command_bus.handler');
$services = [];
foreach ($ids as $id => $tags) {
foreach ($tags as $tag => $attributes) {
if (!isset($attributes['handles'])) {
throw new LogicException;
}
$services[$attributes['handles']] = $id;
$container
->getDefinition('innmind_command_bus.default')
->replaceArgument(1, $services);