Completed
Push — master ( 884aac...3cb94c )
by Patrick
05:58
created

aws.php ➔ getRawMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 7
rs 9.4285
1
<?php
2
require '/var/www/common/libs/aws/aws-autoloader.php';
3
use Aws\Sns\MessageValidator\Message;
4
use Aws\Sns\MessageValidator\MessageValidator;
5
use Aws\S3\S3Client;
6
use Guzzle\Http\Client;
7
8
function aws()
9
{
10
    global $app;
11
    $app->post('/snsEndpoint', 'snsEndpoint');
12
    $app->post('/test', 'testX');
13
}
14
15
function sendToBackend($function, $payload)
16
{
17
    $context = new ZMQContext();
18
    $queue = new ZMQSocket($context, ZMQ::SOCKET_REQ);
19
20
    $queue->connect('tcp://127.0.0.1:55555');
21
    $message = base64_encode(serialize($payload));
22
    $queue->send($function.':', ZMQ::MODE_SNDMORE);
23
    $queue->send($message);
24
    return $queue->recv();
25
}
26
27
function testX()
0 ignored issues
show
Best Practice introduced by
The function testX() has been defined more than once; this definition is ignored, only the first definition in _local/run.php (L39-44) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
28
{
29
    global $app;
30
    $array = $app->getJSONBody(true);
31
32
    echo sendToBackend('testX', $array);
33
    die();
34
}
35
36
function snsEndpoint()
37
{
38
    global $app;
39
    $array = $app->getJSONBody(true);
40
41
    try
42
    {
43
        $message = Message::fromArray($array);
44
45
        // Validate the message
46
        $validator = new MessageValidator();
47
        $validator->validate($message);
48
    }
49
    catch(\Exception $e)
50
    {
51
        $app->notFound();
52
    }
53
54
    $type = $message->get('Type');
55
    switch($type)
56
    {
57
        case 'SubscriptionConfirmation':
58
            (new Client)->get($message->get('SubscribeURL'))->send();
59
            break;
60
        case 'Notification':
61
            $arn = $message->get('TopicArn');
62
            if($arn !== false)
63
            {
64
                $pos = strpos($arn, 'Listserv');
65
                if($pos !== false)
66
                {
67
                    sendToBackend('processListServMessage', $message->get('Message'));
68
                    echo 'true';
69
                    return;
70
                }
71
            }
72
        default:
73
            file_put_contents('/var/www/profiles/tmp/log.log', print_r($message, true), FILE_APPEND);
74
            break;
75
    }
76
}
77
78 View Code Duplication
function endswith($string, $test)
0 ignored issues
show
Best Practice introduced by
The function endswith() has been defined more than once; this definition is ignored, only the first definition in _local/run.php (L46-52) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
Duplication introduced by
This function seems to be duplicated in 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...
79
{
80
    $strlen = strlen($string);
81
    $testlen = strlen($test);
82
    if($testlen > $strlen)
83
    {
84
        return false;
85
    }
86
    return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0;
87
}
88
89 View Code Duplication
function getDestinationsForID($id)
0 ignored issues
show
Best Practice introduced by
The function getDestinationsForID() has been defined more than once; this definition is ignored, only the first definition in _local/run.php (L54-64) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
Duplication introduced by
This function seems to be duplicated in 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...
90
{
91
    if(strcasecmp($id, 'pboyd') === 0)
92
    {
93
        return array('[email protected]');
94
    }
95
    else
96
    {
97
        return false;
98
    }
99
}
100
101 View Code Duplication
function getActualDestinations($originals)
0 ignored issues
show
Best Practice introduced by
The function getActualDestinations() has been defined more than once; this definition is ignored, only the first definition in _local/run.php (L66-95) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
Duplication introduced by
This function seems to be duplicated in 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...
102
{
103
    $ret = array();
104
    $count = count($originals);
105
    for($i = 0; $i < $count; $i++)
106
    {
107
        $dest = $originals[$i];
108
        if(endswith($dest, 'burningflipside.com'))
109
        {
110
            $parts = explode('@', $dest);
111
            if(count($parts) === 2)
112
            {
113
                $dests = getDestinationsForID($parts[0]);
114
                if($dests === false)
115
                {
116
                    file_put_contents('/var/www/profiles/tmp/log.log', "getActualDestinations: Invalid destination id $parts[0]\n", FILE_APPEND);
117
                }
118
                else
119
                {
120
                    $ret = array_merge($ret, $dests);
121
                }
122
            }
123
            else
124
            {
125
                file_put_contents('/var/www/profiles/tmp/log.log', "getActualDestinations: Invalid destination format $dest\n", FILE_APPEND);
126
            }
127
        }
128
    }
129
    return $ret;
130
}
131
132
function getRawMessage($action)
0 ignored issues
show
Best Practice introduced by
The function getRawMessage() has been defined more than once; this definition is ignored, only the first definition in _local/run.php (L97-108) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
133
{
134
    $s3Client = S3Client::factory();
135
    $object = $s3Client->getObject(array('Bucket'=>$action['bucketName'], 'Key'=>$action['objectKey']));
136
    file_put_contents('/var/www/profiles/tmp/log.log', print_r($object, true), FILE_APPEND);
137
    return $object;
138
}
139
140
function processListServMessage($message)
0 ignored issues
show
Best Practice introduced by
The function processListServMessage() has been defined more than once; this definition is ignored, only the first definition in _local/run.php (L154-189) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
141
{
142
    $message = json_decode($message);
143
    $dests = getActualDestinations($message->mail->destination);
144
    file_put_contents('/var/www/profiles/tmp/log.log', print_r($dests, true), FILE_APPEND);
145
    $rawMessage = getRawMessage($message['action']);
0 ignored issues
show
Unused Code introduced by
$rawMessage is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
146
    //file_put_contents('/var/www/profiles/tmp/log.log', print_r($message, true), FILE_APPEND);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
147
    file_put_contents('/var/www/profiles/tmp/log.log', "processListServMessage: Exited\n", FILE_APPEND);
148
}
149
150
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
151