HttpException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 6 1
A render() 0 9 2
1
<?php
2
/**
3
 * Simple Exception to represent http-based Exceptions.
4
 *
5
 * PHP version 5.3
6
 *
7
 * @category Exception
8
 *
9
 * @package Teapot
10
 *
11
 * @author    Barney Hanlon <[email protected]>
12
 * @copyright 2013-2016 B Hanlon. All rights reserved.
13
 * @license   MIT http://opensource.org/licenses/MIT
14
 *
15
 * @link https://shrikeh.github.com/teapot
16
 */
17
namespace Teapot;
18
19
/**
20
 * Simple Exception to represent http-based Exceptions.
21
 *
22
 * @category Exception
23
 *
24
 * @package Teapot
25
 *
26
 * @author    Barney Hanlon <[email protected]>
27
 * @copyright 2013-2016 B Hanlon. All rights reserved.
28
 * @license   MIT http://opensource.org/licenses/MIT
29
 *
30
 * @link https://shrikeh.github.com/teapot
31
 */
32
class HttpException extends \Exception implements StatusCode
33
{
34
    /**
35
     * The standard HTTP 1.1 prefix.
36
     *
37
     * @var string
38
     */
39
    const HTTP1_1_PREFIX = 'HTTP/1.1';
40
    /**
41
     * Simple magic so you can use the Exception directly as a string, for
42
     * example in header();.
43
     *
44
     * @return string A fully valid status header
45
     */
46
    public function __toString()
47
    {
48
        // I dislike functionality inside magic methods,
49
        // so this just proxies to render().
50
        return $this->render();
51
    }
52
53
    /**
54
     * Render the code and message (in whole or in part) as a valid
55
     * response status header.
56
     *
57
     * @param bool $prependHttp Whether to prepend the HTTP/1.1 prefix
58
     *
59
     * @return string
60
     */
61
    public function render($prependHttp = true)
62
    {
63
        $string = $this->getCode().' '.$this->getMessage();
64
        if (true === $prependHttp) {
65
            $string = self::HTTP1_1_PREFIX.' '.$string;
66
        }
67
68
        return $string;
69
    }
70
}
71