Simplify loops over array_keys

Use native PHP feature of iterating over key-value pairs
instead of looking up the value if it's used.

Change-Id: Id55f774b3a9d97463b97581c5b2ffe081489863a
This commit is contained in:
Matěj Suchánek 2021-08-11 10:31:30 +02:00 committed by Thiemo Kreuz (WMDE)
parent cde4080b22
commit 5267cc09ea
2 changed files with 10 additions and 12 deletions

View file

@ -316,26 +316,24 @@ class Exif {
private function makeFilteredData() { private function makeFilteredData() {
$this->mFilteredExifData = []; $this->mFilteredExifData = [];
foreach ( array_keys( $this->mRawExifData ) as $section ) { foreach ( $this->mRawExifData as $section => $data ) {
if ( !array_key_exists( $section, $this->mExifTags ) ) { if ( !array_key_exists( $section, $this->mExifTags ) ) {
$this->debug( $section, __FUNCTION__, "'$section' is not a valid Exif section" ); $this->debug( $section, __FUNCTION__, "'$section' is not a valid Exif section" );
continue; continue;
} }
foreach ( array_keys( $this->mRawExifData[$section] ) as $tag ) { foreach ( $data as $tag => $value ) {
if ( !array_key_exists( $tag, $this->mExifTags[$section] ) ) { if ( !array_key_exists( $tag, $this->mExifTags[$section] ) ) {
$this->debug( $tag, __FUNCTION__, "'$tag' is not a valid tag in '$section'" ); $this->debug( $tag, __FUNCTION__, "'$tag' is not a valid tag in '$section'" );
continue; continue;
} }
$this->mFilteredExifData[$tag] = $this->mRawExifData[$section][$tag]; if ( $this->validate( $section, $tag, $value ) ) {
// This is ok, as the tags in the different sections do not conflict. // This is ok, as the tags in the different sections do not conflict.
// except in computed and thumbnail section, which we don't use. // except in computed and thumbnail section, which we don't use.
$this->mFilteredExifData[$tag] = $value;
$value = $this->mRawExifData[$section][$tag]; } else {
if ( !$this->validate( $section, $tag, $value ) ) {
$this->debug( $value, __FUNCTION__, "'$tag' contained invalid data" ); $this->debug( $value, __FUNCTION__, "'$tag' contained invalid data" );
unset( $this->mFilteredExifData[$tag] );
} }
} }
} }

View file

@ -71,16 +71,16 @@ abstract class AlphabeticPager extends IndexPager {
$extra = ''; $extra = '';
$msgs = $this->getOrderTypeMessages(); $msgs = $this->getOrderTypeMessages();
foreach ( array_keys( $msgs ) as $order ) { foreach ( $msgs as $order => $msg ) {
if ( $extra !== '' ) { if ( $extra !== '' ) {
$extra .= $this->msg( 'pipe-separator' )->escaped(); $extra .= $this->msg( 'pipe-separator' )->escaped();
} }
if ( $order == $this->mOrderType ) { if ( $order == $this->mOrderType ) {
$extra .= $this->msg( $msgs[$order] )->escaped(); $extra .= $this->msg( $msg )->escaped();
} else { } else {
$extra .= $this->makeLink( $extra .= $this->makeLink(
$this->msg( $msgs[$order] )->escaped(), $this->msg( $msg )->escaped(),
[ 'order' => $order ] [ 'order' => $order ]
); );
} }