DynamicResponse::gzip()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Hhxsv5\LaravelS\Swoole;
4
5
use Symfony\Component\HttpFoundation\StreamedResponse;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\StreamedResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
class DynamicResponse extends Response
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class DynamicResponse
Loading history...
8
{
9
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
10
     * @throws \Exception
11
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
12
    public function gzip()
13
    {
14
        if (extension_loaded('zlib')) {
15
            $this->swooleResponse->gzip(2);
0 ignored issues
show
Bug introduced by
The method gzip() does not exist on Swoole\Http\Response. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
            $this->swooleResponse->/** @scrutinizer ignore-call */ 
16
                                   gzip(2);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
16
        } else {
17
            throw new \RuntimeException('Http GZIP requires library "zlib", use "php --ri zlib" to check.');
18
        }
19
    }
20
21
    public function sendContent()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function sendContent()
Loading history...
22
    {
23
        if ($this->laravelResponse instanceof StreamedResponse) {
24
            ob_start();
25
            $this->laravelResponse = $this->laravelResponse->sendContent();
26
            $content = ob_get_clean();
27
        } else {
28
            $content = $this->laravelResponse->getContent();
29
        }
30
31
        $len = strlen($content);
32
        if ($len === 0) {
33
            $this->swooleResponse->end();
34
            return;
35
        }
36
37
        if ($len > $this->chunkLimit) {
38
            for ($offset = 0, $limit = (int)(0.6 * $this->chunkLimit); $offset < $len; $offset += $limit) {
39
                $chunk = substr($content, $offset, $limit);
40
                $this->swooleResponse->write($chunk);
41
            }
42
            $this->swooleResponse->end();
43
        } else {
44
            $this->swooleResponse->end($content);
45
        }
46
    }
47
}