Skip to content

Commit 2ddfdfa

Browse files
Bernhard Schmittmficzel
authored andcommitted
TASK: Reduce breakiness and Increase PhpStan happiness
1 parent ceddd02 commit 2ddfdfa

8 files changed

Lines changed: 26 additions & 15 deletions

File tree

Neos.Flow/Classes/Http/Client/Browser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function removeAutomaticRequestHeader($name)
148148
* @throws InfiniteRedirectionException
149149
* @api
150150
*/
151-
public function request(string|UriInterface $uri, $method = 'GET', array $arguments = [], array $files = [], array $server = [], $content = null): ResponseInterface
151+
public function request($uri, $method = 'GET', array $arguments = [], array $files = [], array $server = [], $content = null)
152152
{
153153
if (is_string($uri)) {
154154
$uri = new Uri($uri);

Neos.Flow/Classes/Http/Client/CurlEngine.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ class CurlEngine implements RequestEngineInterface
4242
*
4343
* @param integer $optionName One of the CURLOPT_* constants
4444
* @param mixed $value The value to set
45+
* @return void
4546
* @throws \InvalidArgumentException
4647
*/
47-
public function setOption($optionName, $value): void
48+
public function setOption($optionName, $value)
4849
{
4950
if ($optionName === CURLOPT_HTTPHEADER) {
5051
throw new InvalidArgumentException("Setting CURL headers is only possible via the request object and not by using the setOption method.", 1633334307);

Neos.Flow/Classes/Http/ContentStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function detach()
105105
* @param string|resource $stream
106106
* @param string $mode
107107
*/
108-
public function replace(mixed $stream, $mode = 'r'): void
108+
public function replace($stream, $mode = 'r'): void
109109
{
110110
$this->close();
111111
if (is_string($stream)) {

Neos.Flow/Classes/Http/Cookie.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ class Cookie
113113
*
114114
* @param string $name The cookie name as a valid token (RFC 2616)
115115
* @param mixed $value The value to store in the cookie. Must be possible to cast into a string.
116-
* @param integer|\DateTimeInterface $expires Date and time after which this cookie expires.
117-
* @param ?integer $maximumAge Number of seconds until the cookie expires.
116+
* @param int|\DateTimeInterface $expires Date and time after which this cookie expires.
117+
* @param ?int $maximumAge Number of seconds until the cookie expires.
118118
* @param ?string $domain The host to which the user agent will send this cookie
119119
* @param string $path The path describing the scope of this cookie
120120
* @param boolean $secure If this cookie should only be sent through a "secure" channel by the user agent
@@ -123,21 +123,25 @@ class Cookie
123123
* @api
124124
* @throws \InvalidArgumentException
125125
*/
126-
public function __construct($name, $value = null, int|\DateTimeInterface $expires = 0, ?int $maximumAge = null, $domain = null, $path = '/', $secure = false, $httpOnly = true, $sameSite = null)
126+
public function __construct($name, $value = null, $expires = 0, $maximumAge = null, $domain = null, $path = '/', $secure = false, $httpOnly = true, $sameSite = null)
127127
{
128128
if (preg_match(self::PATTERN_TOKEN, $name) !== 1) {
129129
throw new \InvalidArgumentException('The parameter "name" passed to the Cookie constructor must be a valid token as per RFC 2616, Section 2.2.', 1345101977);
130130
}
131131
if ($expires instanceof \DateTimeInterface) {
132132
$expires = $expires->getTimestamp();
133133
}
134-
if ($maximumAge !== null) {
134+
if (!is_int($expires)) {
135+
throw new \InvalidArgumentException('The parameter "expires" passed to the Cookie constructor must be a unix timestamp or a DateTimeInterface object.', 1345108785);
136+
}
137+
/** @phpstan-ignore booleanAnd.alwaysFalse (until $maximumAge is typed ?int in php) */
138+
if ($maximumAge !== null && !is_int($maximumAge)) {
135139
throw new \InvalidArgumentException('The parameter "maximumAge" passed to the Cookie constructor must be an integer value.', 1345108786);
136140
}
137141
if ($domain !== null && preg_match(self::PATTERN_DOMAIN, $domain) !== 1) {
138142
throw new \InvalidArgumentException('The parameter "domain" passed to the Cookie constructor must be a valid domain as per RFC 6265, Section 4.1.2.3.', 1345116246);
139143
}
140-
if (preg_match(self::PATTERN_PATH, $path) !== 1) {
144+
if ($path !== null && preg_match(self::PATTERN_PATH, $path) !== 1) {
141145
throw new \InvalidArgumentException('The parameter "path" passed to the Cookie constructor must be a valid path as per RFC 6265, Section 4.1.1.', 1345123078);
142146
}
143147

Neos.Flow/Classes/Http/Middleware/MiddlewaresChain.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ final class MiddlewaresChain implements RequestHandlerInterface
3131
*/
3232
private $stepCallbacks = [];
3333

34-
public function __construct(MiddlewareInterface ...$middlewaresChain)
34+
/**
35+
* @param MiddlewareInterface[] $middlewaresChain
36+
*/
37+
public function __construct(array $middlewaresChain)
3538
{
3639
$this->chain = $middlewaresChain;
3740
}

Neos.Flow/Classes/Http/Middleware/MiddlewaresChainFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ public function create(array $chainConfiguration): MiddlewaresChain
5353
$middlewaresChain[] = $middleware;
5454
}
5555

56-
return new MiddlewaresChain(...$middlewaresChain);
56+
return new MiddlewaresChain($middlewaresChain);
5757
}
5858
}

Neos.Flow/Classes/Http/RequestHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ protected function resolveDependencies()
149149
/**
150150
* Send the HttpResponse of the component context to the browser and flush all output buffers.
151151
* @param ResponseInterface $response
152+
* @return void
152153
*/
153-
protected function sendResponse(ResponseInterface $response): void
154+
protected function sendResponse(ResponseInterface $response)
154155
{
155156
ob_implicit_flush();
156157
foreach (ResponseInformationHelper::prepareHeaders($response) as $prepareHeader) {

Neos.Flow/Classes/Http/UploadedFile.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ public function __construct($streamOrFile, $size, $errorStatus, $clientFilename
7373
* Depending on the value set file or stream variable
7474
*
7575
* @param string|StreamInterface|resource $streamOrFile
76+
* @return void
7677
* @throws InvalidArgumentException
7778
*/
78-
protected function setStreamOrFile($streamOrFile): void
79+
protected function setStreamOrFile($streamOrFile)
7980
{
8081
if (is_string($streamOrFile)) {
8182
$this->file = $streamOrFile;
@@ -173,21 +174,21 @@ public function getStream()
173174
* @see http://php.net/is_uploaded_file
174175
* @see http://php.net/move_uploaded_file
175176
* @param string $targetPath Path to which to move the uploaded file.
177+
* @return void
176178
* @throws RuntimeException if the upload was not successful.
177179
* @throws InvalidArgumentException if the $path specified is invalid.
178180
* @throws RuntimeException on any error during the move operation, or on
179181
* the second or subsequent call to the method.
180182
* @api PSR-7
181183
*/
182-
public function moveTo(string $targetPath): void
184+
public function moveTo(string $targetPath)
183185
{
184186
$this->throwExceptionIfNotAccessible();
185187

186188
if (empty($targetPath)) {
187189
throw new InvalidArgumentException('Invalid path provided to move uploaded file to. Must be a non-empty string', 1479747624);
188190
}
189191

190-
/** @phpstan-ignore identical.alwaysTrue (FLOW_SAPITYPE can also be "Web") */
191192
if ($this->stream !== null || ($this->file !== null && FLOW_SAPITYPE === 'CLI')) {
192193
$this->moved = $this->writeFile($targetPath);
193194
}
@@ -274,9 +275,10 @@ public function getClientMediaType()
274275
}
275276

276277
/**
278+
* @return void
277279
* @throws RuntimeException if is moved or not ok
278280
*/
279-
protected function throwExceptionIfNotAccessible(): void
281+
protected function throwExceptionIfNotAccessible()
280282
{
281283
if (!$this->isOk()) {
282284
throw new RuntimeException('UploadedFile has the following error: ' . Files::getUploadErrorMessage($this->error), 1479743608);

0 commit comments

Comments
 (0)