Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MediaModerationFileFactory | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFileObjectForRow | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | declare( strict_types=1 ); |
| 3 | |
| 4 | namespace MediaWiki\Extension\MediaModeration\Services; |
| 5 | |
| 6 | use InvalidArgumentException; |
| 7 | use MediaWiki\FileRepo\File\ArchivedFile; |
| 8 | use MediaWiki\FileRepo\File\LocalFile; |
| 9 | use MediaWiki\FileRepo\LocalRepo; |
| 10 | |
| 11 | /** |
| 12 | * A service that allows creating File or ArchivedFile objects |
| 13 | * for given rows from the image, oldimage, and filearchive tables. |
| 14 | */ |
| 15 | class MediaModerationFileFactory { |
| 16 | |
| 17 | public function __construct( |
| 18 | private readonly LocalRepo $localRepo, |
| 19 | ) { |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Get the LocalFile or ArchiveFile object for the $row. |
| 24 | * The exact object type depends on the $table provided. |
| 25 | * |
| 26 | * @param \stdClass $row |
| 27 | * @param string $table |
| 28 | * @return ArchivedFile|LocalFile |
| 29 | */ |
| 30 | public function getFileObjectForRow( $row, string $table ) { |
| 31 | if ( $table === 'image' || $table === 'oldimage' ) { |
| 32 | return $this->localRepo->newFileFromRow( (object)$row ); |
| 33 | } elseif ( $table === 'filearchive' ) { |
| 34 | return ArchivedFile::newFromRow( (object)$row ); |
| 35 | } else { |
| 36 | throw new InvalidArgumentException( "Unrecognised image table '$table'." ); |
| 37 | } |
| 38 | } |
| 39 | } |