Completed
Pull Request — master (#153)
by Deven
02:39
created

MailerComponent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 36.84%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 38
ccs 7
cts 19
cp 0.3684
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B sendReportMail() 0 28 5
1
<?php
2
/* vim: set expandtab sw=4 ts=4 sts=4: */
3
4
/**
5
 * Mailer component handling sending of report notification mails
6
 *
7
 * phpMyAdmin Error reporting server
8
 * Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
9
 *
10
 * Licensed under The MIT License
11
 * For full copyright and license information, please see the LICENSE.txt
12
 * Redistributions of files must retain the above copyright notice.
13
 *
14
 * @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
15
 * @license   https://opensource.org/licenses/mit-license.php MIT License
16
 *
17
 * @see      https://www.phpmyadmin.net/
18
 */
19
20
namespace App\Controller\Component;
21
22
use Cake\Controller\Component;
23
use Cake\ORM\TableRegistry;
24
use Cake\Mailer\Email;
25
use Cake\Core\Configure;
26
27
/**
28
 * Mailer component handling report notification emails.
29
 */
30
class MailerComponent extends Component
31
{
32
    /**
33
     * Send an email about the report to configured Email
34
     *
35
     * @param $viewVars Array of View Variables
36
     *
37
     * @return boolean if Email was sent
38
     */
39 1
    public function sendReportMail($viewVars)
40
    {
41 1
        $email = new Email();
42 1
        $emailTo = Configure::read('NotificationEmailsTo');
43 1
        $emailFrom = Configure::read('NotificationEmailsFrom');
44
45 1
        if (! $emailTo || $emailTo === ''
46 1
            || ! $emailFrom || $emailFrom === ''
47
        ) {
48 1
            return false;
49
        }
50
51
        $email->transport('default')
0 ignored issues
show
Bug introduced by
The method viewVars does only exist in Cake\Mailer\Email, but not in Cake\Mailer\AbstractTransport.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
Deprecated Code introduced by
The method Cake\Mailer\Email::transport() has been deprecated with message: 3.4.0 Use setTransport()/getTransport() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
52
            ->viewVars($viewVars)
53
            ->subject(
54
                sprintf(
55
                    'A new report has been submitted on the Error Reporting Server: %s',
56
                    $viewVars['report']['id']
57
                )
58
            )
59
            ->template('report', 'default')
60
            ->emailFormat('html')
61
            ->to($emailTo)
62
            ->from($emailFrom)
63
            ->send();
64
65
        return true;
66
    }
67
}
68