MessageForm::getUser()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 12
rs 10
1
<?php
2
3
namespace PiedWeb\ConversationBundle\Form;
4
5
use Symfony\Component\Form\Extension\Core\Type\EmailType;
6
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
7
use Symfony\Component\Form\FormBuilderInterface;
8
9
class MessageForm
10
{
11
    use FormTrait;
0 ignored issues
show
Bug introduced by
The trait PiedWeb\ConversationBundle\Form\FormTrait requires the property $query which is not provided by PiedWeb\ConversationBundle\Form\MessageForm.
Loading history...
12
13
    protected function getStepOne(): FormBuilderInterface
14
    {
15
        /*
16
        if ($this->getUser()) {
17
            $this->message->setAuthorEmail($this->getUser()->getEmail());
18
            $this->message->setAuthorName($this->getUser()->getUsername());
19
            $user = true;
20
        }/**/
21
22
        $form = $this->initForm();
23
24
        if (!isset($user) || !$this->getUser()) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $user seems to never exist and therefore isset should always be false.
Loading history...
25
            $form->add('authorEmail', EmailType::class, ['constraints' => $this->getAuthorEmailConstraints()]);
26
            $form->add('authorName', null, ['constraints' => $this->getAuthorNameConstraints()]);
27
        }
28
29
        $form->add('content', TextareaType::class);
30
31
        return $form;
32
    }
33
34
    protected function getUser()
35
    {
36
        if (null === $token = $this->security->getToken()) {
37
            return null;
38
        }
39
40
        if (!\is_object($user = $token->getUser())) {
41
            // e.g. anonymous authentication
42
            return null;
43
        }
44
45
        return $user;
46
    }
47
}
48