GalleryHasMediaAdmin::configureFormFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 16
ccs 0
cts 11
cp 0
crap 2
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace App\Admin;
4
5
use Sonata\AdminBundle\Form\FormMapper;
6
use Sonata\AdminBundle\Form\Type\ModelListType;
7
use Sonata\MediaBundle\Admin\GalleryHasMediaAdmin as BaseGalleryHasMediaAdmin;
8
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
9
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
10
use Symfony\Component\Form\Extension\Core\Type\TextType;
11
12
class GalleryHasMediaAdmin extends BaseGalleryHasMediaAdmin
13
{
14
    /**
15
     * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
16
     *
17
     * @return void
18
     */
19
    protected function configureFormFields(FormMapper $formMapper)
20
    {
21
        parent::configureFormFields($formMapper);
22
23
        $mediaField = $field = $formMapper->get('media');
0 ignored issues
show
Unused Code introduced by
$field is not used, you could remove the assignment.

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.

Loading history...
24
        $options    = $mediaField->getFormConfig()->getOptions();
25
        $options['btn_delete'] = false;
26
27
        $formMapper
28
            ->remove('enabled')
29
            ->remove('position')
30
            ->add('title', null, ['label' => 'Title', 'attr' => ['style' => 'height: 150px']])
31
            ->add('description', null, ['attr' => ['style' => 'height: 150px; width: 400px']])
32
            ->add('media', ModelListType::class, $options)
33
        ;
34
    }
35
}
36