Skip to content

Commit eb684dd

Browse files
Исправление в оформлении кода
1 parent a7782db commit eb684dd

File tree

2 files changed

+29
-44
lines changed

2 files changed

+29
-44
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ src/
3333

3434
Если удобно писать на почту, то можете воспользоваться этим адресом: mepihindeveloper@gmail.com
3535

36-
Мой канал на YouTube, который посвящен разработке веб и игровых проектов: [YouTube: Максим Епихин](https://www.youtube.com/channel/UCKusRcoHUy6T4sei-rVzCqQ)
36+
Мой канал на YouTube, который посвящен разработке веб и игровых
37+
проектов: [YouTube: Максим Епихин](https://www.youtube.com/channel/UCKusRcoHUy6T4sei-rVzCqQ)
3738

3839
Поддержать меня можно переводом на Яндекс.Деньги: [Денежный перевод](https://yoomoney.ru/to/410012382226565)

src/Headers.php

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
*
1313
* Реализует управление заголовками запроса
1414
*/
15-
class Headers implements HeadersInterface
16-
{
15+
class Headers implements HeadersInterface {
1716

1817
/**
1918
* @var array Заголовки
2019
*/
2120
private array $headers;
2221

23-
public function __construct()
24-
{
22+
public function __construct() {
2523
$this->headers = $this->getAllHeaders();
2624
}
2725

@@ -30,23 +28,19 @@ public function __construct()
3028
*
3129
* @return array
3230
*/
33-
private function getAllHeaders(): array
34-
{
31+
private function getAllHeaders(): array {
3532
if (function_exists('getallheaders')) {
3633
return getallheaders() !== false ? getallheaders() : [];
3734
}
38-
39-
if (!is_array($_SERVER))
40-
{
35+
36+
if (!is_array($_SERVER)) {
4137
return [];
4238
}
4339

4440
$headers = [];
4541

46-
foreach ($_SERVER as $name => $value)
47-
{
48-
if (strpos($name, 'HTTP_') === 0)
49-
{
42+
foreach ($_SERVER as $name => $value) {
43+
if (strpos($name, 'HTTP_') === 0) {
5044
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
5145
}
5246
}
@@ -57,12 +51,10 @@ private function getAllHeaders(): array
5751
/**
5852
* @inheritDoc
5953
*/
60-
public function set(array $params): void
61-
{
54+
public function set(array $params): void {
6255
$this->getAll();
6356

64-
foreach ($params as $header => $value)
65-
{
57+
foreach ($params as $header => $value) {
6658
$this->headers[$header] = $value;
6759
}
6860

@@ -72,10 +64,17 @@ public function set(array $params): void
7264
/**
7365
* @inheritDoc
7466
*/
75-
public function add(array $params): void
76-
{
77-
foreach ($params as $header => $value)
78-
{
67+
public function getAll(): array {
68+
$this->headers = !empty($this->headers) ? $this->headers : $this->getAllHeaders();
69+
70+
return $this->headers;
71+
}
72+
73+
/**
74+
* @inheritDoc
75+
*/
76+
public function add(array $params): void {
77+
foreach ($params as $header => $value) {
7978
$headerExists = array_key_exists($header, $this->headers);
8079
$this->headers[$header] = $value;
8180

@@ -86,8 +85,7 @@ public function add(array $params): void
8685
/**
8786
* @inheritDoc
8887
*/
89-
public function remove(string $key): void
90-
{
88+
public function remove(string $key): void {
9189
$this->getAll();
9290

9391
unset($this->headers[$key]);
@@ -97,8 +95,7 @@ public function remove(string $key): void
9795
/**
9896
* @inheritDoc
9997
*/
100-
public function removeAll(): void
101-
{
98+
public function removeAll(): void {
10299
$this->headers = [];
103100

104101
header_remove();
@@ -107,20 +104,8 @@ public function removeAll(): void
107104
/**
108105
* @inheritDoc
109106
*/
110-
public function has(string $key): bool
111-
{
112-
$this->getAll();
113-
114-
return array_key_exists($key, $this->headers);
115-
}
116-
117-
/**
118-
* @inheritDoc
119-
*/
120-
public function get(string $key): string
121-
{
122-
if (!$this->has($key))
123-
{
107+
public function get(string $key): string {
108+
if (!$this->has($key)) {
124109
throw new InvalidArgumentException("Заголовок {$key} отсутствует.");
125110
}
126111

@@ -130,10 +115,9 @@ public function get(string $key): string
130115
/**
131116
* @inheritDoc
132117
*/
133-
public function getAll(): array
134-
{
135-
$this->headers = !empty($this->headers) ? $this->headers : $this->getAllHeaders();
118+
public function has(string $key): bool {
119+
$this->getAll();
136120

137-
return $this->headers;
121+
return array_key_exists($key, $this->headers);
138122
}
139123
}

0 commit comments

Comments
 (0)