Skip to content

Commit 4473f22

Browse files
committed
Причесывание псалмом.
1 parent fa2b2b6 commit 4473f22

File tree

10 files changed

+60
-69
lines changed

10 files changed

+60
-69
lines changed

psalm.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@
4444
<directory name="/"/>
4545
</errorLevel>
4646
</UndefinedConstant>
47+
<UnsafeInstantiation>
48+
<errorLevel type="suppress">
49+
<directory name="/"/>
50+
</errorLevel>
51+
</UnsafeInstantiation>
52+
<InvalidClone>
53+
<errorLevel type="suppress">
54+
<directory name="/"/>
55+
</errorLevel>
56+
</InvalidClone>
4757
<MissingDependency>
4858
<errorLevel type="suppress">
4959
<directory name="/"/>

src/Micro/AbstractStandaloneServiceProvider.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@ class AbstractStandaloneServiceProvider extends ServiceProvider
2727
protected $standartCompilerPasses;
2828

2929
/**
30-
* AbstractStandaloneServiceProvider constructor.
31-
*
32-
* @param string $filename Конфиг.
33-
*
34-
* @throws Exception Ошибка инициализации контейнера.
30+
* @inheritDoc
3531
*/
36-
public function __construct(
37-
string $filename
38-
) {
32+
public function __construct(string $filename) {
3933
$this->symfonyCompilerClass = SymfonyCompilerPassBagLight::class;
4034
parent::__construct($filename);
4135
}

src/ServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
* @since 04.04.2021 Вынес стандартные compile pass Symfony в отдельный класс.
6262
* @since 14.04.2021 Метод boot бандлов вызывается теперь после компиляции контейнера.
6363
* @since 27.04.2021 Баг-фикс: при скомпилированном контейнере не запускался метод boot бандлов.
64+
*
65+
* @psalm-consistent-constructor
6466
*/
6567
class ServiceProvider
6668
{

src/Services/AppKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function getLogDir()
8080
/**
8181
* Gets the application root dir.
8282
*
83-
* @return string The project root dir
83+
* @return string The project root dir.
8484
*/
8585
public function getProjectDir(): string
8686
{

src/Services/PSR/PSR17/HttpFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ public function createStreamFromResource($resource): StreamInterface
8888
*/
8989
public function createUploadedFile(
9090
StreamInterface $stream,
91-
int $size = null,
91+
?int $size = null,
9292
int $error = \UPLOAD_ERR_OK,
93-
string $clientFilename = null,
94-
string $clientMediaType = null
93+
?string $clientFilename = null,
94+
?string $clientMediaType = null
9595
): UploadedFileInterface
9696
{
9797
return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType);

src/Services/PSR/PSR18/PsrClient.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,33 @@ public function sendRequest(RequestInterface $request): ResponseInterface
5555
return new Response($bxClient->getStatus(), $this->normalizeHeader($bxClient->getHeaders()), $responseBody);
5656
}
5757

58-
5958
/**
60-
* @param HttpClient $httpClient
61-
* @param RequestInterface $request
59+
* @param HttpClient $httpClient HTTP клиент.
60+
* @param RequestInterface $request PSR-7 Request.
61+
*
62+
* @return void
6263
*/
63-
private function loadHeaders(HttpClient $httpClient, RequestInterface $request)
64+
private function loadHeaders(HttpClient $httpClient, RequestInterface $request) : void
6465
{
6566
$httpClient->clearHeaders();
6667
foreach ($request->getHeaders() as $name => $values) {
67-
$httpClient->setHeader($name, implode(", ", $values));
68+
$httpClient->setHeader($name, implode(', ', $values));
6869
}
6970
}
7071

7172
/**
72-
* @param HttpHeaders $headers
73+
* @param HttpHeaders $headers Битриксовые заголовки.
74+
*
7375
* @return array
7476
*/
7577
private function normalizeHeader(HttpHeaders $headers): array
7678
{
7779
$result = [];
80+
/** @psalm-suppress RawObjectIteration */
7881
foreach ($headers as $key => $value) {
79-
$result[$key] = implode(", ", (array)$value);
82+
$result[$key] = implode(', ', (array)$value);
8083
}
8184

8285
return $result;
8386
}
84-
}
87+
}

src/Services/PSR/PSR7/Message.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Message implements MessageInterface
2424
protected $request;
2525

2626
/**
27-
* @var string $httpVersion
27+
* @var string|null $httpVersion
2828
*/
2929
protected $httpVersion;
3030

