Completed
Push — master ( b2e200...1332b8 )
by Oscar
04:48
created

Gzip   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 50 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 2
c 3
b 0
f 2
lcom 0
cbo 4
dl 18
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A gzip() 9 9 1
A deflate() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Psr7Middlewares\Transformers;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr7Middlewares\Middleware;
7
8
/**
9
 * Generic resolver to gzip compression.
10
 */
11
class Gzip extends Resolver
12
{
13
    /**
14
     * Gzip minifier using gzencode().
15
     * 
16
     * @param ResponseInterface $response
17
     * 
18
     * @return ResponseInterface
19
     */
20 View Code Duplication
    public function gzip(ResponseInterface $response)
0 ignored issues
show
Duplication introduced by
This method 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...
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
21
    {
22
        $stream = Middleware::createStream();
23
        $stream->write(gzencode((string) $response->getBody()));
24
25
        return $response
26
            ->withHeader('Content-Encoding', 'gzip')
27
            ->withBody($stream);
28
    }
29
30
    /**
31
     * Gzip minifier using gzdeflate().
32
     * 
33
     * @param ResponseInterface $response
34
     * 
35
     * @return ResponseInterface
36
     */
37 View Code Duplication
    public function deflate(ResponseInterface $response)
0 ignored issues
show
Duplication introduced by
This method 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...
38
    {
39
        $stream = Middleware::createStream();
40
        $stream->write(gzdeflate((string) $response->getBody()));
41
42
        return $response
43
            ->withHeader('Content-Encoding', 'deflate')
44
            ->withBody($stream);
45
    }
46
}
47