for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace AppBundle\Controller;
use AppBundle\Legacy\Traits\LegacyTemplateTrait;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AbstractController extends Controller
{
use LegacyTemplateTrait;
/**
* Sets the container.
*
* There is no container available in the constructor of a controller, so we override setContainer() and use this
* @param \Symfony\Component\DependencyInjection\ContainerInterface|null $container A ContainerInterface instance or null.
* @return void
*/
public function setContainer(ContainerInterface $container = null)
parent::setContainer($container);
$requestStack = $container->get('request_stack');
$container
null
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:
function someFunction(A $objectMaybe = null) { if ($objectMaybe instanceof A) { $objectMaybe->doSomething(); } }
/** @var \Symfony\Component\HttpFoundation\Request $masterRequest */
$masterRequest = $requestStack->getMasterRequest();
if ($masterRequest) {
$this->setTarget($masterRequest->getUri());
}
* @param string $message
protected function addErrorMessage($message)
$this->addFlash('error', $message);
protected function addSuccessMessage($message)
$this->addFlash('success', $message);
protected function addInfoMessage($message)
$this->addFlash('info', $message);
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: