• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

codeigniter4 / CodeIgniter4 / 8677009716

13 Apr 2024 11:45PM UTC coverage: 84.44% (-2.2%) from 86.607%
8677009716

push

github

web-flow
Merge pull request #8776 from kenjis/fix-findQualifiedNameFromPath-Cannot-declare-class-v3

fix: Cannot declare class CodeIgniter\Config\Services, because the name is already in use

0 of 3 new or added lines in 1 file covered. (0.0%)

478 existing lines in 72 files now uncovered.

20318 of 24062 relevant lines covered (84.44%)

188.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.94
/system/HTTP/OutgoingRequest.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\HTTP;
15

16
/**
17
 * Representation of an outgoing, client-side request.
18
 *
19
 * @see \CodeIgniter\HTTP\OutgoingRequestTest
20
 */
21
class OutgoingRequest extends Message implements OutgoingRequestInterface
22
{
23
    /**
24
     * Request method.
25
     *
26
     * @var string
27
     */
28
    protected $method;
29

30
    /**
31
     * A URI instance.
32
     *
33
     * @var URI|null
34
     */
35
    protected $uri;
36

37
    /**
38
     * @param string      $method HTTP method
39
     * @param string|null $body
40
     */
41
    public function __construct(
42
        string $method,
43
        ?URI $uri = null,
44
        array $headers = [],
45
        $body = null,
46
        string $version = '1.1'
47
    ) {
48
        $this->method = $method;
147✔
49
        $this->uri    = $uri;
147✔
50

51
        foreach ($headers as $header => $value) {
147✔
52
            $this->setHeader($header, $value);
1✔
53
        }
54

55
        $this->body            = $body;
147✔
56
        $this->protocolVersion = $version;
147✔
57

58
        if (! $this->hasHeader('Host') && $this->uri->getHost() !== '') {
147✔
59
            $this->setHeader('Host', $this->getHostFromUri($this->uri));
49✔
60
        }
61
    }
62

63
    private function getHostFromUri(URI $uri): string
64
    {
65
        $host = $uri->getHost();
50✔
66

67
        return $host . ($uri->getPort() ? ':' . $uri->getPort() : '');
50✔
68
    }
69

70
    /**
71
     * Retrieves the HTTP method of the request.
72
     *
73
     * @return string Returns the request method (always uppercase)
74
     */
75
    public function getMethod(): string
76
    {
77
        return $this->method;
376✔
78
    }
79

80
    /**
81
     * Sets the request method. Used when spoofing the request.
82
     *
83
     * @return $this
84
     *
85
     * @deprecated Use withMethod() instead for immutability
86
     */
87
    public function setMethod(string $method)
88
    {
UNCOV
89
        $this->method = $method;
×
90

UNCOV
91
        return $this;
×
92
    }
93

94
    /**
95
     * Returns an instance with the specified method.
96
     *
97
     * @param string $method
98
     *
99
     * @return static
100
     */
101
    public function withMethod($method)
102
    {
103
        $request         = clone $this;
1✔
104
        $request->method = $method;
1✔
105

106
        return $request;
1✔
107
    }
108

109
    /**
110
     * Retrieves the URI instance.
111
     *
112
     * @return URI|null
113
     */
114
    public function getUri()
115
    {
116
        return $this->uri;
1✔
117
    }
118

119
    /**
120
     * Returns an instance with the provided URI.
121
     *
122
     * @param URI  $uri          New request URI to use.
123
     * @param bool $preserveHost Preserve the original state of the Host header.
124
     *
125
     * @return static
126
     */
127
    public function withUri(URI $uri, $preserveHost = false)
128
    {
129
        $request      = clone $this;
4✔
130
        $request->uri = $uri;
4✔
131

132
        if ($preserveHost) {
4✔
133
            if ($this->isHostHeaderMissingOrEmpty() && $uri->getHost() !== '') {
3✔
134
                $request->setHeader('Host', $this->getHostFromUri($uri));
1✔
135

136
                return $request;
1✔
137
            }
138

139
            if ($this->isHostHeaderMissingOrEmpty() && $uri->getHost() === '') {
2✔
140
                return $request;
1✔
141
            }
142

143
            if (! $this->isHostHeaderMissingOrEmpty()) {
1✔
144
                return $request;
1✔
145
            }
146
        }
147

148
        if ($uri->getHost() !== '') {
1✔
149
            $request->setHeader('Host', $this->getHostFromUri($uri));
1✔
150
        }
151

152
        return $request;
1✔
153
    }
154

155
    private function isHostHeaderMissingOrEmpty(): bool
156
    {
157
        if (! $this->hasHeader('Host')) {
3✔
158
            return true;
2✔
159
        }
160

161
        return $this->header('Host')->getValue() === '';
1✔
162
    }
163
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc