for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Fi\CoreBundle\Subscriber;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
class TablePrefixSubscriber implements \Doctrine\Common\EventSubscriber
{
protected $prefix = '';
public function __construct($prefix)
$this->prefix = (string) $prefix;
}
public function getSubscribedEvents()
return array('loadClassMetadata');
public function loadClassMetadata(LoadClassMetadataEventArgs $args)
$classMetadata = $args->getClassMetadata();
if (false !== strpos($classMetadata->namespace, 'Fi\CoreBundle')) {
$classMetadata->setPrimaryTable(array('name' => $this->prefix.$classMetadata->getTableName()));
foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY
&& isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])
) {
$mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name'];
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
$a = "a"; $ab = "ab"; $abc = "abc";
will produce issues in the first and second line, while this second example
will produce no issues.
$classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix.$mappedTableName;
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.