Skip to content

Commit f8e1009

Browse files
derrabusnicolas-grekas
authored andcommitted
Switched to non-null defaults in exception constructors
1 parent 8054d1d commit f8e1009

File tree

44 files changed

+131
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+131
-114
lines changed

src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function load($resource, $type = null)
7777
// - this handles the case and prevents the second fatal error
7878
// by triggering an exception beforehand.
7979

80-
throw new LoaderLoadException($resource, null, null, null, $type);
80+
throw new LoaderLoadException($resource, null, 0, null, $type);
8181
}
8282
$this->loading = true;
8383

src/Symfony/Component/Config/Exception/FileLoaderImportCircularReferenceException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class FileLoaderImportCircularReferenceException extends LoaderLoadException
2020
{
21-
public function __construct(array $resources, int $code = null, \Throwable $previous = null)
21+
public function __construct(array $resources, ?int $code = 0, \Throwable $previous = null)
2222
{
2323
$message = sprintf('Circular reference detected in "%s" ("%s" > "%s").', $this->varToString($resources[0]), implode('" > "', $resources), $resources[0]);
2424

src/Symfony/Component/Config/Exception/FileLoaderLoadException.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
class FileLoaderLoadException extends \Exception
2222
{
2323
/**
24-
* @param string $resource The resource that could not be imported
25-
* @param string $sourceResource The original resource importing the new resource
26-
* @param int $code The error code
27-
* @param \Throwable $previous A previous exception
28-
* @param string $type The type of resource
24+
* @param string $resource The resource that could not be imported
25+
* @param string|null $sourceResource The original resource importing the new resource
26+
* @param int|null $code The error code
27+
* @param \Throwable|null $previous A previous exception
28+
* @param string|null $type The type of resource
2929
*/
30-
public function __construct(string $resource, string $sourceResource = null, int $code = null, \Throwable $previous = null, string $type = null)
30+
public function __construct(string $resource, string $sourceResource = null, ?int $code = 0, \Throwable $previous = null, string $type = null)
3131
{
3232
$message = '';
3333
if ($previous) {

src/Symfony/Component/Config/Loader/DelegatingLoader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(LoaderResolverInterface $resolver)
3434
public function load($resource, $type = null)
3535
{
3636
if (false === $loader = $this->resolver->resolve($resource, $type)) {
37-
throw new LoaderLoadException($resource, null, null, null, $type);
37+
throw new LoaderLoadException($resource, null, 0, null, $type);
3838
}
3939

4040
return $loader->load($resource, $type);

src/Symfony/Component/Config/Loader/FileLoader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private function doImport($resource, string $type = null, bool $ignoreErrors = f
177177
throw $e;
178178
}
179179

180-
throw new LoaderLoadException($resource, $sourceResource, null, $e, $type);
180+
throw new LoaderLoadException($resource, $sourceResource, 0, $e, $type);
181181
}
182182
}
183183

src/Symfony/Component/Config/Loader/Loader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function resolve($resource, $type = null)
7070
$loader = null === $this->resolver ? false : $this->resolver->resolve($resource, $type);
7171

7272
if (false === $loader) {
73-
throw new LoaderLoadException($resource, null, null, null, $type);
73+
throw new LoaderLoadException($resource, null, 0, null, $type);
7474
}
7575

7676
return $loader;

src/Symfony/Component/Config/Tests/Exception/LoaderLoadExceptionTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public function testMessageCannotLoadResource()
2424

2525
public function testMessageCannotLoadResourceWithType()
2626
{
27-
$exception = new LoaderLoadException('resource', null, null, null, 'foobar');
27+
$exception = new LoaderLoadException('resource', null, 0, null, 'foobar');
2828
$this->assertEquals('Cannot load resource "resource". Make sure there is a loader supporting the "foobar" type.', $exception->getMessage());
2929
}
3030

3131
public function testMessageCannotLoadResourceWithAnnotationType()
3232
{
33-
$exception = new LoaderLoadException('resource', null, null, null, 'annotation');
33+
$exception = new LoaderLoadException('resource', null, 0, null, 'annotation');
3434
$this->assertEquals('Cannot load resource "resource". Make sure annotations are installed and enabled.', $exception->getMessage());
3535
}
3636

@@ -56,7 +56,7 @@ public function testMessageHasPreviousErrorWithDotAndUnableToLoad()
5656
$exception = new LoaderLoadException(
5757
'resource',
5858
null,
59-
null,
59+
0,
6060
new \Exception('There was a previous error with an ending dot.')
6161
);
6262
$this->assertEquals(
@@ -70,7 +70,7 @@ public function testMessageHasPreviousErrorWithoutDotAndUnableToLoad()
7070
$exception = new LoaderLoadException(
7171
'resource',
7272
null,
73-
null,
73+
0,
7474
new \Exception('There was a previous error with no ending dot')
7575
);
7676
$this->assertEquals(
@@ -84,7 +84,7 @@ public function testMessageHasPreviousErrorAndUnableToLoadBundle()
8484
$exception = new LoaderLoadException(
8585
'@resource',
8686
null,
87-
null,
87+
0,
8888
new \Exception('There was a previous error with an ending dot.')
8989
);
9090
$this->assertEquals(

src/Symfony/Component/Console/Exception/CommandNotFoundException.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class CommandNotFoundException extends \InvalidArgumentException implements Exce
2121
private $alternatives;
2222

2323
/**
24-
* @param string $message Exception message to throw
25-
* @param array $alternatives List of similar defined names
26-
* @param int $code Exception code
27-
* @param \Throwable $previous Previous exception used for the exception chaining
24+
* @param string $message Exception message to throw
25+
* @param string[] $alternatives List of similar defined names
26+
* @param int $code Exception code
27+
* @param \Throwable|null $previous Previous exception used for the exception chaining
2828
*/
2929
public function __construct(string $message, array $alternatives = [], int $code = 0, \Throwable $previous = null)
3030
{
@@ -34,7 +34,7 @@ public function __construct(string $message, array $alternatives = [], int $code
3434
}
3535

3636
/**
37-
* @return array A list of similar defined names
37+
* @return string[] A list of similar defined names
3838
*/
3939
public function getAlternatives()
4040
{

src/Symfony/Component/HttpKernel/Exception/AccessDeniedHttpException.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
class AccessDeniedHttpException extends HttpException
1919
{
2020
/**
21-
* @param string $message The internal exception message
22-
* @param \Throwable $previous The previous exception
23-
* @param int $code The internal exception code
21+
* @param string|null $message The internal exception message
22+
* @param \Throwable|null $previous The previous exception
23+
* @param int $code The internal exception code
2424
*/
25-
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
25+
public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = [])
2626
{
2727
parent::__construct(403, $message, $previous, $headers, $code);
2828
}

src/Symfony/Component/HttpKernel/Exception/BadRequestHttpException.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
class BadRequestHttpException extends HttpException
1818
{
1919
/**
20-
* @param string $message The internal exception message
21-
* @param \Throwable $previous The previous exception
22-
* @param int $code The internal exception code
20+
* @param string|null $message The internal exception message
21+
* @param \Throwable|null $previous The previous exception
22+
* @param int $code The internal exception code
2323
*/
24-
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
24+
public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = [])
2525
{
2626
parent::__construct(400, $message, $previous, $headers, $code);
2727
}

src/Symfony/Component/HttpKernel/Exception/ConflictHttpException.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
class ConflictHttpException extends HttpException
1818
{
1919
/**
20-
* @param string $message The internal exception message
21-
* @param \Throwable $previous The previous exception
22-
* @param int $code The internal exception code
20+
* @param string|null $message The internal exception message
21+
* @param \Throwable|null $previous The previous exception
22+
* @param int $code The internal exception code
2323
*/
24-
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
24+
public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = [])
2525
{
2626
parent::__construct(409, $message, $previous, $headers, $code);
2727
}

src/Symfony/Component/HttpKernel/Exception/GoneHttpException.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
class GoneHttpException extends HttpException
1818
{
1919
/**
20-
* @param string $message The internal exception message
21-
* @param \Throwable $previous The previous exception
22-
* @param int $code The internal exception code
20+
* @param string|null $message The internal exception message
21+
* @param \Throwable|null $previous The previous exception
22+
* @param int $code The internal exception code
2323
*/
24-
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
24+
public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = [])
2525
{
2626
parent::__construct(410, $message, $previous, $headers, $code);
2727
}

src/Symfony/Component/HttpKernel/Exception/HttpException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class HttpException extends \RuntimeException implements HttpExceptionInterface
2121
private $statusCode;
2222
private $headers;
2323

24-
public function __construct(int $statusCode, string $message = null, \Throwable $previous = null, array $headers = [], ?int $code = 0)
24+
public function __construct(int $statusCode, ?string $message = '', \Throwable $previous = null, array $headers = [], ?int $code = 0)
2525
{
2626
$this->statusCode = $statusCode;
2727
$this->headers = $headers;

src/Symfony/Component/HttpKernel/Exception/LengthRequiredHttpException.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
class LengthRequiredHttpException extends HttpException
1818
{
1919
/**
20-
* @param string $message The internal exception message
21-
* @param \Throwable $previous The previous exception
22-
* @param int $code The internal exception code
20+
* @param string|null $message The internal exception message
21+
* @param \Throwable|null $previous The previous exception
22+
* @param int $code The internal exception code
2323
*/
24-
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
24+
public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = [])
2525
{
2626
parent::__construct(411, $message, $previous, $headers, $code);
2727
}

src/Symfony/Component/HttpKernel/Exception/MethodNotAllowedHttpException.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
class MethodNotAllowedHttpException extends HttpException
1818
{
1919
/**
20-
* @param array $allow An array of allowed methods
21-
* @param string $message The internal exception message
22-
* @param \Throwable $previous The previous exception
23-
* @param int $code The internal exception code
20+
* @param string[] $allow An array of allowed methods
21+
* @param string|null $message The internal exception message
22+
* @param \Throwable|null $previous The previous exception
23+
* @param int|null $code The internal exception code
2424
*/
25-
public function __construct(array $allow, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
25+
public function __construct(array $allow, ?string $message = '', \Throwable $previous = null, ?int $code = 0, array $headers = [])
2626
{
2727
$headers['Allow'] = strtoupper(implode(', ', $allow));
2828

src/Symfony/Component/HttpKernel/Exception/NotAcceptableHttpException.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
class NotAcceptableHttpException extends HttpException
1818
{
1919
/**
20-
* @param string $message The internal exception message
21-
* @param \Throwable $previous The previous exception
22-
* @param int $code The internal exception code
20+
* @param string|null $message The internal exception message
21+
* @param \Throwable|null $previous The previous exception
22+
* @param int $code The internal exception code
2323
*/
24-
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
24+
public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = [])
2525
{
2626
parent::__construct(406, $message, $previous, $headers, $code);
2727
}

src/Symfony/Component/HttpKernel/Exception/NotFoundHttpException.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
class NotFoundHttpException extends HttpException
1818
{
1919
/**
20-
* @param string $message The internal exception message
21-
* @param \Throwable $previous The previous exception
22-
* @param int $code The internal exception code
20+
* @param string|null $message The internal exception message
21+
* @param \Throwable|null $previous The previous exception
22+
* @param int $code The internal exception code
2323
*/
24-
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
24+
public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = [])
2525
{
2626
parent::__construct(404, $message, $previous, $headers, $code);
2727
}

src/Symfony/Component/HttpKernel/Exception/PreconditionFailedHttpException.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
class PreconditionFailedHttpException extends HttpException
1818
{
1919
/**
20-
* @param string $message The internal exception message
21-
* @param \Throwable $previous The previous exception
22-
* @param int $code The internal exception code
20+
* @param string|null $message The internal exception message
21+
* @param \Throwable|null $previous The previous exception
22+
* @param int $code The internal exception code
2323
*/
24-
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
24+
public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = [])
2525
{
2626
parent::__construct(412, $message, $previous, $headers, $code);
2727
}

src/Symfony/Component/HttpKernel/Exception/PreconditionRequiredHttpException.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
class PreconditionRequiredHttpException extends HttpException
2020
{
2121
/**
22-
* @param string $message The internal exception message
23-
* @param \Throwable $previous The previous exception
24-
* @param int $code The internal exception code
22+
* @param string|null $message The internal exception message
23+
* @param \Throwable|null $previous The previous exception
24+
* @param int $code The internal exception code
2525
*/
26-
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
26+
public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = [])
2727
{
2828
parent::__construct(428, $message, $previous, $headers, $code);
2929
}

src/Symfony/Component/HttpKernel/Exception/ServiceUnavailableHttpException.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
class ServiceUnavailableHttpException extends HttpException
1818
{
1919
/**
20-
* @param int|string $retryAfter The number of seconds or HTTP-date after which the request may be retried
21-
* @param string $message The internal exception message
22-
* @param \Throwable $previous The previous exception
23-
* @param int $code The internal exception code
20+
* @param int|string|null $retryAfter The number of seconds or HTTP-date after which the request may be retried
21+
* @param string|null $message The internal exception message
22+
* @param \Throwable|null $previous The previous exception
23+
* @param int|null $code The internal exception code
2424
*/
25-
public function __construct($retryAfter = null, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
25+
public function __construct($retryAfter = null, ?string $message = '', \Throwable $previous = null, ?int $code = 0, array $headers = [])
2626
{
2727
if ($retryAfter) {
2828
$headers['Retry-After'] = $retryAfter;

src/Symfony/Component/HttpKernel/Exception/TooManyRequestsHttpException.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
class TooManyRequestsHttpException extends HttpException
2020
{
2121
/**
22-
* @param int|string $retryAfter The number of seconds or HTTP-date after which the request may be retried
23-
* @param string $message The internal exception message
24-
* @param \Throwable $previous The previous exception
25-
* @param int $code The internal exception code
22+
* @param int|string|null $retryAfter The number of seconds or HTTP-date after which the request may be retried
23+
* @param string|null $message The internal exception message
24+
* @param \Throwable|null $previous The previous exception
25+
* @param int|null $code The internal exception code
2626
*/
27-
public function __construct($retryAfter = null, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
27+
public function __construct($retryAfter = null, ?string $message = '', \Throwable $previous = null, ?int $code = 0, array $headers = [])
2828
{
2929
if ($retryAfter) {
3030
$headers['Retry-After'] = $retryAfter;

src/Symfony/Component/HttpKernel/Exception/UnauthorizedHttpException.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
class UnauthorizedHttpException extends HttpException
1818
{
1919
/**
20-
* @param string $challenge WWW-Authenticate challenge string
21-
* @param string $message The internal exception message
22-
* @param \Throwable $previous The previous exception
23-
* @param int $code The internal exception code
20+
* @param string $challenge WWW-Authenticate challenge string
21+
* @param string|null $message The internal exception message
22+
* @param \Throwable|null $previous The previous exception
23+
* @param int|null $code The internal exception code
2424
*/
25-
public function __construct(string $challenge, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
25+
public function __construct(string $challenge, ?string $message = '', \Throwable $previous = null, ?int $code = 0, array $headers = [])
2626
{
2727
$headers['WWW-Authenticate'] = $challenge;
2828

src/Symfony/Component/HttpKernel/Exception/UnprocessableEntityHttpException.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
class UnprocessableEntityHttpException extends HttpException
1818
{
1919
/**
20-
* @param string $message The internal exception message
21-
* @param \Throwable $previous The previous exception
22-
* @param int $code The internal exception code
20+
* @param string|null $message The internal exception message
21+
* @param \Throwable|null $previous The previous exception
22+
* @param int $code The internal exception code
2323
*/
24-
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
24+
public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = [])
2525
{
2626
parent::__construct(422, $message, $previous, $headers, $code);
2727
}

src/Symfony/Component/HttpKernel/Exception/UnsupportedMediaTypeHttpException.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
class UnsupportedMediaTypeHttpException extends HttpException
1818
{
1919
/**
20-
* @param string $message The internal exception message
21-
* @param \Throwable $previous The previous exception
22-
* @param int $code The internal exception code
20+
* @param string|null $message The internal exception message
21+
* @param \Throwable|null $previous The previous exception
22+
* @param int $code The internal exception code
2323
*/
24-
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
24+
public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = [])
2525
{
2626
parent::__construct(415, $message, $previous, $headers, $code);
2727
}

0 commit comments

Comments
 (0)