Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
64.71% covered (warning)
64.71%
11 / 17
25.00% covered (danger)
25.00%
2 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
ImageRecommendationData
64.71% covered (warning)
64.71%
11 / 17
25.00% covered (danger)
25.00%
2 / 8
12.56
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 getFilename
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSource
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getProjects
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFormattedProjects
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 getDatasetId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSectionNumber
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSectionTitle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace GrowthExperiments\NewcomerTasks\AddImage;
4
5/**
6 * Normalized image recommendation data returned from the image recommendation API
7 */
8class ImageRecommendationData {
9
10    /** @var mixed */
11    private $filename;
12
13    /** @var mixed */
14    private $source;
15
16    /** @var mixed */
17    private $projects;
18
19    /** @var mixed */
20    private $datasetId;
21
22    /** @var mixed */
23    private $sectionNumber;
24
25    /** @var mixed */
26    private $sectionTitle;
27
28    /**
29     * @param mixed $filename Recommendation image file name
30     * @param mixed $source Reason for the image being suggested; should be either
31     *   ImageRecommendationImage::SOURCE_WIKIDATA, ImageRecommendation::SOURCE_WIKIPEDIA or
32     *   ImageRecommendationImage::SOURCE_COMMONS
33     * @param mixed $projects Projects in which the image is found; separated by comma
34     * @param mixed $datasetId Dataset ID for the recommendation
35     * @param mixed $sectionNumber Section number for which the image is recommended (1-based
36     *   index of the section within the second-level sections), or null for top-level
37     *   recommendations.
38     * @param mixed $sectionTitle Wikitext of the section title for which the image is
39     *   recommended, or null for top-level recommendations.
40     */
41    public function __construct(
42        $filename = null,
43        $source = null,
44        $projects = null,
45        $datasetId = null,
46        $sectionNumber = null,
47        $sectionTitle = null
48    ) {
49        $this->filename = $filename;
50        $this->source = $source;
51        $this->projects = $projects;
52        $this->datasetId = $datasetId;
53        $this->sectionNumber = $sectionNumber;
54        $this->sectionTitle = $sectionTitle;
55    }
56
57    /**
58     * @return mixed
59     */
60    public function getFilename() {
61        return $this->filename;
62    }
63
64    /**
65     * @return mixed
66     */
67    public function getSource() {
68        return $this->source;
69    }
70
71    /**
72     * @return mixed
73     */
74    public function getProjects() {
75        return $this->projects;
76    }
77
78    /**
79     * Get an array of projects in which the image recommendation can be found
80     *
81     * @return array
82     */
83    public function getFormattedProjects(): array {
84        if ( $this->projects ) {
85            return array_map( static function ( $project ) {
86                return preg_replace( '/[^a-zA-Z0-9_-]/', '', $project );
87            }, explode( ',', $this->projects ) );
88        }
89        return [];
90    }
91
92    /**
93     * @return mixed
94     */
95    public function getDatasetId() {
96        return $this->datasetId ?? null;
97    }
98
99    /**
100     * @return mixed
101     */
102    public function getSectionNumber() {
103        return $this->sectionNumber;
104    }
105
106    /**
107     * @return mixed
108     */
109    public function getSectionTitle() {
110        return $this->sectionTitle;
111    }
112}