FormTrait   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 241
Duplicated Lines 9.96 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 6
Bugs 0 Features 1
Metric Value
wmc 14
c 6
b 0
f 1
lcom 1
cbo 1
dl 24
loc 241
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 10 1
B editAction() 8 30 3
B newAction() 8 26 2
B createNewEditForm() 0 28 2
A deleteConfirmAction() 0 17 2
B deleteAction() 8 24 3
A createDeleteForm() 0 15 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Xdaysaysay\AdminBundle\FormTrait;
4
5
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
6
use Symfony\Component\HttpFoundation\Request;
7
8
/**
9
 * Class FormTrait
10
 * @package Xdaysaysay\AdminBundle\FormTrait
11
 */
12
trait FormTrait
13
{
14
    private $entityClassName;
15
    private $repositoryName;
16
    private $twigFormDirectory;
17
    private $formRoute;
18
    private $translation;
19
    private $formType;
20
21
    /**
22
     * Displays list of existing entities.
23
     *
24
     * @return \Symfony\Component\HttpFoundation\Response
25
     *
26
     * @throws \LogicException
27
     * @throws \UnexpectedValueException
28
     */
29
    public function indexAction()
30
    {
31
        $entities = $this->getDoctrine()->getRepository($this->entityClassName)->findBy([], ['id' => 'DESC']);
1 ignored issue
show
Bug introduced by
It seems like getDoctrine() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
32
33
        return $this->render(
1 ignored issue
show
Bug introduced by
It seems like render() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
34
            $this->twigFormDirectory.':index.html.twig', [
35
                'entities' => $entities,
36
            ]
37
        );
38
    }
39
40
    /**
41
     * Displays a form to edit an existing entity.
42
     *
43
     * @param Request $request
44
     * @param int $id
45
     *
46
     * @return \Symfony\Component\HttpFoundation\Response
47
     *
48
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
49
     * @throws \LogicException
50
     * @throws \InvalidArgumentException
51
     * @throws \Symfony\Component\Form\Exception\AlreadySubmittedException
52
     * @throws \Symfony\Component\Form\Exception\LogicException
53
     * @throws \Symfony\Component\Form\Exception\UnexpectedTypeException
54
     */
55
    public function editAction(Request $request, $id)
56
    {
57
        $em = $this->getDoctrine()->getManager();
1 ignored issue
show
Bug introduced by
It seems like getDoctrine() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
58
59
        $entity = $em->getRepository($this->entityClassName)->find($id);
60
61
        if (!$entity) {
62
            throw $this->createNotFoundException('Unable to find entity.');
1 ignored issue
show
Bug introduced by
It seems like createNotFoundException() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
63
        }
64
65
        $form = $this->createNewEditForm($entity);
66
67
        $form->handleRequest($request);
68
69 View Code Duplication
        if ($form->isValid()) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
            $em->persist($entity);
71
            $em->flush();
72
73
            $this->addFlash('success', $this->get('translator')->trans('admin.'.$this->translation.'.flash.edit', [], 'admin'));
2 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like addFlash() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
74
75
            return $this->redirect($this->generateUrl('xdaysaysay_admin_'.$this->formRoute.'_edit', ['id' => $entity->getId()]));
2 ignored issues
show
Bug introduced by
It seems like generateUrl() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like redirect() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
76
        }
77
78
        return $this->render(
1 ignored issue
show
Bug introduced by
It seems like render() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
79
            $this->twigFormDirectory.':edit.html.twig', [
80
                'entity' => $entity,
81
                'form'   => $form->createView(),
82
            ]
83
        );
84
    }
85
86
    /**
87
     * Displays a form to edit an existing entity.
88
     *
89
     * @param Request $request
90
     *
91
     * @return \Symfony\Component\HttpFoundation\Response
92
     *
93
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
94
     * @throws \LogicException
95
     * @throws \InvalidArgumentException
96
     * @throws \Symfony\Component\Form\Exception\AlreadySubmittedException
97
     * @throws \Symfony\Component\Form\Exception\LogicException
98
     * @throws \Symfony\Component\Form\Exception\UnexpectedTypeException
99
     */
100
    public function newAction(Request $request)
101
    {
102
        $em = $this->getDoctrine()->getManager();
1 ignored issue
show
Bug introduced by
It seems like getDoctrine() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
103
104
        $entity = new $this->entityClassName;
105
106
        $form = $this->createNewEditForm($entity);
107
108
        $form->handleRequest($request);
109
110 View Code Duplication
        if ($form->isValid()) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
            $em->persist($entity);
112
            $em->flush();
113
114
            $this->addFlash('success', $this->get('translator')->trans('admin.'.$this->translation.'.flash.create', [], 'admin'));
2 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like addFlash() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
115
116
            return $this->redirect($this->generateUrl('xdaysaysay_admin_'.$this->formRoute.'_edit', ['id' => $entity->getId()]));
2 ignored issues
show
Bug introduced by
It seems like generateUrl() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like redirect() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
117
        }
118
119
        return $this->render(
1 ignored issue
show
Bug introduced by
It seems like render() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
120
            $this->twigFormDirectory.':new.html.twig', [
121
                'entity' => $entity,
122
                'form'   => $form->createView(),
123
            ]
124
        );
