Failed Conditions
Pull Request — master (#319)
by Guilherme
08:18
created

SupportHandler   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 68
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getInitialMessage() 0 6 1
A __construct() 0 8 1
A getSupportPerson() 0 8 2
A getValidationMap() 0 7 1
A personalDataToValidationArray() 0 13 4
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\SupportBundle\Service;
12
13
use LoginCidadao\CoreBundle\Entity\PersonRepository;
14
use LoginCidadao\CoreBundle\Entity\SentEmail;
15
use LoginCidadao\CoreBundle\Entity\SentEmailRepository;
16
use LoginCidadao\CoreBundle\Model\PersonInterface;
17
use LoginCidadao\SupportBundle\Exception\PersonNotFoundException;
18
use LoginCidadao\SupportBundle\Model\PersonalData;
19
use LoginCidadao\SupportBundle\Model\SupportPerson;
20
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
21
22
class SupportHandler
23
{
24
    /** @var AuthorizationCheckerInterface */
25
    private $authChecker;
26
27
    /** @var PersonRepository */
28
    private $personRepository;
29
30
    /** @var SentEmailRepository */
31
    private $sentEmailRepository;
32
33
    /**
34
     * SupportHandler constructor.
35
     * @param AuthorizationCheckerInterface $authChecker
36
     * @param PersonRepository $personRepository
37
     * @param SentEmailRepository $sentEmailRepository
38
     */
39 4
    public function __construct(
40
        AuthorizationCheckerInterface $authChecker,
41
        PersonRepository $personRepository,
42
        SentEmailRepository $sentEmailRepository
43
    ) {
44 4
        $this->authChecker = $authChecker;
45 4
        $this->personRepository = $personRepository;
46 4
        $this->sentEmailRepository = $sentEmailRepository;
47 4
    }
48
49 2
    public function getSupportPerson($id): SupportPerson
50
    {
51 2
        $person = $this->personRepository->find($id);
52 2
        if (!$person instanceof PersonInterface) {
53 1
            throw new PersonNotFoundException();
54
        }
55
56 1
        return new SupportPerson($person, $this->authChecker);
57
    }
58
59 1
    public function getInitialMessage($id): ?SentEmail
60
    {
61
        /** @var SentEmail $sentEmail */
62 1
        $sentEmail = $this->sentEmailRepository->find($id);
63
64 1
        return $sentEmail;
65
    }
66
67 1
    public function getValidationMap(SupportPerson $person): array
68
    {
69 1
        return array_filter([
70 1
            'cpf' => $this->personalDataToValidationArray($person->getCpf(), true),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->personalDataToVal...person->getCpf(), true) targeting LoginCidadao\SupportBund...DataToValidationArray() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
71 1
            'birthday' => $this->personalDataToValidationArray($person->getBirthday(), true),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->personalDataToVal...n->getBirthday(), true) targeting LoginCidadao\SupportBund...DataToValidationArray() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
72 1
            'email' => $this->personalDataToValidationArray($person->getEmail(), true),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->personalDataToVal...rson->getEmail(), true) targeting LoginCidadao\SupportBund...DataToValidationArray() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
73 1
            'phoneNumber' => $this->personalDataToValidationArray($person->getPhoneNumber(), true),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->personalDataToVal...getPhoneNumber(), true) targeting LoginCidadao\SupportBund...DataToValidationArray() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
74
        ]);
75
    }
76
77 1
    private function personalDataToValidationArray(PersonalData $data, bool $skipIfValueSet = false): ?array
78
    {
79 1
        if (false === $data->isValueFilled()) {
80 1
            return null;
81
        }
82 1
        if ($skipIfValueSet && $data->getValue() !== null) {
83 1
            return null;
84
        }
85
86
        return [
87 1
            'name' => $data->getName(),
88 1
            'hash' => $data->getHash(),
89 1
            'challenge' => $data->getChallenge(),
90
        ];
91
    }
92
}
93