Completed
Push — master ( b29d6b...03436d )
by Bjørn
03:06
created

Header::setHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace WebPConvert\Serve;
3
4
/**
5
 * Add / Set HTTP header.
6
 *
7
 * This class does nothing more than adding two convenience functions for calling the "header" function.
8
 *
9
 * @package    WebPConvert
10
 * @author     Bjørn Rosell <[email protected]>
11
 * @since      Class available since Release 2.0.0
12
 */
13
class Header
14
{
15
    /**
16
     * Convenience function for adding header (append).
17
     *
18
     * @return void
19
     */
20 3
    public static function addHeader($header)
21
    {
22 3
        header($header, false);
23 3
    }
24
25
    /**
26
     * Convenience function for replacing header.
27
     *
28
     * @return void
29
     */
30 5
    public static function setHeader($header)
31
    {
32 5
        header($header, true);
33 5
    }
34
35
    /**
36
     * @param  string  $msg  Message to add to "X-WebP-Convert-Log" header
37
     * @param  \WebPConvert\Loggers\BaseLogger $logger (optional)
38
     * @return void
39
     */
40 1
    public static function addLogHeader($msg, $logger = null)
41
    {
42 1
        self::addHeader('X-WebP-Convert-Log: ' . $msg);
43 1
        if (!is_null($logger)) {
44 1
            $logger->logLn($msg);
45
        }
46 1
    }
47
}
48