@@ -54,7 +54,7 @@ class Message implements MessageInterface
5454
*/
5555
public function __construct(
5656
HttpRequest $request,
57-
string $httpVersion = null,
57+
?string $httpVersion = null,
5858
$body = null,
5959
array $attributes = []
6060
) {
@@ -129,11 +129,11 @@ public function getHeader($name)
129129
public function getHeaderLine($name)
130130
{
131131
$value = $this->getHeader($name);
132-
if (empty($value)) {
132+
if (count($value) === 0) {
133133
return '';
134134
}
135135

136-
return implode(',', (array)$value);
136+
return implode(',', $value);
137137
}
138138

139139
/**
@@ -143,6 +143,7 @@ public function withHeader($name, $value)
143143
{
144144
$newRequest = $this->getClonedRequest();
145145
$newRequest->getHeaders()->add($name, $value);
146+
146147
return new static($newRequest, $this->httpVersion, $this->body, $this->attributes);
147148
}
148149

@@ -200,6 +201,14 @@ public function withBody(StreamInterface $body)
200201
return new static($this->request, $this->httpVersion, $body, $this->attributes);
201202
}
202203

204+
/**
205+
* @return HttpRequest
206+
*/
207+
protected function getClonedRequest()
208+
{
209+
return clone $this->request;
210+
}
211+
203212
/**
204213
* @param HttpRequest $request Битриксовый Request.
205214
*

src/Services/PSR/PSR7/PsrRequest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Prokl\ServiceProvider\Services\PSR\PSR7;
44

5-
use Bitrix\Main\HttpRequest;
65
use Psr\Http\Message\RequestInterface;
76
use Psr\Http\Message\UriInterface;
87

@@ -68,12 +67,4 @@ public function withUri(UriInterface $uri, $preserveHost = false)
6867

6968
return new static($newRequest, $this->httpVersion, $this->body, $this->attributes);
7069
}
71-
72-
/**
73-
* @return HttpRequest
74-
*/
75-
protected function getClonedRequest()
76-
{
77-
return clone $this->request;
78-
}
7970
}

src/Services/PSR/PSR7/PsrResponse.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@
1212
/**
1313
* Class PsrResponse
1414
* @package Prokl\ServiceProvider\Services\Convertor
15+
*
16+
* @psalm-consistent-constructor
1517
*/
1618
class PsrResponse implements ResponseInterface, Serializable
1719
{
1820
private const DEFAULT_HTTP_VERSION = '1.1';
1921

2022
/**
21-
* @var HttpResponse $response
23+
* @var HttpResponse $response Битриксовый Response.
2224
*/
2325
private $response;
2426

2527
/**
26-
* @var string|null $httpVersion
28+
* @var string $httpVersion
2729
*/
2830
private $httpVersion;
2931

@@ -35,11 +37,11 @@ class PsrResponse implements ResponseInterface, Serializable
3537
/**
3638
* PsrResponse constructor.
3739
*
38-
* @param HttpResponse $response
39-
* @param string|null $httpVersion
40-
* @param string $body
40+
* @param HttpResponse $response Битриксовый Response.
41+
* @param string|null $httpVersion HTTP version.
42+
* @param string|null $body Тело ответа.
4143
*/
42-
public function __construct(HttpResponse $response, ?string $httpVersion = null, $body = '')
44+
public function __construct(HttpResponse $response, ?string $httpVersion = null, ?string $body = '')
4345
{
4446
$this->response = $response;
4547
$this->httpVersion = $httpVersion ?? static::DEFAULT_HTTP_VERSION;
@@ -106,6 +108,7 @@ public function withHeader($name, $value)
106108
{
107109
$newResponse = clone $this->response;
108110
$newResponse->getHeaders()->set($name, $value);
111+
109112
return new static($newResponse, $this->httpVersion, $this->body);
110113
}
111114

src/Services/PSR/PSR7/ServerPsrRequest.php

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class ServerPsrRequest extends PsrRequest implements ServerRequestInterface
1313
{
1414
/**
15-
* @return array
15+
* @inheritDoc
1616
*/
1717
public function getServerParams(): array
1818
{
@@ -128,59 +128,38 @@ public function getAttributes(): array
128128
/**
129129
* @inheritDoc
130130
*/
131-
public function getAttribute($attribute, $default = null)
131+
public function getAttribute($name, $default = null)
132132
{
133-
if (false === array_key_exists($attribute, $this->attributes)) {
133+
if (false === array_key_exists($name, $this->attributes)) {
134134
return $default;
135135
}
136136

137-
return $this->attributes[$attribute];
137+
return $this->attributes[$name];
138138
}
139139

140140
/**
141141
* @inheritDoc
142142
*/
143-
public function withAttribute($attribute, $value): ServerRequestInterface
143+
public function withAttribute($name, $value): ServerRequestInterface
144144
{
145145
$new = clone $this;
146-
$new->attributes[$attribute] = $value;
146+
$new->attributes[$name] = $value;
147147

148148
return $new;
149149
}
150150

151151
/**
152152
* @inheritDoc
153153
*/
154-
public function withoutAttribute($attribute): ServerRequestInterface
154+
public function withoutAttribute($name): ServerRequestInterface
155155
{
156-
if (false === array_key_exists($attribute, $this->attributes)) {
156+
if (false === array_key_exists($name, $this->attributes)) {
157157
return $this;
158158
}
159159

160160
$new = clone $this;
161-
unset($new->attributes[$attribute]);
161+
unset($new->attributes[$name]);
162162

163163
return $new;
164164
}
165-
166-
/**
167-
* @return array
168-
*/
169-
private function getFileList(): array
170-
{
171-
$fileList = [];
172-
foreach ($this->request->getFileList() as $key => $file) {
173-
foreach ($file as $k => $value) {
174-
if (is_array($value)) {
175-
foreach ($value as $i => $v) {
176-
$fileList[$key][$i][$k] = $v;
177-
}
178-
} else {
179-
$fileList[$key][$k] = $v;
180-
}
181-
}
182-
}
183-
184-
return $fileList;
185-
}
186165
}

0 commit comments

Comments
 (0)