GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b5dfb6...a568a9 )
by Mario
40:05
created

AutoResponderDataFactory::resolveSubject()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 32

Duplication

Lines 15
Ratio 46.88 %

Importance

Changes 0
Metric Value
dl 15
loc 32
rs 9.0968
c 0
b 0
f 0
cc 5
nc 4
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\InformationCollection\Core\Factory;
6
7
use function array_key_exists;
8
use Netgen\InformationCollection\API\Value\Event\InformationCollected;
9
use Netgen\InformationCollection\API\Exception\MissingValueException;
10
use Netgen\InformationCollection\API\Value\DataTransfer\EmailContent;
11
use Netgen\InformationCollection\API\Value\DataTransfer\TemplateContent;
12
use Netgen\InformationCollection\API\Constants;
13
use function trim;
14
15
class AutoResponderDataFactory extends EmailDataFactory
16
{
17
    /**
18
     * Factory method.
19
     *
20
     * @param InformationCollected $value
21
     *
22
     * @return EmailData
23
     */
24
    public function build(InformationCollected $value)
25
    {
26
        $location = $value->getLocation();
27
        $contentType = $value->getContentType();
28
        $content = $this->contentService->loadContent($location->contentId);
29
30
        $template = $this->resolveTemplate($contentType->identifier);
31
32
        $templateWrapper = $this->twig->load($template);
33
        $data = new TemplateData($value, $content, $templateWrapper);
34
35
        $body = $this->resolveBody($data);
36
37
        return new EmailData(
38
            $this->resolveRecipient($data),
39
            $this->resolve($data, Constants::FIELD_SENDER, Constants::FIELD_TYPE_EMAIL),
40
            $this->resolveSubject($data),
41
            $body
42
        );
43
    }
44
45
    /**
46
     * Returns resolved parameter.
47
     *
48
     * @param TemplateData $data
49
     *
50
     * @return string
51
     */
52
    protected function resolveRecipient(TemplateData $data)
53
    {
54
        $fields = $data->getEvent()->getInformationCollectionStruct()->getCollectedFields();
55 View Code Duplication
        if ($data->getTemplateWrapper()->hasBlock(Constants::FIELD_RECIPIENT)) {
0 ignored issues
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...
56
            $rendered = $data->getTemplateWrapper()->renderBlock(
57
                Constants::FIELD_RECIPIENT,
58
                [
59
                    'event' => $data->getEvent(),
60
                    'collected_fields' => $fields,
61
                    'content' => $data->getContent(),
62
                ]
63
            );
64
65
            return trim($rendered);
66
        }
67
68
        $field = 'email';
69 View Code Duplication
        if (!empty($this->config[ConfigurationConstants::DEFAULT_VARIABLES][ConfigurationConstants::EMAIL_FIELD_IDENTIFIER])) {
0 ignored issues
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
            $field = $this->config[ConfigurationConstants::DEFAULT_VARIABLES][ConfigurationConstants::EMAIL_FIELD_IDENTIFIER];
71
        }
72
73
        if (array_key_exists($field, $fields)) {
74
            return $fields[$field]->email;
75
        }
76
77
        throw new MissingValueException($field);
78
    }
79
80
    /**
81
     * Returns resolved parameter.
82
     *
83
     * @param TemplateData $data
84
     *
85
     * @return string
86
     */
87
    protected function resolveSubject(TemplateData $data)
88
    {
89
        $fields = $data->getEvent()->getInformationCollectionStruct()->getCollectedFields();
90 View Code Duplication
        if ($data->getTemplateWrapper()->hasBlock(Constants::FIELD_AUTO_RESPONDER_SUBJECT)) {
0 ignored issues
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...
91
            $rendered = $data->getTemplateWrapper()->renderBlock(
92
                Constants::FIELD_AUTO_RESPONDER_SUBJECT,
93
                [
94
                    'event' => $data->getEvent(),
95
                    'collected_fields' => $fields,
96
                    'content' => $data->getContent(),
97
                ]
98
            );
99
100
            return trim($rendered);
101
        }
102
103
        $content = $data->getContent();
104
        if (array_key_exists(Constants::FIELD_AUTO_RESPONDER_SUBJECT, $content->fields) &&
105
            !$this->fieldHelper->isFieldEmpty($content, Constants::FIELD_AUTO_RESPONDER_SUBJECT)
106
        ) {
107
            $fieldValue = $this->translationHelper->getTranslatedField($content, Constants::FIELD_AUTO_RESPONDER_SUBJECT);
108
109
            return $fieldValue->value->text;
110
        }
111
112 View Code Duplication
        if (!empty($this->config[ConfigurationConstants::DEFAULT_VARIABLES][ConfigurationConstants::EMAIL_SUBJECT])) {
0 ignored issues
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...
113
            return $this->config[ConfigurationConstants::DEFAULT_VARIABLES][ConfigurationConstants::EMAIL_SUBJECT];
114
        }
115
116
        $message = Constants::FIELD_AUTO_RESPONDER_SUBJECT . '|' . ConfigurationConstants::EMAIL_SUBJECT;
117
        throw new MissingValueException($message);
118
    }
119
}
120