Symfony controller action method should not be too long

  • Major
  • Readability

More information: https://insight.sensiolabs.com/what-we-analyse/symfony.controller.action_method_too_long

63% of all actions have more than 20 lines. This violation is raised when more than 10% actions are too long.

Time to fix: about 2 hours
Open Issue Permalink
Collective

Occurences of the rule violations:

Public methods in controller classes should only be actions (with the <code>Action</code> suffix) 4

  • Major
  • Architecture

More information: https://insight.sensiolabs.com/what-we-analyse/symfony.controller.non_action_public_method_in_controller_class

  1. *
  2. * @param Request $request Symfony request object
  3. * @param integer $pageId Page identifier
  4. * @param integer $blockId Block identifier
  5. */
  6. public function execute(Request $request, $pageId, $blockId)

    Non-action public method found in controller class

    Time to fix: about 1 hour
    Open Issue Permalink
    Collective
  7. {
  8. $cmsManager = $this->cmsManagerSelector->retrieve();
  9. $page = $cmsManager->getPageById($pageId);
  10. $block = $cmsManager->getBlock($blockId);
  1. *
  2. * @return \Symfony\Component\HttpFoundation\RedirectResponse
  3. *
  4. * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  5. */
  6. public function batchActionSnapshot($query)

    Non-action public method found in controller class

    Time to fix: about 1 hour
    Open Issue Permalink
    Collective
  7. {
  8. if (!$this->get('security.context')->isGranted('ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT')) {
  9. throw new AccessDeniedException();
  10. }
  1. }
  2. /**
  3. * @return \Sonata\PageBundle\Listener\ExceptionListener
  4. */
  5. public function getExceptionListener()

    Non-action public method found in controller class

    Time to fix: about 1 hour
    Open Issue Permalink
    Collective
  6. {
  7. return $this->get('sonata.page.kernel.exception_listener');
  8. }
  9. }
  1. *
  2. * @return \Symfony\Component\HttpFoundation\RedirectResponse
  3. *
  4. * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  5. */
  6. public function batchActionToggleEnabled($query)

    Non-action public method found in controller class

    Time to fix: about 1 hour
    Open Issue Permalink
    Collective
  7. {
  8. if (!$this->get('security.context')->isGranted('ROLE_SONATA_PAGE_ADMIN_BLOCK_EDIT')) {
  9. throw new AccessDeniedException();
  10. }

Files should not be executable

  • Major
  • Security

More information: https://insight.sensiolabs.com/what-we-analyse/php.too_permissive_file_permissions

Your project contains files with permissive permissions. In order to avoid opening a security breach, you should restrict execution rights on following files:

Time to fix: about 30 minutes
Open Issue Permalink
Collective

Object parameters should be type hinted 9

  • Minor
  • Bugrisk

More information: https://insight.sensiolabs.com/what-we-analyse/php.object_parameter_not_type_hinted

  1. *
  2. * @return \Symfony\Component\HttpFoundation\RedirectResponse
  3. *
  4. * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  5. */
  6. public function batchActionSnapshot($query)

    The parameter query, which is an object, should be typehinted.

    Time to fix: about 1 hour
    Open Issue Permalink
    Collective
  7. {
  8. if (!$this->get('security.context')->isGranted('ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT')) {
  9. throw new AccessDeniedException();
  10. }
  1. *
  2. * @return \Symfony\Component\HttpFoundation\RedirectResponse
  3. *
  4. * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  5. */
  6. public function batchActionToggleEnabled($query)

    The parameter query, which is an object, should be typehinted.

    Time to fix: about 1 hour
    Open Issue Permalink
    Collective
  7. {
  8. if (!$this->get('security.context')->isGranted('ROLE_SONATA_PAGE_ADMIN_BLOCK_EDIT')) {
  9. throw new AccessDeniedException();
  10. }
in Admin/BlockAdmin.php, line 134
  1. }
  2. /**
  3. * {@inheritdoc}
  4. */
  5. public function preUpdate($object)

    The parameter object, which is an object, should be typehinted.

    Time to fix: about 1 hour
    Open Issue Permalink
    Collective
  6. {
  7. $this->blockManager->get($object)->preUpdate($object);
  8. // fix weird bug with setter object not being call
  9. $object->setChildren($object->getChildren());
in Admin/BlockAdmin.php, line 158
  1. }
  2. /**
  3. * {@inheritdoc}
  4. */
  5. public function prePersist($object)

    The parameter object, which is an object, should be typehinted.

    Time to fix: about 1 hour
    Open Issue Permalink
    Collective
  6. {
  7. $this->blockManager->get($object)->prePersist($object);
  8. $object->getPage()->setEdited(true);
in Admin/PageAdmin.php, line 261
  1. }
  2. /**
  3. * {@inheritdoc}
  4. */
  5. public function postUpdate($object)

    The parameter object, which is an object, should be typehinted.

    Time to fix: about 1 hour
    Open Issue Permalink
    Collective
  6. {
  7. if ($this->cacheManager) {
  8. $this->cacheManager->invalidate(array(
  9. 'page_id' => $object->getId()
  10. ));
in Admin/PageAdmin.php, line 273
  1. }
  2. /**
  3. * {@inheritdoc}
  4. */
  5. public function update($object)

    The parameter object, which is an object, should be typehinted.

    Time to fix: about 1 hour
    Open Issue Permalink
    Collective
  6. {
  7. $object->setEdited(true);
  8. $this->preUpdate($object);
  9. $this->pageManager->save($object);
in Admin/PageAdmin.php, line 285
  1. }
  2. /**
  3. * {@inheritdoc}
  4. */
  5. public function create($object)

    The parameter object, which is an object, should be typehinted.

    Time to fix: about 1 hour
    Open Issue Permalink
    Collective
  6. {
  7. $object->setEdited(true);
  8. $this->prePersist($object);
  1. }
  2. /**
  3. * {@inheritdoc}
  4. */
  5. public function postUpdate($object)

    The parameter object, which is an object, should be typehinted.

    Time to fix: about 1 hour
    Open Issue Permalink
    Collective
  6. {
  7. $this->cacheManager->invalidate(array(
  8. 'page_id' => $object->getPage()->getId()
  9. ));
  10. }
  1. }
  2. /**
  3. * {@inheritdoc}
  4. */
  5. public function postPersist($object)

    The parameter object, which is an object, should be typehinted.

    Time to fix: about 1 hour
    Open Issue Permalink
    Collective
  6. {
  7. $this->cacheManager->invalidate(array(
  8. 'page_id' => $object->getPage()->getId()
  9. ));
  10. }

User specific files should not appear in .gitignore 3

  • Minor
  • Codestyle

More information: https://insight.sensiolabs.com/what-we-analyse/git.user_specific_ignored_file

in .gitignore, line 1
  1. .idea

    .idea is user-specific and should not appear in a project .gitignore. Consider adding it to the user global .gitignore instead.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  2. .DS_Store
  3. build
  4. phpunit.xml
  5. Resources/doc/_build/*
  6. nbproject
in .gitignore, line 2
  1. .idea
  2. .DS_Store

    .DS_Store is user-specific and should not appear in a project .gitignore. Consider adding it to the user global .gitignore instead.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  3. build
  4. phpunit.xml
  5. Resources/doc/_build/*
  6. nbproject
  7. coverage
in .gitignore, line 6
  1. .idea
  2. .DS_Store
  3. build
  4. phpunit.xml
  5. Resources/doc/_build/*
  6. nbproject

    nbproject is user-specific and should not appear in a project .gitignore. Consider adding it to the user global .gitignore instead.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  7. coverage
  8. composer.lock
  9. vendor

Unused method, property, variable or parameter 8

  • Minor
  • Deadcode

More information: https://insight.sensiolabs.com/what-we-analyse/php.unused_local_variable_or_private_member

  1. *
  2. * @param Request $request Symfony request object
  3. * @param integer $pageId Page identifier
  4. * @param integer $blockId Block identifier
  5. */
  6. public function execute(Request $request, $pageId, $blockId)

    This request argument is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  7. {
  8. $cmsManager = $this->cmsManagerSelector->retrieve();
  9. $page = $cmsManager->getPageById($pageId);
  10. $block = $cmsManager->getBlock($blockId);
  1. */
  2. public function execute(Request $request, $pageId, $blockId)
  3. {
  4. $cmsManager = $this->cmsManagerSelector->retrieve();
  5. $page = $cmsManager->getPageById($pageId);

    This page local variable is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  6. $block = $cmsManager->getBlock($blockId);
  7. if (!$block instanceof BlockInterface) {
  8. throw new BlockNotFoundException(sprintf('Unable to find block identifier "%s" in page "%s".', $blockId, $pageId));
  9. }
in Admin/PageAdmin.php, line 103
  1. ->add('type', null, array('field_type' => 'sonata_page_type_choice'))
  2. ->add('pageAlias')
  3. ->add('parent')
  4. ->add('edited')
  5. ->add('hybrid', 'doctrine_orm_callback', array(
  6. 'callback' => function($queryBuilder, $alias, $field, $data) {

    This field argument is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  7. if (in_array($data['value'], array('hybrid', 'cms'))) {
  8. $queryBuilder->andWhere(sprintf('%s.routeName %s :routeName', $alias, $data['value'] == 'cms' ? '=' : '!='));
  9. $queryBuilder->setParameter('routeName', PageInterface::PAGE_ROUTE_CMS_NAME);
  10. }
  11. },
  1. $input->getOption('mode'),
  2. $input->getOption('keep-snapshots'),
  3. $input->getOption('no-debug') ? '--no-debug' : ''
  4. ));
  5. $p->run(function($type, $data) use ($output) {

    This type argument is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  6. $output->write($data, OutputInterface::OUTPUT_RAW);
  7. });
  8. }
  9. }
  1. $output->writeln(" done!");
  2. } else {
  3. $p = new Process(sprintf('%s sonata:page:create-snapshots --env=%s --site=%s --mode=%s %s ', $input->getOption('base-console'), $input->getOption('env'), $site->getId(), $input->getOption('mode'), $input->getOption('no-debug') ? '--no-debug' : ''));
  4. $p->run(function($type, $data) use ($output) {

    This type argument is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  5. $output->write($data, OutputInterface::OUTPUT_RAW);
  6. });
  7. }
  8. }
  1. if (!$manager instanceof CmsManagerInterface) {
  2. throw new RuntimeException('The service does not implement the CmsManagerInterface');
  3. }
  4. $page = $manager->getPageById($input->getArgument('page_id'));

    This page local variable is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  5. $block = $manager->getBlock($input->getArgument('block_id'));
  6. if (!$block) {
  7. throw new \RuntimeException('Unable to find the related block');
  1. $this->updateRoutes($site, $output);
  2. $output->writeln("");
  3. } else {
  4. $p = new Process(sprintf('%s sonata:page:update-core-routes --env=%s --site=%s %s', $input->getOption('base-command'), $input->getOption('env'), $site->getId(), $input->getOption('no-debug') ? '--no-debug' : ''));
  5. $p->run(function($type, $data) use ($output) {

    This type argument is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  6. $output->write($data);
  7. });
  8. }
  9. }
  1. * @return void
  2. */
  3. private function updateRoutes(SiteInterface $site, OutputInterface $output)
  4. {
  5. $router = $this->getContainer()->get('router');
  6. $cmsManager = $this->getCmsPageManager();

    This cmsManager local variable is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  7. $pageManager = $this->getPageManager();
  8. $decorator = $this->getDecoratorStrategy();
  9. $message = sprintf(" > <info>Updating core routes for site</info> : <comment>%s - %s</comment>", $site->getName(), $site->getUrl());

Unused use statement should be avoided 8

  • Minor
  • Deadcode

More information: https://insight.sensiolabs.com/what-we-analyse/php.unused_use_statement

  1. */
  2. namespace Sonata\PageBundle\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;

    The class Symfony\Component\HttpFoundation\Response is declared but never used. You should remove the use statement.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  5. use Sonata\BlockBundle\Exception\BlockNotFoundException;
  6. use Sonata\BlockBundle\Model\BlockInterface;
  7. use Sonata\BlockBundle\Block\BlockRendererInterface;
  1. namespace Sonata\PageBundle\Controller;
  2. use Sonata\PageBundle\Exception\PageNotFoundException;
  3. use Sonata\PageBundle\Exception\InternalErrorException;
  4. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  5. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

    The class Symfony\Component\HttpKernel\Exception\NotFoundHttpException is declared but never used. You should remove the use statement.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  8. /**
  9. * Page controller
  1. */
  2. namespace Sonata\PageBundle\Command;
  3. use Guzzle\Common\Exception\RuntimeException;
  4. use Sonata\BlockBundle\Model\BlockInterface;

    The class Sonata\BlockBundle\Model\BlockInterface is declared but never used. You should remove the use statement.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  5. use Sonata\BlockBundle\Tests\Block\BlockContextManagerTest;
  6. use Sonata\PageBundle\CmsManager\CmsManagerInterface;
  7. use Symfony\Component\Console\Input\InputArgument;
  8. use Symfony\Component\Console\Input\InputOption;
  9. use Symfony\Component\Console\Input\InputInterface;
  1. namespace Sonata\PageBundle\Command;
  2. use Guzzle\Common\Exception\RuntimeException;
  3. use Sonata\BlockBundle\Model\BlockInterface;
  4. use Sonata\BlockBundle\Tests\Block\BlockContextManagerTest;

    The class Sonata\BlockBundle\Tests\Block\BlockContextManagerTest is declared but never used. You should remove the use statement.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  5. use Sonata\PageBundle\CmsManager\CmsManagerInterface;
  6. use Symfony\Component\Console\Input\InputArgument;
  7. use Symfony\Component\Console\Input\InputOption;
  8. use Symfony\Component\Console\Input\InputInterface;
  9. use Symfony\Component\Console\Output\OutputInterface;
  1. use Guzzle\Common\Exception\RuntimeException;
  2. use Sonata\BlockBundle\Model\BlockInterface;
  3. use Sonata\BlockBundle\Tests\Block\BlockContextManagerTest;
  4. use Sonata\PageBundle\CmsManager\CmsManagerInterface;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputOption;

    The class Symfony\Component\Console\Input\InputOption is declared but never used. You should remove the use statement.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  7. use Symfony\Component\Console\Input\InputInterface;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. use Symfony\Component\HttpFoundation\Request;
  10. /**
  1. use Sonata\BlockBundle\Model\BlockInterface;
  2. use Sonata\PageBundle\Model\PageInterface;
  3. use Sonata\PageBundle\Model\SiteInterface;
  4. use Symfony\Component\HttpFoundation\Request;

    The class Symfony\Component\HttpFoundation\Request is declared but never used. You should remove the use statement.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  5. /**
  6. * The CmsManagerInterface class is in charge of retrieving the correct page (cms page or action page)
  7. *
  8. * An action page is linked to a symfony action and a cms page is a standalone page.
  1. use Sonata\PageBundle\Exception\PageNotFoundException;
  2. use Sonata\PageBundle\CmsManager\DecoratorStrategyInterface;
  3. use Sonata\PageBundle\Model\PageInterface;
  4. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  5. use Symfony\Component\HttpFoundation\Request;

    The class Symfony\Component\HttpFoundation\Request is declared but never used. You should remove the use statement.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  6. /**
  7. * This class redirect the onCoreResponse event to the correct
  8. * cms manager upon user permission
  9. *
  1. */
  2. namespace Sonata\PageBundle\Listener;
  3. use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
  4. use Symfony\Component\HttpFoundation\Request;

    The class Symfony\Component\HttpFoundation\Request is declared but never used. You should remove the use statement.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Collective
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\Cookie;
  7. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  8. use Sonata\PageBundle\Page\PageServiceManagerInterface;