HttpRequest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 7
dl 0
loc 103
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getUri() 0 3 1
A getQuery() 0 3 1
A getMethod() 0 3 1
A getVersion() 0 3 1
A getMessage() 0 3 1
A getHeader() 0 3 1
A getBody() 0 3 1
A toString() 0 13 2
1
<?php
2
3
/*
4
 * Copyright (c) 2011-2015, Celestino Diaz <[email protected]>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 */
24
25
namespace Brickoo\Component\Http;
26
27
/**
28
 * HttpRequest
29
 *
30
 * Implements a http request.
31
 * @author Celestino Diaz <[email protected]>
32
 */
33
class HttpRequest {
34
35
    /** @var \Brickoo\Component\Http\HttpMessage */
36
    private $message;
37
38
    /** @var \Brickoo\Component\Http\Uri */
39
    private $uri;
40
41
    /** @var \Brickoo\Component\Http\HttpMethod */
42
    private $method;
43
44
    /** @var \Brickoo\Component\Http\HttpVersion */
45
    private $version;
46
47
    /**
48
     * Class constructor.
49
     * @param \Brickoo\Component\Http\HttpMethod $method
50
     * @param \Brickoo\Component\Http\HttpVersion $version
51
     * @param \Brickoo\Component\Http\Uri $uri
52
     * @param \Brickoo\Component\Http\HttpMessage $message
53
     */
54 1
    public function __construct(HttpMethod $method, HttpVersion $version, Uri $uri, HttpMessage $message) {
55 1
        $this->method = $method;
56 1
        $this->version = $version;
57 1
        $this->uri = $uri;
58 1
        $this->message = $message;
59 1
    }
60
61
    /**
62
     * Returns the request Uri.
63
     * @return \Brickoo\Component\Http\Uri
64
     */
65 1
    public function getUri() {
66 1
        return $this->uri;
67
    }
68
69
    /**
70
     * Returns the request query part.
71
     * @return \Brickoo\Component\Http\UriQuery
72
     */
73 1
    public function getQuery() {
74 1
        return $this->uri->getQuery();
75
    }
76
77
    /**
78
     * Returns the http method.
79
     * @return \Brickoo\Component\Http\HttpMethod
80
     */
81 1
    public function getMethod() {
82 1
        return $this->method;
83
    }
84
85
    /**
86
     * Returns the http version.
87
     * @return \Brickoo\Component\Http\HttpVersion
88
     */
89 1
    public function getVersion() {
90 1
        return $this->version;
91
    }
92
93
    /**
94
     * Returns the http message.
95
     * @return \Brickoo\Component\Http\HttpMessage
96
     */
97 1
    public function getMessage() {
98 1
        return $this->message;
99
    }
100
101
    /**
102
     * Returns the message header.
103
     * @return \Brickoo\Component\Http\HttpMessageHeader
104
     */
105 1
    public function getHeader() {
106 1
        return $this->message->getHeader();
107
    }
108
109
    /**
110
     * Returns the message body.
111
     * @return \Brickoo\Component\Http\HttpMessageBody
112
     */
113 1
    public function getBody() {
114 1
        return $this->message->getBody();
115
    }
116
117
    /**
118
     * Returns the request string representation.
119
     * @return string the request representation
120
     */
121 1
    public function toString() {
122 1
        $queryString = (($queryString = $this->getQuery()->toString()) ? "?".$queryString : "");
123
124 1
        $request = sprintf("%s %s %s\r\n",
125 1
            $this->getMethod()->toString(),
126 1
            $this->getUri()->getPath().$queryString,
127 1
            $this->getVersion()->toString()
128 1
        );
129 1
        $request .= rtrim($this->getHeader()->toString(), "\r\n");
130 1
        $request .= "\r\n\r\n".$this->getBody()->getContent();
131
132 1
        return $request;
133
    }
134
135
 }
136