Reduce nesting by turning big if-else into guard clauses

Change-Id: If3d2f18af0cc7d0f8fe9f764bd4d0e4bae70e440
This commit is contained in:
Thiemo Kreuz 2019-11-08 17:19:13 +01:00
parent b777cc6b46
commit 9c6473dc1d
3 changed files with 35 additions and 39 deletions

View file

@ -386,7 +386,10 @@ class JobQueueDB extends JobQueue {
}
}
if ( $row ) { // claim the job
if ( !$row ) {
break;
}
$dbw->update( 'job', // update by PK
[
'job_token' => $uuid,
@ -400,9 +403,6 @@ class JobQueueDB extends JobQueue {
if ( !$dbw->affectedRows() ) {
$row = false; // raced out
}
} else {
break; // nothing to do
}
} while ( !$row );
return $row;
@ -455,17 +455,18 @@ class JobQueueDB extends JobQueue {
__METHOD__
);
}
if ( !$dbw->affectedRows() ) {
break;
}
// Fetch any row that we just reserved...
if ( $dbw->affectedRows() ) {
$row = $dbw->selectRow( 'job', self::selectFields(),
[ 'job_cmd' => $this->type, 'job_token' => $uuid ], __METHOD__
);
if ( !$row ) { // raced out by duplicate job removal
wfDebug( "Row deleted as duplicate by another process." );
}
} else {
break; // nothing to do
}
} while ( !$row );
return $row;

View file

@ -207,19 +207,14 @@ class SwiftFileBackend extends FileBackendStore {
$contentHeaders[$name] = $value;
}
// By default, Swift has annoyingly low maximum header value limits
if ( isset( $contentHeaders['content-disposition'] ) ) {
$disposition = '';
$maxLength = 255;
// @note: assume FileBackend::makeContentDisposition() already used
foreach ( explode( ';', $contentHeaders['content-disposition'] ) as $part ) {
$part = trim( $part );
$new = ( $disposition === '' ) ? $part : "{$disposition};{$part}";
if ( strlen( $new ) <= 255 ) {
$disposition = $new;
} else {
break; // too long; sigh
}
}
$contentHeaders['content-disposition'] = $disposition;
$offset = $maxLength - strlen( $contentHeaders['content-disposition'] );
if ( $offset < 0 ) {
$pos = strrpos( $contentHeaders['content-disposition'], ';', $offset );
$contentHeaders['content-disposition'] = $pos === false
? ''
: trim( substr( $contentHeaders['content-disposition'], 0, $pos ) );
}
return $contentHeaders;