Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| MediaModerationMockPhotoDNAServiceProvider | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | n/a |
0 / 0 |
|||
| __construct | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| check | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| 1 | <?php |
| 2 | declare( strict_types=1 ); |
| 3 | |
| 4 | namespace MediaWiki\Extension\MediaModeration\Services; |
| 5 | |
| 6 | use MediaWiki\Extension\MediaModeration\PhotoDNA\IMediaModerationPhotoDNAServiceProvider; |
| 7 | use MediaWiki\Extension\MediaModeration\PhotoDNA\MediaModerationPhotoDNAResponseHandler; |
| 8 | use MediaWiki\Extension\MediaModeration\PhotoDNA\Response; |
| 9 | use MediaWiki\Json\FormatJson; |
| 10 | use StatusValue; |
| 11 | |
| 12 | /** |
| 13 | * Mock implementation of PhotoDNA endpoint, for local development environments and CI. |
| 14 | * @codeCoverageIgnore This is for CI and local development, so does not need code coverage. |
| 15 | */ |
| 16 | class MediaModerationMockPhotoDNAServiceProvider implements IMediaModerationPhotoDNAServiceProvider { |
| 17 | |
| 18 | use MediaModerationPhotoDNAResponseHandler; |
| 19 | |
| 20 | /** |
| 21 | * @param array $filesToIsMatchMap Map of file names to boolean values where true indicates |
| 22 | * a match with PhotoDNA's database, and false (default) means no match |
| 23 | * @param array $filesToStatusCodeMap Map of file names to integer status codes, |
| 24 | * see the Response::STATUS_ constants. Default is STATUS_OK. |
| 25 | */ |
| 26 | public function __construct( |
| 27 | private readonly array $filesToIsMatchMap = [], |
| 28 | private readonly array $filesToStatusCodeMap = [], |
| 29 | ) { |
| 30 | } |
| 31 | |
| 32 | /** @inheritDoc */ |
| 33 | public function check( $file ): StatusValue { |
| 34 | $statusCode = $this->filesToStatusCodeMap[ $file->getName() ] ?? Response::STATUS_OK; |
| 35 | $isMatch = $this->filesToIsMatchMap[ $file->getName() ] ?? false; |
| 36 | $response = new Response( |
| 37 | $statusCode, |
| 38 | $isMatch, |
| 39 | FormatJson::encode( 'Mock endpoint in use!' ) |
| 40 | ); |
| 41 | return $this->createStatusFromResponse( $response ); |
| 42 | } |
| 43 | |
| 44 | } |