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/Slack/Notifier.php (10 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\Slack;
7
8
use Jeancsil\FlightSpy\Api\DataTransfer\SessionParameters;
9
use Jeancsil\FlightSpy\Service\ElasticSearch\ElasticSearchWriterTrait;
10
use Jeancsil\FlightSpy\Service\ElasticSearch\ElasticSearchRequester;
11
use Jeancsil\FlightSpy\Notifier\Deal;
12
use Jeancsil\FlightSpy\Notifier\NotifiableInterface;
13
use Maknz\Slack\Client;
14
15
class Notifier implements NotifiableInterface
16
{
17
    use ElasticSearchWriterTrait;
18
19
    /**
20
     * @var ElasticSearchRequester
21
     */
22
    private $elasticSearchRequester;
23
    /**
24
     * @var Client
25
     */
26
    private $slackClient;
27
    /**
28
     * @var string
29
     */
30
    private $slackUserName;
31
32
    public function __construct(Client $slackClient, $slackUserName)
33
    {
34
        $this->slackClient = $slackClient;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 3 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...
35
        $this->slackUserName = $slackUserName;
36
    }
37
38
    /** @inheritdoc */
39
    public function notify(array $deals, SessionParameters $sessionParameters)
40
    {
41
        $notifications = $this->createNotifications($sessionParameters, $deals);
42
43
        /**
44
         * @var string $identifier
45
         * @var SlackNotification $notification
46
         */
47
        foreach ($notifications as $identifier => $notification) {
48
            $this->slackClient
49
                ->createMessage()
50
                ->send($notification->message);
0 ignored issues
show
Accessing message on the interface Jeancsil\FlightSpy\Notifier\Notification suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
51
52
            $this->elasticSearchWriter
53
                ->writeOne([
54
                    'identifier' => $identifier,
55
                    'notified' => $notification->to
0 ignored issues
show
Accessing to on the interface Jeancsil\FlightSpy\Notifier\Notification suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
56
                ]);
57
        }
58
    }
59
60
    /** @inheritdoc */
61
    public function wasNotified(Deal $deal, $notifyTo)
62
    {
63
        return $this->elasticSearchRequester
64
            ->wasNotified(
65
                $deal->getIdentifier(),
66
                $notifyTo
67
            );
68
    }
69
70
    /** @inheritdoc */
71
    public function createNotifications(SessionParameters $parameters, array $deals = [])
72
    {
73
        $notifications = [];
74
        /** @var Deal $deal */
75
        foreach ($deals as $deal) {
76
            $to = "@{$this->slackUserName}";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
77
78
            if ($this->wasNotified($deal, $to)) {
79
                continue;
80
            }
81
82
            $notification = new SlackNotification();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 5 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...
83
            $notification->to = $to;
84
            $message = $deal->getAgentName() . ' ';
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 10 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...
85
            $message.= $parameters->currency . ' *' . number_format($deal->getPrice()) . '* ';
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 0 spaces

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...
86
87
            if ($deal->getDeepLinkUrl()) {
88
                $message .=  PHP_EOL . "<{$deal->getDeepLinkUrl()}|Deep Link>";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $deal instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
89
            }
90
91
            $notification->message = $message;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 17 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...
92
            $notifications[$deal->getIdentifier()] = $notification;
93
        }
94
95
        return $notifications;
96
    }
97
98
    /**
99
     * @param ElasticSearchRequester $elasticSearchRequester
100
     */
101
    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...
102
    {
103
        $this->elasticSearchRequester = $elasticSearchRequester;
104
    }
105
}
106