WorkermanHttpWrapper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A start() 0 5 1
A onWorkerStart() 0 5 1
A onRequest() 0 9 1
A endResponse() 0 12 2
1
<?php
2
namespace Laravoole\Wrapper;
3
4
use Laravoole\Workerman\Worker;
5
use Laravoole\Illuminate\Request;
6
use Laravoole\Response;
7
8
class WorkermanHttpWrapper extends Workerman implements ServerInterface
9
{
10
    use HttpTrait;
11
12 4
    public function __construct($host, $port)
13
    {
14 4
        parent::__construct($host, $port);
15 4
        $this->server = new Worker("http://{$host}:{$port}");
16 4
    }
17
18 4
    public function start()
19
    {
20 4
        $this->on('Receive', [$this, 'onRequest']);
21 4
        return parent::start();
22
    }
23
24 4
    public function onWorkerStart($worker)
25
    {
26 4
        parent::onWorkerStart($worker);
27 4
        $this->accept_gzip = config('laravoole.base_config.gzip');
28 4
    }
29
30 4
    public function onRequest($connection, $data)
31
    {
32 4
        $request = new Request($data['get'], $data['post'], []/* attributes */, $data['cookie'], $data['files'], $data['server']);
33 4
        $request->setLaravooleInfo(['workermanConnection' => $connection]);
34 4
        $response = new Response($this, $request);
35
        // provide response callback
36 4
        $illuminateResponse = parent::handleRequest($request);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (handleRequest() instead of onRequest()). Are you sure this is correct? If so, you might want to change this to $this->handleRequest().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
37 4
        return $this->handleResponse($response, $illuminateResponse, $request->header('Accept-Encoding', ''));
0 ignored issues
show
Bug introduced by
It seems like $request->header('Accept-Encoding', '') targeting Illuminate\Http\Concerns...actsWithInput::header() can also be of type array; however, Laravoole\Wrapper\HttpTrait::handleResponse() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
38
    }
39
40 4
    public function endResponse($response, $content)
41
    {
42 4
    	$connection = $response->request->getLaravooleInfo()->workermanConnection;
43 4
        if (!is_string($content)) {
44 4
        	$response->content = file_get_contents($content());
45 2
        } else {
46 4
        	$response->content = $content;
47
        }
48 4
        $rawContent = $response->getRawContent();
49 4
    	$connection->maxSendBufferSize = strlen($rawContent);
50 4
        $connection->close($rawContent, true);
51 4
    }
52
}
53