Issues (149)

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/Notifier/Email/Notifier.php (4 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
 * @author Jean Silva <[email protected]>
4
 * @license MIT
5
 */
6
namespace Jeancsil\FlightSpy\Notifier\Email;
7
8
use Jeancsil\FlightSpy\Api\DataTransfer\SessionParameters;
9
use Jeancsil\FlightSpy\Service\Currency\PriceFormatter;
10
use Jeancsil\FlightSpy\Service\ElasticSearch\ElasticSearchWriterTrait;
11
use Jeancsil\FlightSpy\Service\ElasticSearch\ElasticSearchRequester;
12
use Jeancsil\FlightSpy\Notifier\Deal;
13
use Jeancsil\FlightSpy\Notifier\NotifiableInterface;
14
use Postmark\PostmarkClient;
15
16
class Notifier implements NotifiableInterface
17
{
18
    use ElasticSearchWriterTrait;
19
20
    /**
21
     * @var ElasticSearchRequester
22
     */
23
    private $elasticSearchRequester;
24
    /**
25
     * @var PriceFormatter
26
     */
27
    private $priceFormatter;
28
    /**
29
     * @var PostmarkClient
30
     */
31
    private $mailer;
32
    private $html;
33
    private $from;
34
    private $to;
35
    private $subject;
36
37
    private $tableLines = [];
38
39
    public function __construct(PostmarkClient $mailer, $html, $from, $to, $subject)
40
    {
41
        $this->mailer = $mailer;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
42
        $this->from = $from;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
43
        $this->to = $to;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
44
        $this->subject = $subject;
45
46
        $this->initializeHtmlTemplate($html);
47
    }
48
49
    /** @inheritdoc */
50
    public function notify(array $deals, SessionParameters $sessionParameters)
51
    {
52
        $notifications = $this->createNotifications($sessionParameters, $deals);
53
54
        if (empty($this->tableLines)) {
55
            return;
56
        }
57
58
        /**
59
         * @var string $identifier
60
         * @var EmailNotification $notification
61
         */
62
        foreach ($notifications as $identifier => $notification) {
63
            $this->elasticSearchWriter
64
                ->writeOne([
65
                    'identifier' => $identifier,
66
                    'notified' => $this->to
67
                ]);
68
        }
69
70
        $this->mailer->sendEmail(
71
            $this->from,
72
            $this->to,
73
            $this->subject,
74
            str_replace('<!--NewLine-->', implode('', $this->tableLines), $this->html)
75
        );
76
    }
77
78
    /** @inheritdoc */
79
    public function wasNotified(Deal $deal, $notifyTo)
80
    {
81
        return $this->elasticSearchRequester
82
            ->wasNotified(
83
                $deal->getIdentifier(),
84
                $notifyTo
85
            );
86
    }
87
88
89
    /** @inheritdoc */
90
    public function createNotifications(SessionParameters $parameters, array $deals = [])
91
    {
92
        $notifications = [];
93
        /** @var Deal $deal */
94
        foreach ($deals as $deal) {
95
            if ($this->wasNotified($deal, $this->to)) {
96
                continue;
97
            }
98
99
            $this->tableLines[] = $this->createTableLine(
100
                $deal->getAgentName(),
101
                $this->priceFormatter->format($deal->getPrice(), $parameters->currency),
102
                $deal->getDeepLinkUrl()
103
            );
104
105
            $notifications[$deal->getIdentifier()] = new EmailNotification();
106
        }
107
108
        return $notifications;
109
    }
110
111
    /**
112
     * @param ElasticSearchRequester $elasticSearchRequester
113
     */
114
    public function setElasticSearchRequester(ElasticSearchRequester $elasticSearchRequester)
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $elasticSearchRequester exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
115
    {
116
        $this->elasticSearchRequester = $elasticSearchRequester;
117
    }
118
119
    /**
120
     * @param PriceFormatter $priceFormatter
121
     */
122
    public function setPriceFormatter(PriceFormatter $priceFormatter)
123
    {
124
        $this->priceFormatter = $priceFormatter;
125
    }
126
127
    /**
128
     * @param $htmlTemplate
129
     */
130
    private function initializeHtmlTemplate($htmlTemplate)
131
    {
132
        $this->html = file_get_contents($htmlTemplate);
133
    }
134
135
    /**
136
     * @param $agentName
137
     * @param $price
138
     * @param $deepLink
139
     * @return string
140
     */
141
    private function createTableLine($agentName, $price, $deepLink)
142
    {
143
        $deepLinkHtml = '';
144
145
        if ($deepLink) {
146
            $deepLinkHtml = '<a href="' . $deepLink . '" 
147
               target="_blank" 
148
               style="text-decoration:underline;background-color:#ffffff;
149
                border:solid 1px #3498db;border-radius:5px;
150
                box-sizing:border-box;color:#3498db;
151
                cursor:pointer;font-size:12px;
152
                margin:0;padding:3px 3px;
153
                text-decoration:none;text-transform:capitalize;
154
                background-color:#3498db;border-color:#3498db;color:#ffffff;">Book</a>';
155
        }
156
157
        return sprintf(
158
            '<tr>
159
                <td style="font-family:sans-serif;font-size:14px;vertical-align:top;padding-bottom:15px;">%s</td>
160
                <td style="font-family:sans-serif;font-size:14px;vertical-align:top;padding-bottom:15px;">%s</td>
161
                <td style="font-family:sans-serif;font-size:14px;vertical-align:top;padding-bottom:15px;">%s</td>
162
            </tr>',
163
            $agentName,
164
            $price,
165
            $deepLinkHtml
166
        );
167
    }
168
}
169