| Total Complexity | 17 |
| Total Lines | 263 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | final class DsnRequest |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * The request uri |
||
| 14 | * |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | private $url; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * The protocol to use |
||
| 21 | * |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | private $scheme; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Host specification |
||
| 28 | * |
||
| 29 | * @var string|null |
||
| 30 | */ |
||
| 31 | private $host; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Port specification |
||
| 35 | * |
||
| 36 | * @var string|null |
||
| 37 | */ |
||
| 38 | private $port; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * User name for login |
||
| 42 | * |
||
| 43 | * @var string|null |
||
| 44 | */ |
||
| 45 | private $user; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Password for login |
||
| 49 | * |
||
| 50 | * @var string|null |
||
| 51 | */ |
||
| 52 | private $password; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Path info from the dsn |
||
| 56 | * |
||
| 57 | * @var string|null |
||
| 58 | */ |
||
| 59 | private $path; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * The query bag |
||
| 63 | * |
||
| 64 | * @var array |
||
| 65 | */ |
||
| 66 | private $query = []; |
||
| 67 | |||
| 68 | |||
| 69 | /** |
||
| 70 | * DsnRequest constructor. |
||
| 71 | * |
||
| 72 | * @param string $url |
||
| 73 | * @param string $scheme |
||
| 74 | */ |
||
| 75 | 13 | public function __construct(string $url, string $scheme) |
|
| 76 | { |
||
| 77 | 13 | $this->url = $url; |
|
| 78 | 13 | $this->scheme = $scheme; |
|
| 79 | 13 | } |
|
| 80 | |||
| 81 | /** |
||
| 82 | * Gets the request url |
||
| 83 | * |
||
| 84 | * @return null|string |
||
| 85 | */ |
||
| 86 | 2 | public function getUrl(): ?string |
|
| 87 | { |
||
| 88 | 2 | return $this->url; |
|
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Gets the scheme part |
||
| 93 | * |
||
| 94 | * @return null|string |
||
| 95 | */ |
||
| 96 | 7 | public function getScheme(): ?string |
|
| 97 | { |
||
| 98 | 7 | return $this->scheme; |
|
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Gets the host part |
||
| 103 | * |
||
| 104 | * @return null|string |
||
| 105 | */ |
||
| 106 | 6 | public function getHost(): ?string |
|
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Sets the host part |
||
| 113 | * |
||
| 114 | * @param string $host |
||
| 115 | * |
||
| 116 | * @return $this |
||
| 117 | */ |
||
| 118 | 8 | public function setHost(string $host): self |
|
| 119 | { |
||
| 120 | 8 | $this->host = $host; |
|
| 121 | |||
| 122 | 8 | return $this; |
|
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Gets the port part |
||
| 127 | * |
||
| 128 | * @return null|string |
||
| 129 | */ |
||
| 130 | 3 | public function getPort(): ?string |
|
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Sets the port part |
||
| 137 | * |
||
| 138 | * @param string $port |
||
| 139 | * |
||
| 140 | * @return $this |
||
| 141 | */ |
||
| 142 | 3 | public function setPort(string $port): self |
|
| 143 | { |
||
| 144 | 3 | $this->port = $port; |
|
| 145 | |||
| 146 | 3 | return $this; |
|
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Gets the user part |
||
| 151 | * |
||
| 152 | * @return null|string |
||
| 153 | */ |
||
| 154 | 5 | public function getUser(): ?string |
|
| 155 | { |
||
| 156 | 5 | return $this->user; |
|
| 157 | } |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Sets the user part |
||
| 161 | * |
||
| 162 | * @param string $user |
||
| 163 | * |
||
| 164 | * @return $this |
||
| 165 | */ |
||
| 166 | 5 | public function setUser(string $user): self |
|
| 167 | { |
||
| 168 | 5 | $this->user = $user; |
|
| 169 | |||
| 170 | 5 | return $this; |
|
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Gets the password part |
||
| 175 | * |
||
| 176 | * @return null|string |
||
| 177 | */ |
||
| 178 | 5 | public function getPassword(): ?string |
|
| 179 | { |
||
| 180 | 5 | return $this->password; |
|
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Sets the password part |
||
| 185 | * |
||
| 186 | * @param string $password |
||
| 187 | * |
||
| 188 | * @return $this |
||
| 189 | */ |
||
| 190 | 5 | public function setPassword(string $password): self |
|
| 191 | { |
||
| 192 | 5 | $this->password = $password; |
|
| 193 | |||
| 194 | 5 | return $this; |
|
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Gets the path part |
||
| 199 | * |
||
| 200 | * @return null|string |
||
| 201 | */ |
||
| 202 | 8 | public function getPath(): ?string |
|
| 203 | { |
||
| 204 | 8 | return $this->path; |
|
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Sets the path part |
||
| 209 | * |
||
| 210 | * @param string $path |
||
| 211 | * |
||
| 212 | * @return $this |
||
| 213 | */ |
||
| 214 | 10 | public function setPath(string $path): self |
|
| 215 | { |
||
| 216 | 10 | $this->path = $path; |
|
| 217 | |||
| 218 | 10 | return $this; |
|
| 219 | } |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Gets the query part |
||
| 223 | * |
||
| 224 | * @return array |
||
| 225 | */ |
||
| 226 | 2 | public function getQuery(): array |
|
| 227 | { |
||
| 228 | 2 | return $this->query; |
|
| 229 | } |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Sets the query part |
||
| 233 | * |
||
| 234 | * @param array $query |
||
| 235 | * |
||
| 236 | * @return $this |
||
| 237 | */ |
||
| 238 | 7 | public function setQuery(array $query): self |
|
| 243 | } |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Sets the query part |
||
| 247 | * |
||
| 248 | * @param string $key |
||
| 249 | * @param mixed $default |
||
| 250 | * |
||
| 251 | * @return mixed |
||
| 252 | */ |
||
| 253 | 6 | public function query(string $key, $default = null) |
|
| 254 | { |
||
| 255 | 6 | return $this->query[$key] ?? $default; |
|
| 256 | } |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Gets array representation |
||
| 260 | * |
||
| 261 | * @return array |
||
| 262 | */ |
||
| 263 | 1 | public function toArray(): array |
|
| 273 | ]; |
||
| 274 | } |
||
| 275 | } |