125
    }
126
127
    /**
128
     * Creates a form to create a entity.
129
     *
130
     * @param $entity
131
     *
132
     * @return \Symfony\Component\Form\Form The form
133
     *
134
     * @throws \InvalidArgumentException
135
     * @throws \Symfony\Component\Form\Exception\AlreadySubmittedException
136
     * @throws \Symfony\Component\Form\Exception\LogicException
137
     * @throws \Symfony\Component\Form\Exception\UnexpectedTypeException
138
     */
139
    private function createNewEditForm($entity)
140
    {
141
        $action = $this->generateUrl('xdaysaysay_admin_'.$this->formRoute.'_new');
1 ignored issue
show
Bug introduced by
It seems like generateUrl() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
142
        $submitText = $this->get('translator')->trans('admin.common.form.create', [], 'admin');
1 ignored issue
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
143
144
        if ($entity->getId() !== null) {
145
            $action = $this->generateUrl('xdaysaysay_admin_'.$this->formRoute.'_edit', ['id' => $entity->getId()]);
1 ignored issue
show
Bug introduced by
It seems like generateUrl() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
146
            $submitText = $this->get('translator')->trans('admin.common.form.update', [], 'admin');
1 ignored issue
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
147
        }
148
149
        $form = $this->createForm(
1 ignored issue
show
Bug introduced by
It seems like createForm() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
150
            $this->formType, $entity, [
151
                'action' => $action,
152
                'method' => 'PUT',
153
            ]
154
        );
155
156
        $form->add(
157
            'submit', SubmitType::class, [
158
                'label' => $submitText,
159
                'attr'  => [
160
                    'class' => 'btn btn-primary',
161
                ],
162
            ]
163
        );
164
165
        return $form;
166
    }
167
168
    /**
169
     * @param $id
170
     *
171
     * @return \Symfony\Component\HttpFoundation\Response
172
     *
173
     * @throws \LogicException
174
     * @throws \InvalidArgumentException
175
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
176
     */
177
    public function deleteConfirmAction($id)
178
    {
179
        $em = $this->getDoctrine()->getManager();
1 ignored issue
show
Bug introduced by
It seems like getDoctrine() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
180
181
        $entity = $em->getRepository($this->entityClassName)->find($id);
182
183
        if (!$entity) {
184
            throw $this->createNotFoundException('Unable to find entity.');
1 ignored issue
show
Bug introduced by
It seems like createNotFoundException() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
185
        }
186
187
        return $this->render(
1 ignored issue
show
Bug introduced by
It seems like render() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
188
            $this->twigFormDirectory.':confirm_delete.html.twig', [
189
                'entity' => $entity,
190
                'form'   => $this->createDeleteForm($entity)->createView(),
191
            ]
192
        );
193
    }
194
195
    /**
196
     * @param Request $request
197
     * @param $id
198
     *
199
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
200
     *
201
     * @throws \LogicException
202
     * @throws \InvalidArgumentException
203
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
204
     */
205
    public function deleteAction(Request $request, $id)
206
    {
207
        $em = $this->getDoctrine()->getManager();
1 ignored issue
show
Bug introduced by
It seems like getDoctrine() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
208
209
        $entity = $em->getRepository($this->entityClassName)->find($id);
210
211
        if (!$entity) {
212
            throw $this->createNotFoundException('Unable to find entity.');
1 ignored issue
show
Bug introduced by
It seems like createNotFoundException() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
213
        }
214
215
        $form = $this->createDeleteForm($entity);
216
217
        $form->handleRequest($request);
218 View Code Duplication
        if ($form->isValid()) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
219
            $em->remove($entity);
220
            $em->flush();
221
222
            $this->addFlash('success', $this->get('translator')->trans('admin.'.$this->translation.'.flash.delete', [], 'admin'));
2 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like addFlash() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
223
224
            return $this->redirectToRoute('xdaysaysay_admin_'.$this->formRoute.'_index');
1 ignored issue
show
Bug introduced by
It seems like redirectToRoute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
225
        }
226
227
        return $this->redirectToRoute('xdaysaysay_admin_'.$this->formRoute.'_delete_confirm', ['id' => $id]);
1 ignored issue
show
Bug introduced by
It seems like redirectToRoute() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
228
    }
229
230
    /**
231
     * @param $entity
232
     *
233
     * @return \Symfony\Component\Form\Form
234
     *
235
     * @throws \InvalidArgumentException
236
     */
237
    private function createDeleteForm($entity)
238
    {
239
        $form = $this->createFormBuilder()
1 ignored issue
show
Bug introduced by
It seems like createFormBuilder() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
240
            ->setAction($this->generateUrl('xdaysaysay_admin_'.$this->formRoute.'_delete', ['id' => $entity->getId()]))
1 ignored issue
show
Bug introduced by
It seems like generateUrl() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
241
            ->setMethod('DELETE')
242
            ->add('submit', SubmitType::class, [
243
                'label' => $this->get('translator')->trans('admin.common.action.delete', [], 'admin'),
1 ignored issue
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
244
                'attr'  => [
245
                    'class' => 'btn btn-danger',
246
                ],
247
            ])
248
            ->getForm();
249
250
        return $form;
251
    }
252
}