AsyncHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 57
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 17 1
A escapeshellarg() 0 10 2
A handle() 0 10 2
1
<?php namespace Understand\UnderstandLaravel5\Handlers;
2
3
class AsyncHandler extends BaseHandler
4
{
5
6
    /**
7
     * @param string $escapedData
8
     * @return string|void
9
     */
10
    protected function send($escapedData)
11
    {
12
        $parts = [
13
            'curl',
14
            '-X POST',
15
            '--cacert',
16
            $this->sslBundlePath,
17
            '-d',
18
            $escapedData,
19
            $this->getEndpoint(),
20
            '> /dev/null 2>&1 &'
21
        ];
22
23
        $cmd = implode(' ', $parts);
24
25
        exec($cmd);
26
    }
27
28
    /**
29
     * @param $requestData
30
     * @return string|void
31
     */
32
    protected function escapeshellarg($requestData)
33
    {
34
        // the `escapeshellarg` function throws a fatal error in Unix if the size exceeds 2097152 bytes (~2mb)
35
        if (strlen($requestData) >= 2000000)
36
        {
37
            return;
38
        }
39
40
        return escapeshellarg($requestData);
41
    }
42
43
    /**
44
     * Serialize data and send to storage
45
     *
46
     * @param array $requestData
47
     * @return void
48
     */
49
    public function handle(array $requestData)
50
    {
51
        $json = json_encode($requestData);
52
        $escapedData = $this->escapeshellarg($json);
53
54
        if ($escapedData)
0 ignored issues
show
Bug Best Practice introduced by
The expression $escapedData of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
55
        {
56
            return $this->send($escapedData);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->send($escapedData); of type string|null adds the type string to the return on line 56 which is incompatible with the return type of the parent method Understand\UnderstandLar...ers\BaseHandler::handle of type array.
Loading history...
57
        }
58
    }
59
}
60