• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / dd6e866a9e6d253114633104d9e3858d807178ba

19 Jun 2024 10:03AM UTC coverage: 48.628% (-4.3%) from 52.936%
dd6e866a9e6d253114633104d9e3858d807178ba

push

github

web-flow
Merge pull request #21431 from Yoast/21429-update-copy-in-the-introduction-and-consent-modals

Updates the copy for the introduction and consent modals

7441 of 13454 branches covered (55.31%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 2 files covered. (0.0%)

3718 existing lines in 107 files now uncovered.

25100 of 53464 relevant lines covered (46.95%)

62392.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/inc/class-wpseo-rank.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Internals
6
 */
7

8
/**
9
 * Holder for SEO Rank information.
10
 */
11
class WPSEO_Rank {
12

13
        /**
14
         * Constant used for determining a bad SEO rating.
15
         *
16
         * @var string
17
         */
18
        public const BAD = 'bad';
19

20
        /**
21
         * Constant used for determining an OK SEO rating.
22
         *
23
         * @var string
24
         */
25
        public const OK = 'ok';
26

27
        /**
28
         * Constant used for determining a good SEO rating.
29
         *
30
         * @var string
31
         */
32
        public const GOOD = 'good';
33

34
        /**
35
         * Constant used for determining that no focus keyphrase is set.
36
         *
37
         * @var string
38
         */
39
        public const NO_FOCUS = 'na';
40

41
        /**
42
         * Constant used for determining that this content is not indexed.
43
         *
44
         * @var string
45
         */
46
        public const NO_INDEX = 'noindex';
47

48
        /**
49
         * All possible ranks.
50
         *
51
         * @var array
52
         */
53
        protected static $ranks = [
54
                self::BAD,
55
                self::OK,
56
                self::GOOD,
57
                self::NO_FOCUS,
58
                self::NO_INDEX,
59
        ];
60

61
        /**
62
         * Holds the translation from seo score slug to actual score range.
63
         *
64
         * @var array
65
         */
66
        protected static $ranges = [
67
                self::NO_FOCUS => [
68
                        'start' => 0,
69
                        'end'   => 0,
70
                ],
71
                self::BAD => [
72
                        'start' => 1,
73
                        'end'   => 40,
74
                ],
75
                self::OK => [
76
                        'start' => 41,
77
                        'end'   => 70,
78
                ],
79
                self::GOOD => [
80
                        'start' => 71,
81
                        'end'   => 100,
82
                ],
83
        ];
84

85
        /**
86
         * The current rank.
87
         *
88
         * @var int
89
         */
90
        protected $rank;
91

92
        /**
93
         * WPSEO_Rank constructor.
94
         *
95
         * @param int $rank The actual rank.
96
         */
UNCOV
97
        public function __construct( $rank ) {
×
UNCOV
98
                if ( ! in_array( $rank, self::$ranks, true ) ) {
×
UNCOV
99
                        $rank = self::BAD;
×
100
                }
101

UNCOV
102
                $this->rank = $rank;
×
103
        }
104

105
        /**
106
         * Returns the saved rank for this rank.
107
         *
108
         * @return string
109
         */
UNCOV
110
        public function get_rank() {
×
UNCOV
111
                return $this->rank;
×
112
        }
113

114
        /**
115
         * Returns a CSS class for this rank.
116
         *
117
         * @return string
118
         */
UNCOV
119
        public function get_css_class() {
×
120
                $labels = [
UNCOV
121
                        self::NO_FOCUS => 'na',
×
122
                        self::NO_INDEX => 'noindex',
123
                        self::BAD      => 'bad',
124
                        self::OK       => 'ok',
125
                        self::GOOD     => 'good',
126
                ];
127

UNCOV
128
                return $labels[ $this->rank ];
×
129
        }
130

131
        /**
132
         * Returns a label for this rank.
133
         *
134
         * @return string
135
         */
UNCOV
136
        public function get_label() {
×
137
                $labels = [
UNCOV
138
                        self::NO_FOCUS => __( 'Not available', 'wordpress-seo' ),
×
UNCOV
139
                        self::NO_INDEX => __( 'No index', 'wordpress-seo' ),
×
UNCOV
140
                        self::BAD      => __( 'Needs improvement', 'wordpress-seo' ),
×
UNCOV
141
                        self::OK       => __( 'OK', 'wordpress-seo' ),
×
UNCOV
142
                        self::GOOD     => __( 'Good', 'wordpress-seo' ),
×
143
                ];
144

UNCOV
145
                return $labels[ $this->rank ];
×
146
        }
147

148
        /**
149
         * Returns an inclusive language label for this rank.
150
         * The only difference with get_label above is that we return "Potentially non-inclusive" for an OK rank.
151
         *
152
         * @return string
153
         */
UNCOV
154
        public function get_inclusive_language_label() {
×
UNCOV
155
                if ( $this->rank === self::OK ) {
×
UNCOV
156
                        return __( 'Potentially non-inclusive', 'wordpress-seo' );
×
157
                }
UNCOV
158
                return $this->get_label();
×
159
        }
160

161
        /**
162
         * Returns a label for use in a drop down.
163
         *
164
         * @return mixed
165
         */
UNCOV
166
        public function get_drop_down_label() {
×
167
                $labels = [
UNCOV
168
                        self::NO_FOCUS => sprintf(
×
169
                                /* translators: %s expands to the SEO score */
UNCOV
170
                                __( 'SEO: %s', 'wordpress-seo' ),
×
UNCOV
171
                                __( 'No Focus Keyphrase', 'wordpress-seo' )
×
172
                        ),
UNCOV
173
                        self::BAD => sprintf(
×
174
                                /* translators: %s expands to the SEO score */
UNCOV
175
                                __( 'SEO: %s', 'wordpress-seo' ),
×
UNCOV
176
                                __( 'Needs improvement', 'wordpress-seo' )
×
177
                        ),
UNCOV
178
                        self::OK => sprintf(
×
179
                                /* translators: %s expands to the SEO score */
UNCOV
180
                                __( 'SEO: %s', 'wordpress-seo' ),
×
UNCOV
181
                                __( 'OK', 'wordpress-seo' )
×
182
                        ),
UNCOV
183
                        self::GOOD => sprintf(
×
184
                                /* translators: %s expands to the SEO score */
UNCOV
185
                                __( 'SEO: %s', 'wordpress-seo' ),
×
UNCOV
186
                                __( 'Good', 'wordpress-seo' )
×
187
                        ),
UNCOV
188
                        self::NO_INDEX => sprintf(
×
189
                                /* translators: %s expands to the SEO score */
UNCOV
190
                                __( 'SEO: %s', 'wordpress-seo' ),
×
UNCOV
191
                                __( 'Post Noindexed', 'wordpress-seo' )
×
192
                        ),
193
                ];
194

UNCOV
195
                return $labels[ $this->rank ];
×
196
        }
197

198
        /**
199
         * Gets the drop down labels for the readability score.
200
         *
201
         * @return string The readability rank label.
202
         */
UNCOV
203
        public function get_drop_down_readability_labels() {
×
204
                $labels = [
UNCOV
205
                        self::BAD => sprintf(
×
206
                                /* translators: %s expands to the readability score */
UNCOV
207
                                __( 'Readability: %s', 'wordpress-seo' ),
×
UNCOV
208
                                __( 'Needs improvement', 'wordpress-seo' )
×
209
                        ),
UNCOV
210
                        self::OK => sprintf(
×
211
                                /* translators: %s expands to the readability score */
UNCOV
212
                                __( 'Readability: %s', 'wordpress-seo' ),
×
UNCOV
213
                                __( 'OK', 'wordpress-seo' )
×
214
                        ),
UNCOV
215
                        self::GOOD => sprintf(
×
216
                                /* translators: %s expands to the readability score */
UNCOV
217
                                __( 'Readability: %s', 'wordpress-seo' ),
×
UNCOV
218
                                __( 'Good', 'wordpress-seo' )
×
219
                        ),
220
                ];
221

UNCOV
222
                return $labels[ $this->rank ];
×
223
        }
224

225
        /**
226
         * Gets the drop down labels for the inclusive language score.
227
         *
228
         * @return string The inclusive language rank label.
229
         */
UNCOV
230
        public function get_drop_down_inclusive_language_labels() {
×
231
                $labels = [
UNCOV
232
                        self::BAD => sprintf(
×
233
                        /* translators: %s expands to the inclusive language score */
UNCOV
234
                                __( 'Inclusive language: %s', 'wordpress-seo' ),
×
UNCOV
235
                                __( 'Needs improvement', 'wordpress-seo' )
×
236
                        ),
UNCOV
237
                        self::OK => sprintf(
×
238
                        /* translators: %s expands to the inclusive language score */
UNCOV
239
                                __( 'Inclusive language: %s', 'wordpress-seo' ),
×
UNCOV
240
                                __( 'Potentially non-inclusive', 'wordpress-seo' )
×
241
                        ),
UNCOV
242
                        self::GOOD => sprintf(
×
243
                        /* translators: %s expands to the inclusive language score */
UNCOV
244
                                __( 'Inclusive language: %s', 'wordpress-seo' ),
×
UNCOV
245
                                __( 'Good', 'wordpress-seo' )
×
246
                        ),
247
                ];
248

UNCOV
249
                return $labels[ $this->rank ];
×
250
        }
251

252
        /**
253
         * Get the starting score for this rank.
254
         *
255
         * @return int The start score.
256
         */
UNCOV
257
        public function get_starting_score() {
×
258
                // No index does not have a starting score.
UNCOV
259
                if ( $this->rank === self::NO_INDEX ) {
×
UNCOV
260
                        return -1;
×
261
                }
262

UNCOV
263
                return self::$ranges[ $this->rank ]['start'];
×
264
        }
265

266
        /**
267
         * Get the ending score for this rank.
268
         *
269
         * @return int The end score.
270
         */
UNCOV
271
        public function get_end_score() {
×
272
                // No index does not have an end score.
UNCOV
273
                if ( $this->rank === self::NO_INDEX ) {
×
UNCOV
274
                        return -1;
×
275
                }
276

UNCOV
277
                return self::$ranges[ $this->rank ]['end'];
×
278
        }
279

280
        /**
281
         * Returns a rank for a specific numeric score.
282
         *
283
         * @param int $score The score to determine a rank for.
284
         *
285
         * @return self
286
         */
UNCOV
287
        public static function from_numeric_score( $score ) {
×
288
                // Set up the default value.
UNCOV
289
                $rank = new self( self::BAD );
×
290

UNCOV
291
                foreach ( self::$ranges as $rank_index => $range ) {
×
UNCOV
292
                        if ( $range['start'] <= $score && $score <= $range['end'] ) {
×
UNCOV
293
                                $rank = new self( $rank_index );
×
UNCOV
294
                                break;
×
295
                        }
296
                }
297

UNCOV
298
                return $rank;
×
299
        }
300

301
        /**
302
         * Returns a list of all possible SEO Ranks.
303
         *
304
         * @return WPSEO_Rank[]
305
         */
UNCOV
306
        public static function get_all_ranks() {
×
UNCOV
307
                return array_map( [ 'WPSEO_Rank', 'create_rank' ], self::$ranks );
×
308
        }
309

310
        /**
311
         * Returns a list of all possible Readability Ranks.
312
         *
313
         * @return WPSEO_Rank[]
314
         */
UNCOV
315
        public static function get_all_readability_ranks() {
×
UNCOV
316
                return array_map( [ 'WPSEO_Rank', 'create_rank' ], [ self::BAD, self::OK, self::GOOD ] );
×
317
        }
318

319
        /**
320
         * Returns a list of all possible Inclusive Language Ranks.
321
         *
322
         * @return WPSEO_Rank[]
323
         */
UNCOV
324
        public static function get_all_inclusive_language_ranks() {
×
UNCOV
325
                return array_map( [ 'WPSEO_Rank', 'create_rank' ], [ self::BAD, self::OK, self::GOOD ] );
×
326
        }
327

328
        /**
329
         * Converts a numeric rank into a WPSEO_Rank object, for use in functional array_* functions.
330
         *
331
         * @param string $rank SEO Rank.
332
         *
333
         * @return WPSEO_Rank
334
         */
335
        private static function create_rank( $rank ) {
×
336
                return new self( $rank );
×
337
        }
338
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc