Completed
Push — pac-89--debug-report ( aa1038 )
by Marcus
02:19
created

DebugSendPlugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 49
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 40 4
1
<?php
2
3
/**
4
 * TechDivision\Import\Plugins\DebugSendPlugin
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 7
13
 *
14
 * @author    Marcus Döllerer <[email protected]>
15
 * @copyright 2020 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Plugins;
22
23
use Symfony\Component\Console\Question\ConfirmationQuestion;
24
use Symfony\Component\Console\Question\Question;
25
use TechDivision\Import\Configuration\Jms\Configuration\SwiftMailer;
26
27
/**
28
 * Plugin that creates and sends a debug report via email.
29
 *
30
 * @author    Marcus Döllerer <[email protected]>
31
 * @copyright 2020 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/techdivision/import
34
 * @link      http://www.techdivision.com
35
 */
36
class DebugSendPlugin extends AbstractConsolePlugin
37
{
38
39
    /**
40
     * Process the plugin functionality.
41
     *
42
     * @return void
43
     */
44
    public function process()
45
    {
46
47
        // retrieve the SwiftMailer configuration
48
        $swiftMailerConfiguration = $this->getPluginConfiguration()->getSwiftMailer();
0 ignored issues
show
Bug introduced by
The method getSwiftMailer() does not seem to exist on object<TechDivision\Impo...ConfigurationInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
50
        // retrieve the question helper
51
        $questionHelper = $this->getHelper('question');
52
53
        // use the configured SwiftMail recipient address as default if possible
54
        if ($swiftMailerConfiguration instanceof SwiftMailer && $swiftMailerConfiguration->hasParam('to')) {
0 ignored issues
show
Bug introduced by
The class TechDivision\Import\Conf...nfiguration\SwiftMailer does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
55
            $recipient = $swiftMailerConfiguration->getParam('to');
56
            // ask the user for the recipient address to send the debug report to
57
            $recipientQuestion = new Question(
58
                "<question>Please enter the email address of the debug report recipient (Configured: " . $recipient . "):\n</question>",
59
                $recipient
60
            );
61
        } else {
62
            $recipientQuestion = new Question(
63
                "<question>Please enter the email address of the debug report recipient:\n</question>"
64
            );
65
        }
66
67
        // ask the user to confirm the configured recipient address or enter a new one
68
        $recipient = $questionHelper->ask($this->getInput(), $this->getOutput(), $recipientQuestion);
69
70
        // warn the user about the impact of submitting their report and ask for confirmation
71
        $confirmationQuestion = new ConfirmationQuestion(
72
            "<comment>The debug report may contain confidential information (depending on the data you were importing).\n</comment>"
73
            . "<question>Do you really want to send the report to " . $recipient . "? (Y/n)\n</question>"
74
        );
75
76
        // abort the operation if the user does not confirm with 'y' or enter
77
        if (!$questionHelper->ask($this->getInput(), $this->getOutput(), $confirmationQuestion)) {
78
            $this->getOutput()->writeln('<info>Aborting operation - debug report has NOT been sent.</info>');
79
            return;
80
        }
81
82
        $this->getOutput()->writeln('<info>The debug report has successfully been submitted to ' . $recipient . '</info>');
83
    }
84
}
85