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

Minifier   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 29.79 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 0
cbo 4
dl 14
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A js() 7 7 1
A css() 0 7 1
A html() 7 7 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
use JSMinPlus;
8
use CSSmin;
9
use Minify_HTML;
10
11
/**
12
 * Generic resolver to minify responses.
13
 */
14
class Minifier extends Resolver
15
{
16
    /**
17
     * Javascript minifier.
18
     * 
19
     * @param ResponseInterface $response
20
     * 
21
     * @return ResponseInterface
22
     */
23 View Code Duplication
    public function js(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...
24
    {
25
        $stream = Middleware::createStream();
26
        $stream->write(JSMinPlus::minify((string) $response->getBody()));
27
28
        return $response->withBody($stream);
29
    }
30
31
    /**
32
     * CSS minifier.
33
     * 
34
     * @param ResponseInterface $response
35
     * 
36
     * @return ResponseInterface
37
     */
38
    public function css(ResponseInterface $response)
39
    {
40
        $stream = Middleware::createStream();
41
        $stream->write((new CSSmin())->run((string) $response->getBody()));
42
43
        return $response->withBody($stream);
44
    }
45
46
    /**
47
     * HTML minifier.
48
     * 
49
     * @param ResponseInterface $response
50
     * 
51
     * @return ResponseInterface
52
     */
53 View Code Duplication
    public function html(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...
54
    {
55
        $stream = Middleware::createStream();
56
        $stream->write(Minify_HTML::minify((string) $response->getBody(), ['jsCleanComments' => true]));
57
58
        return $response->withBody($stream);
59
    }
60
}
61