Skip to content

Commit a6ecf71

Browse files
committed
Make use of language features like end() and array_pad()
1 parent 5a45e13 commit a6ecf71

4 files changed

Lines changed: 7 additions & 14 deletions

File tree

src/ByPropertyIdArray.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private function moveObjectInPropertyGroup( $object, $toIndex ) {
221221
$propertyId = $object->getPropertyId();
222222

223223
$numericIndices = $this->getFlatArrayIndices( $propertyId );
224-
$lastIndex = $numericIndices[count( $numericIndices ) - 1];
224+
$lastIndex = end( $numericIndices );
225225

226226
if ( $toIndex > $lastIndex + 1 || $toIndex < $numericIndices[0] ) {
227227
throw new OutOfBoundsException( 'Object cannot be moved to ' . $toIndex );
@@ -398,7 +398,7 @@ public function moveObjectToIndex( $object, $toIndex ) {
398398
} else {
399399
$edgeIndex = ( $toIndex <= $propertyIndices[0] )
400400
? $propertyIndices[0]
401-
: $propertyIndices[count( $propertyIndices ) - 1];
401+
: end( $propertyIndices );
402402

403403
$this->moveObjectInPropertyGroup( $object, $edgeIndex );
404404
$this->movePropertyGroup( $object->getPropertyId(), $toIndex );
@@ -465,11 +465,11 @@ private function addObjectToPropertyGroup( $object, $index = null ) {
465465
}
466466

467467
// Add index to allow placing object after the last object of the "property group":
468-
$validIndices[] = $validIndices[count( $validIndices ) - 1] + 1;
468+
$validIndices[] = end( $validIndices ) + 1;
469469

470470
if ( $index === null ) {
471471
// If index is null, append object to "property group".
472-
$index = $validIndices[count( $validIndices ) - 1];
472+
$index = end( $validIndices );
473473
}
474474

475475
if ( in_array( $index, $validIndices ) ) {

src/Entity/EntityId.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ public function equals( $target ) {
224224
* @return string[] Array of form [ string $repositoryName, string $localPart ]
225225
*/
226226
protected static function extractRepositoryNameAndLocalPart( $serialization ) {
227-
$parts = explode( ':', $serialization, 2 );
228-
return isset( $parts[1] ) ? $parts : [ '', $parts[0] ];
227+
return array_pad( explode( ':', $serialization, 2 ), -2, '' );
229228
}
230229

231230
}

src/Snak/DerivedPropertyValueSnak.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ public function getDerivedDataValues() {
7272
* @return DataValue|null
7373
*/
7474
public function getDerivedDataValue( $key ) {
75-
if ( isset( $this->derivedDataValues[$key] ) ) {
76-
return $this->derivedDataValues[$key];
77-
}
78-
79-
return null;
75+
return $this->derivedDataValues[$key] ?? null;
8076
}
8177

8278
/**

tests/unit/Snak/SnakListTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ public function testRemoveSnak( SnakList $array ) {
144144
public function testAddSnak( SnakList $array ) {
145145
$elementCount = $array->count();
146146

147-
$elements = $this->elementInstancesProvider();
148-
$element = array_shift( $elements );
149-
$element = $element[0][0];
147+
$element = $this->elementInstancesProvider()[0][0][0];
150148

151149
if ( !$array->hasSnak( $element ) ) {
152150
++$elementCount;

0 commit comments

Comments
 (0)