Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
ImageRecommendationBaseTaskTypeHandler | |
0.00% |
0 / 21 |
|
0.00% |
0 / 7 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getChangeTags | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRecommendationProvider | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSubmissionHandler | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
validateTaskTypeConfiguration | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
getTaskTypeIdByChangeTagName | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\NewcomerTasks\TaskType; |
4 | |
5 | use GrowthExperiments\NewcomerTasks\AddImage\AddImageSubmissionHandler; |
6 | use GrowthExperiments\NewcomerTasks\AddImage\ImageRecommendationProvider; |
7 | use GrowthExperiments\NewcomerTasks\ConfigurationLoader\ConfigurationValidator; |
8 | use LogicException; |
9 | use MediaWiki\Title\TitleParser; |
10 | use StatusValue; |
11 | |
12 | abstract class ImageRecommendationBaseTaskTypeHandler extends StructuredTaskTypeHandler { |
13 | |
14 | // This weird hack is the only way in PHP to have abstract constants. |
15 | public const ID = self::ID; |
16 | public const TASK_TYPE_ID = self::TASK_TYPE_ID; |
17 | public const CHANGE_TAG = self::CHANGE_TAG; |
18 | public const WEIGHTED_TAG_PREFIX = self::WEIGHTED_TAG_PREFIX; |
19 | |
20 | protected ImageRecommendationProvider $recommendationProvider; |
21 | protected AddImageSubmissionHandler $submissionHandler; |
22 | |
23 | /** |
24 | * @param ConfigurationValidator $configurationValidator |
25 | * @param TitleParser $titleParser |
26 | * @param ImageRecommendationProvider $recommendationProvider |
27 | * @param AddImageSubmissionHandler $submissionHandler |
28 | */ |
29 | public function __construct( |
30 | ConfigurationValidator $configurationValidator, |
31 | TitleParser $titleParser, |
32 | ImageRecommendationProvider $recommendationProvider, |
33 | AddImageSubmissionHandler $submissionHandler |
34 | ) { |
35 | parent::__construct( $configurationValidator, $titleParser ); |
36 | $this->recommendationProvider = $recommendationProvider; |
37 | $this->submissionHandler = $submissionHandler; |
38 | } |
39 | |
40 | /** @inheritDoc */ |
41 | public function getId(): string { |
42 | return static::ID; |
43 | } |
44 | |
45 | /** @inheritDoc */ |
46 | public function getChangeTags( ?string $taskType = null ): array { |
47 | return [ TaskTypeHandler::NEWCOMER_TASK_TAG, static::CHANGE_TAG ]; |
48 | } |
49 | |
50 | /** @inheritDoc */ |
51 | public function getRecommendationProvider(): ImageRecommendationProvider { |
52 | return $this->recommendationProvider; |
53 | } |
54 | |
55 | /** @inheritDoc */ |
56 | public function getSubmissionHandler(): AddImageSubmissionHandler { |
57 | return $this->submissionHandler; |
58 | } |
59 | |
60 | /** @inheritDoc */ |
61 | public function validateTaskTypeConfiguration( string $taskTypeId, array $config ): StatusValue { |
62 | $status = parent::validateTaskTypeConfiguration( $taskTypeId, $config ); |
63 | if ( !$status->isOK() ) { |
64 | return $status; |
65 | } |
66 | foreach ( [ |
67 | ImageRecommendationBaseTaskType::FIELD_MAX_TASKS_PER_DAY, |
68 | ImageRecommendationBaseTaskType::FIELD_MINIMUM_CAPTION_CHARACTER_LENGTH, |
69 | ] as $field ) { |
70 | if ( array_key_exists( $field, $config ) ) { |
71 | $status->merge( $this->configurationValidator->validateInteger( |
72 | $config, $field, $taskTypeId, 1 ) ); |
73 | } |
74 | } |
75 | return $status; |
76 | } |
77 | |
78 | /** @inheritDoc */ |
79 | public function getTaskTypeIdByChangeTagName( string $changeTagName ): ?string { |
80 | if ( $changeTagName !== static::CHANGE_TAG ) { |
81 | throw new LogicException( "\"$changeTagName\" is not a valid change tag name for " . static::class ); |
82 | } |
83 | return static::TASK_TYPE_ID; |
84 | } |
85 | |
86 | } |