for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelListType;
use Sonata\MediaBundle\Admin\GalleryHasMediaAdmin as BaseGalleryHasMediaAdmin;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class GalleryHasMediaAdmin extends BaseGalleryHasMediaAdmin
{
/**
* @param \Sonata\AdminBundle\Form\FormMapper $formMapper
*
* @return void
*/
protected function configureFormFields(FormMapper $formMapper)
parent::configureFormFields($formMapper);
$mediaField = $field = $formMapper->get('media');
$field
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
$myVar = 'Value'; $higher = false; if (rand(1, 6) > 3) { $higher = true; } else { $higher = false; }
Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.
$myVar
$higher
$options = $mediaField->getFormConfig()->getOptions();
$options['btn_delete'] = false;
$formMapper
->remove('enabled')
->remove('position')
->add('title', null, ['label' => 'Title', 'attr' => ['style' => 'height: 150px']])
->add('description', null, ['attr' => ['style' => 'height: 150px; width: 400px']])
->add('media', ModelListType::class, $options)
;
}
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.