for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Sugarcrm\UpgradeSpec\DI\Compiler;
use Sugarcrm\UpgradeSpec\Data\DataAwareInterface;
use Sugarcrm\UpgradeSpec\Template\RendererAwareInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;
class SpecElementPass implements CompilerPassInterface
{
/**
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
if (!$container->has('element.provider')) {
return;
}
$providerDefinition = $container->findDefinition('element.provider');
$elements = [];
foreach (array_keys($container->findTaggedServiceIds('element.section')) as $id) {
if (!$container->has($id)) {
$elementDefinition = $container->findDefinition($id);
$elementClass = $elementDefinition->getClass();
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.
$reflectionClass = new \ReflectionClass($elementClass);
if ($reflectionClass->implementsInterface(RendererAwareInterface::class)) {
if (!$container->has('template.renderer')) {
$elementDefinition->addMethodCall('setRenderer', [new Reference('template.renderer')]);
if ($reflectionClass->implementsInterface(DataAwareInterface::class)) {
if (!$container->has('data.manager')) {
$elementDefinition->addMethodCall('setDataManager', [new Reference('data.manager')]);
$elements[] = new Reference($id);
$providerDefinition->addMethodCall('addElements', [$elements]);
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.