Unverified Commit 7c3b2861 authored by alexpott's avatar alexpott
Browse files

Issue #3209619 by longwave, daffie, catch: [Symfony 6] Passing null as...

Issue #3209619 by longwave, daffie, catch: [Symfony 6] Passing null as $message to Symfony exception constructors is deprecated, pass an empty string instead
parent ea56478e
......@@ -304,10 +304,10 @@ public function orIf(AccessResultInterface $other) {
$merge_other = TRUE;
}
if ($this->isForbidden() && $this instanceof AccessResultReasonInterface && !is_null($this->getReason())) {
if ($this->isForbidden() && $this instanceof AccessResultReasonInterface && $this->getReason() !== '') {
$result->setReason($this->getReason());
}
elseif ($other->isForbidden() && $other instanceof AccessResultReasonInterface && !is_null($other->getReason())) {
elseif ($other->isForbidden() && $other instanceof AccessResultReasonInterface && $other->getReason() !== '') {
$result->setReason($other->getReason());
}
}
......@@ -323,10 +323,10 @@ public function orIf(AccessResultInterface $other) {
$merge_other = TRUE;
}
if ($this instanceof AccessResultReasonInterface && !is_null($this->getReason())) {
if ($this instanceof AccessResultReasonInterface && $this->getReason() !== '') {
$result->setReason($this->getReason());
}
elseif ($other instanceof AccessResultReasonInterface && !is_null($other->getReason())) {
elseif ($other instanceof AccessResultReasonInterface && $other->getReason() !== '') {
$result->setReason($other->getReason());
}
}
......
......@@ -10,7 +10,7 @@ class AccessResultForbidden extends AccessResult implements AccessResultReasonIn
/**
* The reason why access is forbidden. For use in error messages.
*
* @var string|null
* @var string
*/
protected $reason;
......@@ -35,7 +35,7 @@ public function isForbidden() {
* {@inheritdoc}
*/
public function getReason() {
return $this->reason;
return (string) $this->reason;
}
/**
......
......@@ -10,7 +10,7 @@ class AccessResultNeutral extends AccessResult implements AccessResultReasonInte
/**
* The reason why access is neutral. For use in messages.
*
* @var string|null
* @var string
*/
protected $reason;
......@@ -35,7 +35,7 @@ public function isNeutral() {
* {@inheritdoc}
*/
public function getReason() {
return $this->reason;
return (string) $this->reason;
}
/**
......
......@@ -17,8 +17,9 @@ interface AccessResultReasonInterface extends AccessResultInterface {
/**
* Gets the reason for this access result.
*
* @return string|null
* The reason of this access result or NULL if no reason is provided.
* @return string
* The reason of this access result or an empty string if no reason is
* provided.
*/
public function getReason();
......
......@@ -28,7 +28,7 @@ class BrokenPostRequestException extends BadRequestHttpException {
* @param int $code
* The internal exception code.
*/
public function __construct($max_upload_size, $message = NULL, \Exception $previous = NULL, $code = 0) {
public function __construct($max_upload_size, $message = '', \Exception $previous = NULL, $code = 0) {
parent::__construct($message, $previous, $code);
$this->size = $max_upload_size;
......
......@@ -114,10 +114,10 @@ protected function checkAccess(Request $request) {
}
if (!$access_result->isAllowed()) {
if ($access_result instanceof CacheableDependencyInterface && $request->isMethodCacheable()) {
throw new CacheableAccessDeniedHttpException($access_result, $access_result instanceof AccessResultReasonInterface ? $access_result->getReason() : NULL);
throw new CacheableAccessDeniedHttpException($access_result, $access_result instanceof AccessResultReasonInterface ? $access_result->getReason() : '');
}
else {
throw new AccessDeniedHttpException($access_result instanceof AccessResultReasonInterface ? $access_result->getReason() : NULL);
throw new AccessDeniedHttpException($access_result instanceof AccessResultReasonInterface ? $access_result->getReason() : '');
}
}
}
......
......@@ -19,7 +19,7 @@ class AccessResultNeutralTest extends UnitTestCase {
*/
public function testConstruction() {
$a = new AccessResultNeutral();
$this->assertNull($a->getReason());
$this->assertEquals('', $a->getReason());
$reason = $this->getRandomGenerator()->string();
$b = new AccessResultNeutral($reason);
......
......@@ -123,7 +123,7 @@ public function testAccessForbiddenReason() {
};
$b = AccessResult::forbidden();
$verify($b, NULL);
$verify($b, '');
$reason = $this->getRandomGenerator()->string();
$b = AccessResult::forbidden($reason);
......@@ -319,7 +319,7 @@ public function testOrIf() {
$access = $neutral_reasonless->orIf($neutral);
$this->assertEquals('neutral message', $access->getReason());
$access = $neutral_reasonless->orIf($neutral_reasonless);
$this->assertNull($access->getReason());
$this->assertEquals('', $access->getReason());
// NEUTRAL || ALLOWED === ALLOWED.
$access = $neutral->orIf($allowed);
......@@ -370,7 +370,7 @@ public function testOrIf() {
$access = $forbidden_reasonless->orIf($forbidden);
$this->assertEquals('forbidden message', $access->getReason());
$access = $forbidden_reasonless->orIf($forbidden_reasonless);
$this->assertNull($access->getReason());
$this->assertEquals('', $access->getReason());
// FORBIDDEN || * === FORBIDDEN.
$access = $forbidden->orIf($unused_access_result_due_to_lazy_evaluation);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment