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.
Test Setup Failed
Push — email_fix ( a1c2be )
by
unknown
09:01
created

MailComponent   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 59
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrap() 0 13 2
A __construct() 0 22 3
A getMailFrom() 0 6 2
1
<?php
2
3
namespace app\modules\core\components;
4
5
use app\commands\SubmissionsController;
6
use app\modules\core\components\mail\SendMailHandler;
7
use yii\base\BootstrapInterface;
8
use yii\base\Event;
9
use yii\swiftmailer\Mailer;
10
11
class MailComponent extends Mailer implements BootstrapInterface
12
{
13
    private $componentConfig = [];
14
15
    /**
16
     * Bootstrap method to be called during application bootstrap stage.
17
     * @param Application $app the application currently running
18
     */
19
    public function bootstrap($app)
20
    {
21
        if ($app instanceof \yii\console\Application === true) {
0 ignored issues
show
Bug introduced by
The class yii\console\Application 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...
22
            Event::on(
23
                SubmissionsController::className(),
24
                SubmissionsController::EVENT_SEND_SUBMISSIONS,
25
                [
26
                    SendMailHandler::class,
27
                    'submissionsSendMail'
28
                ]
29
            );
30
        }
31
    }
32
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function __construct($config = [])
38
    {
39
        parent::__construct($config);
40
41
        $this->componentConfig = $mailConfig = \Yii::$app->getModule('core')->emailConfig;
42
43
        $_config = [
44
            'class' => $mailConfig['transport'],
45
        ];
46
47
        if ('Swift_SmtpTransport' === $mailConfig['transport']) {
48
            $_config['host'] = $mailConfig['host'];
49
            $_config['username'] = $mailConfig['username'];
50
            $_config['password'] = $mailConfig['password'];
51
            $_config['port'] = $mailConfig['port'];
52
            $_config['encryption'] = $mailConfig['encryption'];
53
        } elseif ('Swift_SendmailTransport' === $mailConfig['transport']) {
54
            $_config['command'] = $mailConfig['sendMail'];
55
        }
56
57
        $this->setTransport($_config);
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getMailFrom()
64
    {
65
        return !empty($this->componentConfig['mailFrom'])
66
            ? $this->componentConfig['mailFrom']
67
            : '';
68
    }
69
}