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

Minifier::css()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4286
cc 1
eloc 4
nc 1
nop 1
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