Merge pull request #18488 from kamil-tekiela/Add-never-type

Add never return type
This commit is contained in:
Maurício Meneghini Fauth 2023-06-09 16:13:33 -03:00 committed by GitHub
commit a52667ee28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 104 additions and 68 deletions

View File

@ -36,8 +36,6 @@ final class ShowConfigController
$GLOBALS['ConfigFile']->resetConfigData();
// drop post data
$response->generateHeader303('../setup/index.php' . Url::getCommonRaw(['route' => '/setup']));
return;
}
/** @var mixed $submitDownload */

View File

@ -28,20 +28,18 @@ class AuthenticationConfig extends AuthenticationPlugin
{
/**
* Displays authentication form
*
* @return bool always true
*/
public function showLoginForm(): bool
public function showLoginForm(): void
{
$response = ResponseRenderer::getInstance();
if ($response->isAjax()) {
$response->setRequestStatus(false);
// reload_flag removes the token parameter from the URL and reloads
$response->addJSON('reload_flag', '1');
$response->callExit();
if (! $response->isAjax()) {
return;
}
return true;
$response->setRequestStatus(false);
// reload_flag removes the token parameter from the URL and reloads
$response->addJSON('reload_flag', '1');
$response->callExit();
}
/**
@ -66,7 +64,7 @@ class AuthenticationConfig extends AuthenticationPlugin
*
* @param string $failure String describing why authentication has failed
*/
public function showFailure(string $failure): void
public function showFailure(string $failure): never
{
parent::showFailure($failure);

View File

@ -63,7 +63,7 @@ class AuthenticationCookie extends AuthenticationPlugin
*
* @global string $conn_error the last connection error
*/
public function showLoginForm(): bool
public function showLoginForm(): never
{
$GLOBALS['conn_error'] ??= null;
@ -379,7 +379,6 @@ class AuthenticationCookie extends AuthenticationPlugin
SessionCache::remove('proc_priv');
$this->showFailure('no-activity');
ResponseRenderer::getInstance()->callExit();
}
// check password cookie
@ -552,12 +551,9 @@ class AuthenticationCookie extends AuthenticationPlugin
* prepares error message and switches to showLoginForm() which display the error
* and the login form
*
* this function MUST exit/quit the application,
* currently done by call to showLoginForm()
*
* @param string $failure String describing why authentication has failed
*/
public function showFailure(string $failure): void
public function showFailure(string $failure): never
{
$GLOBALS['conn_error'] ??= null;

View File

@ -30,10 +30,8 @@ class AuthenticationHttp extends AuthenticationPlugin
{
/**
* Displays authentication form and redirect as necessary
*
* @return bool always true (no return indeed)
*/
public function showLoginForm(): bool
public function showLoginForm(): never
{
$response = ResponseRenderer::getInstance();
if ($response->isAjax()) {
@ -43,13 +41,13 @@ class AuthenticationHttp extends AuthenticationPlugin
$response->callExit();
}
return $this->authForm();
$this->authForm();
}
/**
* Displays authentication form
*/
public function authForm(): bool
public function authForm(): never
{
if (empty($GLOBALS['cfg']['Server']['auth_http_realm'])) {
if (empty($GLOBALS['cfg']['Server']['verbose'])) {
@ -179,7 +177,7 @@ class AuthenticationHttp extends AuthenticationPlugin
*
* @param string $failure String describing why authentication has failed
*/
public function showFailure(string $failure): void
public function showFailure(string $failure): never
{
parent::showFailure($failure);

View File

@ -32,7 +32,7 @@ class AuthenticationSignon extends AuthenticationPlugin
/**
* Displays authentication form
*/
public function showLoginForm(): bool
public function showLoginForm(): never
{
$response = ResponseRenderer::getInstance();
$response->disable();
@ -244,7 +244,7 @@ class AuthenticationSignon extends AuthenticationPlugin
*
* @param string $failure String describing why authentication has failed
*/
public function showFailure(string $failure): void
public function showFailure(string $failure): never
{
parent::showFailure($failure);

View File

@ -61,7 +61,7 @@ abstract class AuthenticationPlugin
/**
* Displays authentication form
*/
abstract public function showLoginForm(): bool;
abstract public function showLoginForm(): void;
/**
* Gets authentication credentials

View File

@ -439,7 +439,7 @@ class ResponseRenderer
*
* @param string $location will set location to redirect.
*/
public function generateHeader303(string $location): void
public function generateHeader303(string $location): never
{
$this->setHttpResponseCode(303);
$this->header('Location: ' . $location);

View File

@ -48,8 +48,6 @@ class FormProcessing
$response = ResponseRenderer::getInstance();
$response->disable();
$response->generateHeader303('../setup/index.php' . Url::getCommonRaw(['route' => '/setup']));
return;
}
// form has errors, show warning

View File

@ -8177,9 +8177,6 @@
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['allowDeny_forbidden']]]></code>
</InvalidArrayOffset>
<PossiblyUnusedReturnValue>
<code>bool</code>
</PossiblyUnusedReturnValue>
</file>
<file src="libraries/classes/Plugins/Auth/AuthenticationCookie.php">
<DocblockTypeContradiction>
@ -8243,7 +8240,6 @@
</PossiblyNullReference>
<PossiblyUnusedReturnValue>
<code>bool</code>
<code>bool</code>
</PossiblyUnusedReturnValue>
<RedundantCast>
<code><![CDATA[(int) $GLOBALS['cfg']['LoginCookieStore']]]></code>
@ -8271,9 +8267,6 @@
<PossiblyInvalidCast>
<code>$oldUser</code>
</PossiblyInvalidCast>
<PossiblyUnusedReturnValue>
<code>bool</code>
</PossiblyUnusedReturnValue>
</file>
<file src="libraries/classes/Plugins/Auth/AuthenticationSignon.php">
<MixedArgument>
@ -8297,9 +8290,6 @@
<code><![CDATA[$this->password]]></code>
<code><![CDATA[$this->user]]></code>
</MixedAssignment>
<PossiblyUnusedReturnValue>
<code>bool</code>
</PossiblyUnusedReturnValue>
<RedundantCast>
<code><![CDATA[(array) $GLOBALS['cfg']['Server']['SignonCookieParams']]]></code>
</RedundantCast>
@ -8326,9 +8316,6 @@
<PossiblyNullReference>
<code>issetCookie</code>
</PossiblyNullReference>
<PossiblyUnusedReturnValue>
<code>bool</code>
</PossiblyUnusedReturnValue>
</file>
<file src="libraries/classes/Plugins/AuthenticationPluginFactory.php">
<RedundantFunctionCall>

View File

@ -94,7 +94,7 @@ class AuthenticationConfigTest extends AbstractTestCase
$html = ob_get_clean();
$this->assertInstanceOf(ExitException::class, $throwable ?? null);
$this->assertInstanceOf(ExitException::class, $throwable);
$this->assertIsString($html);

View File

@ -73,7 +73,7 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
}
#[Group('medium')]
public function testAuthErrorAJAX(): void
public function testAuthErrorAJAX(): never
{
$mockResponse = $this->mockResponse();
@ -191,7 +191,7 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
$result = ob_get_clean();
$this->assertInstanceOf(ExitException::class, $throwable ?? null);
$this->assertInstanceOf(ExitException::class, $throwable);
$this->assertIsString($result);
@ -276,7 +276,7 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
$result = ob_get_clean();
$this->assertInstanceOf(ExitException::class, $throwable ?? null);
$this->assertInstanceOf(ExitException::class, $throwable);
$this->assertIsString($result);
@ -355,7 +355,7 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
$result = ob_get_clean();
$this->assertInstanceOf(ExitException::class, $throwable ?? null);
$this->assertInstanceOf(ExitException::class, $throwable);
$this->assertIsString($result);
@ -643,7 +643,8 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
->will($this->returnValue('testBF'));
$this->object->expects($this->once())
->method('showFailure');
->method('showFailure')
->willThrowException(new ExitException());
$this->expectException(ExitException::class);
$this->object->readCredentials();
@ -711,6 +712,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
->onlyMethods(['showLoginForm'])
->getMock();
$this->object->expects($this->exactly(1))
->method('showLoginForm')
->willThrowException(new ExitException());
$GLOBALS['server'] = 2;
$_COOKIE['pmaAuth-2'] = 'pass';
@ -718,7 +723,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
['Cache-Control: no-store, no-cache, must-revalidate'],
['Pragma: no-cache'],
);
$this->object->showFailure('empty-denied');
try {
$this->object->showFailure('empty-denied');
} catch (ExitException) {
}
$this->assertEquals(
$GLOBALS['conn_error'],
@ -773,6 +781,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
->onlyMethods(['showLoginForm'])
->getMock();
$this->object->expects($this->exactly(1))
->method('showLoginForm')
->willThrowException(new ExitException());
$GLOBALS['server'] = 2;
$_COOKIE['pmaAuth-2'] = 'pass';
@ -780,7 +792,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
['Cache-Control: no-store, no-cache, must-revalidate'],
['Pragma: no-cache'],
);
$this->object->showFailure('allow-denied');
try {
$this->object->showFailure('allow-denied');
} catch (ExitException) {
}
$this->assertEquals($GLOBALS['conn_error'], 'Access denied!');
}
@ -792,6 +807,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
->onlyMethods(['showLoginForm'])
->getMock();
$this->object->expects($this->exactly(1))
->method('showLoginForm')
->willThrowException(new ExitException());
$GLOBALS['server'] = 2;
$_COOKIE['pmaAuth-2'] = 'pass';
@ -802,7 +821,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
['Cache-Control: no-store, no-cache, must-revalidate'],
['Pragma: no-cache'],
);
$this->object->showFailure('no-activity');
try {
$this->object->showFailure('no-activity');
} catch (ExitException) {
}
$this->assertEquals(
$GLOBALS['conn_error'],
@ -818,6 +840,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
->onlyMethods(['showLoginForm'])
->getMock();
$this->object->expects($this->exactly(1))
->method('showLoginForm')
->willThrowException(new ExitException());
$GLOBALS['server'] = 2;
$_COOKIE['pmaAuth-2'] = 'pass';
@ -836,7 +862,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
['Cache-Control: no-store, no-cache, must-revalidate'],
['Pragma: no-cache'],
);
$this->object->showFailure('');
try {
$this->object->showFailure('');
} catch (ExitException) {
}
$this->assertEquals($GLOBALS['conn_error'], '#42 Cannot log in to the MySQL server');
}
@ -848,6 +877,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
->onlyMethods(['showLoginForm'])
->getMock();
$this->object->expects($this->exactly(1))
->method('showLoginForm')
->willThrowException(new ExitException());
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
@ -866,7 +899,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase
['Cache-Control: no-store, no-cache, must-revalidate'],
['Pragma: no-cache'],
);
$this->object->showFailure('');
try {
$this->object->showFailure('');
} catch (ExitException) {
}
$this->assertEquals($GLOBALS['conn_error'], 'Cannot log in to the MySQL server');
}

View File

@ -314,7 +314,7 @@ class AuthenticationHttpTest extends AbstractNetworkTestCase
$result = ob_get_clean();
$this->assertInstanceOf(ExitException::class, $throwable ?? null);
$this->assertInstanceOf(ExitException::class, $throwable);
$this->assertIsString($result);
@ -326,15 +326,20 @@ class AuthenticationHttpTest extends AbstractNetworkTestCase
->getMock();
$this->object->expects($this->exactly(2))
->method('authForm');
->method('authForm')
->willThrowException(new ExitException());
// case 2
$GLOBALS['cfg']['Server']['host'] = 'host';
$GLOBALS['errno'] = 1045;
$this->object->showFailure('');
try {
$this->object->showFailure('');
} catch (ExitException) {
}
// case 3
$GLOBALS['errno'] = 1043;
$this->expectException(ExitException::class);
$this->object->showFailure('');
}
}

View File

@ -67,7 +67,7 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase
$result = ob_get_clean();
$this->assertInstanceOf(ExitException::class, $throwable ?? null);
$this->assertInstanceOf(ExitException::class, $throwable);
$this->assertIsString($result);
@ -229,9 +229,13 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase
->getMock();
$this->object->expects($this->exactly(1))
->method('showLoginForm');
->method('showLoginForm')
->willThrowException(new ExitException());
$this->object->showFailure('empty-denied');
try {
$this->object->showFailure('empty-denied');
} catch (ExitException) {
}
$this->assertEquals(
'Login without a password is forbidden by configuration (see AllowNoPassword)',
@ -250,9 +254,13 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase
->getMock();
$this->object->expects($this->exactly(1))
->method('showLoginForm');
->method('showLoginForm')
->willThrowException(new ExitException());
$this->object->showFailure('allow-denied');
try {
$this->object->showFailure('allow-denied');
} catch (ExitException) {
}
$this->assertEquals('Access denied!', $_SESSION['PMA_single_signon_error_message']);
}
@ -268,11 +276,15 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase
->getMock();
$this->object->expects($this->exactly(1))
->method('showLoginForm');
->method('showLoginForm')
->willThrowException(new ExitException());
$GLOBALS['cfg']['LoginCookieValidity'] = '1440';
$this->object->showFailure('no-activity');
try {
$this->object->showFailure('no-activity');
} catch (ExitException) {
}
$this->assertEquals(
'You have been automatically logged out due to inactivity of'
@ -293,7 +305,8 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase
->getMock();
$this->object->expects($this->exactly(1))
->method('showLoginForm');
->method('showLoginForm')
->willThrowException(new ExitException());
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
@ -305,7 +318,10 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase
$GLOBALS['dbi'] = $dbi;
$this->object->showFailure('');
try {
$this->object->showFailure('');
} catch (ExitException) {
}
$this->assertEquals('error&lt;123&gt;', $_SESSION['PMA_single_signon_error_message']);
}
@ -322,7 +338,8 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase
->getMock();
$this->object->expects($this->exactly(1))
->method('showLoginForm');
->method('showLoginForm')
->willThrowException(new ExitException());
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
@ -334,7 +351,10 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase
$GLOBALS['dbi'] = $dbi;
$this->object->showFailure('');
try {
$this->object->showFailure('');
} catch (ExitException) {
}
$this->assertEquals('Cannot log in to the MySQL server', $_SESSION['PMA_single_signon_error_message']);
}