Completed
Push — master ( 45292f...31ad2c )
by PastisD
02:24
created

FormTrait::editAction()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 30
Code Lines 16

Duplication

Lines 8
Ratio 26.67 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 30
rs 8.8571
cc 3
eloc 16
nc 3
nop 2
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
trait FormTrait
9
{
10
    /**
11
     * Displays list of existing entities.
12
     *
13
     * @return \Symfony\Component\HttpFoundation\Response
14
     *
15
     * @throws \LogicException
16
     * @throws \UnexpectedValueException
17
     */
18
    public function indexAction()
19
    {
20
        $this->get('avanzu_admin_theme.theme_manager')->registerScript('datatble', 'bundles/xdaysaysayadmin/js/datatable.js');
0 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...
21
22
        $entities = $this->getDoctrine()->getRepository($this->entityClassName)->findBy([], ['id' => 'DESC']);
1 ignored issue
show
Bug introduced by
The property entityClassName does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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...
23
24
        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...
25
            $this->twigFormDirectory . ':index.html.twig', [
0 ignored issues
show
Bug introduced by
The property twigFormDirectory does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26
                'entities' => $entities,
27
            ]
28
        );
29
    }
30
31
32
    /**
33
     * Displays a form to edit an existing entity.
34
     *
35
     * @param Request $request
36
     * @param int $id
37
     *
38
     * @return \Symfony\Component\HttpFoundation\Response
39
     *
40
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
41
     * @throws \LogicException
42
     * @throws \InvalidArgumentException
43
     * @throws \Symfony\Component\Form\Exception\AlreadySubmittedException
44
     * @throws \Symfony\Component\Form\Exception\LogicException
45
     * @throws \Symfony\Component\Form\Exception\UnexpectedTypeException
46
     */
47
    public function editAction(Request $request, $id)
48
    {
49
        $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...
50
51
        $entity = $em->getRepository($this->entityClassName)->find($id);
52
53
        if (!$entity) {
54
            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...
55
        }
56
57
        $form = $this->createNewEditForm($entity);
58
59
        $form->handleRequest($request);
60
61 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...
62
            $em->persist($entity);
63
            $em->flush();
64
65
            $this->addFlash('success', $this->get('translator')->trans('admin.' . $this->translation . '.flash.edit', [], 'admin'));
2 ignored issues
show
Bug introduced by
The property translation does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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...
66
67
            return $this->redirect($this->generateUrl('xdaysaysay_admin_' . $this->formRoute . '_edit', ['id' => $entity->getId()]));
2 ignored issues
show
Bug introduced by
The property formRoute does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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...
68
        }
69
70
        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...
71
            $this->twigFormDirectory . ':edit.html.twig', [
72
                'entity' => $entity,
73
                'form'   => $form->createView(),
74
            ]
75
        );
76
    }
77
78
79
    /**
80
     * Displays a form to edit an existing entity.
81
     *
82
     * @param Request $request
83
     *
84
     * @return \Symfony\Component\HttpFoundation\Response
85
     *
86
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
87
     * @throws \LogicException
88
     * @throws \InvalidArgumentException
89
     * @throws \Symfony\Component\Form\Exception\AlreadySubmittedException
90
     * @throws \Symfony\Component\Form\Exception\LogicException
91
     * @throws \Symfony\Component\Form\Exception\UnexpectedTypeException
92
     */
93
    public function newAction(Request $request)
94
    {
95
        $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...
96
97
        $entity = new $this->entityClassName;
98
99
        $form = $this->createNewEditForm($entity);
100
101
        $form->handleRequest($request);
102
103 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...
104
            $em->persist($entity);
105
            $em->flush();
106
107
            $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...
108
109
            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...
110
        }
111
112
        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...
113
            $this->twigFormDirectory . ':new.html.twig', [
114
                'entity' => $entity,
115
                'form'   => $form->createView(),
116
            ]
117
        );
118
    }
119
120
121
    /**
122
     * Creates a form to create a entity.
123
     *
124
     * @param $entity
125
     *
126
     * @return \Symfony\Component\Form\Form The form
127
     *
128
     * @throws \InvalidArgumentException
129
     * @throws \Symfony\Component\Form\Exception\AlreadySubmittedException
130
     * @throws \Symfony\Component\Form\Exception\LogicException
131
     * @throws \Symfony\Component\Form\Exception\UnexpectedTypeException
132
     */
133
    private function createNewEditForm($entity)
134
    {
135
        if ($entity->getId() !== null) {
136
            $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...
137
            $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...
138
        } else {
139
            $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...
140
            $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...
141
        }
142
143
        $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...
144
            $this->formType, $entity, [
0 ignored issues
show
Bug introduced by
The property formType does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
145
                'action' => $action,
146
                'method' => 'PUT',
147
            ]
148
        );
149
150
        $form->add(
151
            'submit', SubmitType::class, [
152
                'label' => $submitText,
153
                'attr'  => [
154
                    'class' => 'btn btn-primary',
155
                ],
156
            ]
157
        );
158
159
        return $form;
160
    }
161
162
163
    /**
164
     * @param $id
165
     *
166
     * @return \Symfony\Component\HttpFoundation\Response
167
     */
168
    public function deleteConfirmAction($id)
169
    {
170
        $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...
171
172
        $entity = $em->getRepository($this->entityClassName)->find($id);
173
174
        if (!$entity) {
175
            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...
176
        }
177
178
        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...
179
            $this->twigFormDirectory . ':confirm_delete.html.twig', [
180
                'entity' => $entity,
181
                'form'   => $this->createDeleteForm($entity)->createView(),
182
            ]
183
        );
184
    }
185
186
187
    /**
188
     * @param Request $request
189
     * @param $id
190
     *
191
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
192
     *
193
     * @throws \LogicException
194
     * @throws \InvalidArgumentException
195
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
196
     */
197
    public function deleteAction(Request $request, $id)
198
    {
199
        $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...
200
201
        $entity = $em->getRepository($this->entityClassName)->find($id);
202
203
        if (!$entity) {
204
            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...
205
        }
206
207
        $form = $this->createDeleteForm($entity);
208
209
        $form->handleRequest($request);
210
        if ($form->isValid()) {
211
            $em->remove($entity);
212
            $em->flush();
213
214
            $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...
215
216
            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...
217
        } else {
218
            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...
219
        }
220
    }
221
222
    /**
223
     * @param $entity
224
     *
225
     * @return \Symfony\Component\Form\Form
226
     *
227
     * @throws \InvalidArgumentException
228
     */
229
    private function createDeleteForm($entity)
230
    {
231
        $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...
232
            ->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...
233
            ->setMethod('DELETE')
234
            ->add('submit', SubmitType::class, [
235
                '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...
236
                'attr'  => [
237
                    'class' => 'btn btn-danger',
238
                ],
239
            ])
240
            ->getForm();
241
242
        return $form;
243
    }
244
}