Issues (16)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Email/Swift5.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Jaeger
4
 *
5
 * @copyright	Copyright (c) 2015-2016, mithra62
6
 * @link		http://jaeger-app.com
7
 * @version		1.0
8
 * @filesource 	./Email/Swift5.php
9
 */
10
namespace JaegerApp\Email;
11
12
use Swift_SmtpTransport;
13
use Swift_MailTransport;
14
use Swift_Message;
15
use Swift_Attachment;
16
use Swift_Mailer;
17
use Swift_Plugins_Loggers_ArrayLogger;
18
use Swift_Plugins_LoggerPlugin;
19
20
/**
21
 * Jaeger - Swift5 Email Abstraction
22
 *
23
 * Defines what email objects should contain
24
 *
25
 * @package Email
26
 * @author Eric Lamb <[email protected]>
27
 */
28
class Swift5 extends SwiftAbstract
29
{
30
    /**
31
     * Set it up
32
     * @param unknown $config
33
     */
34
    public function __construct($config = array())
35
    {
36
        $this->config = $config;
0 ignored issues
show
Documentation Bug introduced by
It seems like $config can also be of type object<JaegerApp\Email\unknown>. However, the property $config is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
37
        if( !class_exists('\Swift_Mailer') ) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
38
            //require_once dirname(__FILE__).'../../../vendor/swiftmailer/swiftmailer/lib/swift_required.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39
        }
40
    }
41
    
42
    /**
43
     * (non-PHPdoc)
44
     * @see \JaegerApp\Email\SwiftAbstract::getMailer()
45
     */
46
    public function getMailer()
47
    {
48
        if(is_null($this->mailer))
49
        {
50 View Code Duplication
            if (isset($this->config['type']) && $this->config['type'] == 'smtp') {
0 ignored issues
show
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...
51
                $transport = \Swift_SmtpTransport::newInstance($this->config['smtp_options']['host'], $this->config['smtp_options']['port']);
52
                $transport->setUsername($this->config['smtp_options']['connection_config']['username']);
53
                $transport->setPassword($this->config['smtp_options']['connection_config']['password']);
54
            } else {
55
                $transport = \Swift_MailTransport::newInstance();
56
            }
57
            
58
            $this->mailer = \Swift_Mailer::newInstance($transport);
59
            $this->mailer_logger = new \Swift_Plugins_Loggers_ArrayLogger();
0 ignored issues
show
The property mailer_logger does not seem to exist. Did you mean mailer?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
60
            $this->mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($this->mailer_logger));
0 ignored issues
show
The property mailer_logger does not seem to exist. Did you mean mailer?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
61
        }
62
        
63
        return $this->mailer;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->mailer; (Swift_Mailer) is incompatible with the return type declared by the abstract method JaegerApp\Email\SwiftAbstract::getMailer of type JaegerApp\Email\Swift_Mailer.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
64
    }
65
    
66
    /**
67
     * (non-PHPdoc)
68
     * @see \JaegerApp\Email\SwiftAbstract::getMessage()
69
     */
70
    public function getMessage(array $to, $from_email, $from_name, $subject, $message_body, array $attachments, $mail_type='html')
71
    {
72
        $message = \Swift_Message::newInstance();
73
        $message->setTo($to);
74
        if ($attachments) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $attachments of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
75
            foreach ($attachments as $attachment) {
76
                foreach ($attachment as $file => $alt_name) {
77
                    if ($alt_name == '') {
78
                        $message->attach(\Swift_Attachment::fromPath($file));
79
                    } else {
80
                        $message->attach(\Swift_Attachment::fromPath($file)->setFilename($alt_name));
81
                    }
82
                }
83
            }
84
        }
85
        
86
        $message->setFrom($from_email, $from_name);
87
        $message->setSubject($subject);
88
        if ($mail_type == 'html') {
89
            $message->setBody($message_body, 'text/html');
90
        } else {
91
            $message->setBody($message_body);
92
        }
93
        
94
        return $message;
95
    }
96
    
97
    public function send($message, $extra = null)
98
    {
99
        return $this->getMailer()->send($message);
100
    }
101
}