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

Yoast / wordpress-seo / ad2c4b607f7daae862318f3d8e622f745e25b2c7

18 Oct 2024 10:15AM UTC coverage: 49.406% (-5.2%) from 54.573%
ad2c4b607f7daae862318f3d8e622f745e25b2c7

push

github

web-flow
Merge pull request #21717 from Yoast/389-enable-typescript-in-the-package

Enable typescript in the yoastseo package

7549 of 13564 branches covered (55.65%)

Branch coverage included in aggregate %.

20 of 98 new or added lines in 1 file covered. (20.41%)

4289 existing lines in 144 files now uncovered.

25667 of 53667 relevant lines covered (47.83%)

42470.98 hits per line

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

0.0
/admin/class-asset.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin
6
 */
7

8
/**
9
 * Represents a WPSEO asset
10
 */
11
class WPSEO_Admin_Asset {
12

13
        /**
14
         * Constant used to identify file type as a JS file.
15
         *
16
         * @var string
17
         */
18
        public const TYPE_JS = 'js';
19

20
        /**
21
         * Constant used to identify file type as a CSS file.
22
         *
23
         * @var string
24
         */
25
        public const TYPE_CSS = 'css';
26

27
        /**
28
         * The name option identifier.
29
         *
30
         * @var string
31
         */
32
        public const NAME = 'name';
33

34
        /**
35
         * The source option identifier.
36
         *
37
         * @var string
38
         */
39
        public const SRC = 'src';
40

41
        /**
42
         * The dependencies option identifier.
43
         *
44
         * @var string
45
         */
46
        public const DEPS = 'deps';
47

48
        /**
49
         * The version option identifier.
50
         *
51
         * @var string
52
         */
53
        public const VERSION = 'version';
54

55
        /* Style specific. */
56

57
        /**
58
         * The media option identifier.
59
         *
60
         * @var string
61
         */
62
        public const MEDIA = 'media';
63

64
        /**
65
         * The rtl option identifier.
66
         *
67
         * @var string
68
         */
69
        public const RTL = 'rtl';
70

71
        /* Script specific. */
72

73
        /**
74
         * The "in footer" option identifier.
75
         *
76
         * @var string
77
         */
78
        public const IN_FOOTER = 'in_footer';
79

80
        /**
81
         * Asset identifier.
82
         *
83
         * @var string
84
         */
85
        protected $name;
86

87
        /**
88
         * Path to the asset.
89
         *
90
         * @var string
91
         */
92
        protected $src;
93

94
        /**
95
         * Asset dependencies.
96
         *
97
         * @var string|array
98
         */
99
        protected $deps;
100

101
        /**
102
         * Asset version.
103
         *
104
         * @var string
105
         */
106
        protected $version;
107

108
        /**
109
         * For CSS Assets. The type of media for which this stylesheet has been defined.
110
         *
111
         * See https://www.w3.org/TR/CSS2/media.html#media-types.
112
         *
113
         * @var string
114
         */
115
        protected $media;
116

117
        /**
118
         * For JS Assets. Whether or not the script should be loaded in the footer.
119
         *
120
         * @var bool
121
         */
122
        protected $in_footer;
123

124
        /**
125
         * For JS Assets. The script's async/defer strategy.
126
         *
127
         * @var string
128
         */
129
        protected $strategy;
130

131
        /**
132
         * For CSS Assets. Whether this stylesheet is a right-to-left stylesheet.
133
         *
134
         * @var bool
135
         */
136
        protected $rtl;
137

138
        /**
139
         * File suffix.
140
         *
141
         * @var string
142
         */
143
        protected $suffix;
144

145
        /**
146
         * Default asset arguments.
147
         *
148
         * @var array
149
         */
150
        private $defaults = [
151
                'deps'      => [],
152
                'in_footer' => true,
153
                'rtl'       => true,
154
                'media'     => 'all',
155
                'version'   => '',
156
                'suffix'    => '',
157
                'strategy'  => '',
158
        ];
159

160
        /**
161
         * Constructs an instance of the WPSEO_Admin_Asset class.
162
         *
163
         * @param array $args The arguments for this asset.
164
         *
165
         * @throws InvalidArgumentException Throws when no name or src has been provided.
166
         */
UNCOV
167
        public function __construct( array $args ) {
×
UNCOV
168
                if ( ! isset( $args['name'] ) ) {
×
UNCOV
169
                        throw new InvalidArgumentException( 'name is a required argument' );
×
170
                }
171

UNCOV
172
                if ( ! isset( $args['src'] ) ) {
×
UNCOV
173
                        throw new InvalidArgumentException( 'src is a required argument' );
×
174
                }
175

176
                $args = array_merge( $this->defaults, $args );
×
177

178
                $this->name      = $args['name'];
×
179
                $this->src       = $args['src'];
×
180
                $this->deps      = $args['deps'];
×
181
                $this->version   = $args['version'];
×
182
                $this->media     = $args['media'];
×
183
                $this->in_footer = $args['in_footer'];
×
184
                $this->strategy  = $args['strategy'];
×
185
                $this->rtl       = $args['rtl'];
×
186
                $this->suffix    = $args['suffix'];
×
187
        }
188

189
        /**
190
         * Returns the asset identifier.
191
         *
192
         * @return string
193
         */
UNCOV
194
        public function get_name() {
×
UNCOV
195
                return $this->name;
×
196
        }
197

198
        /**
199
         * Returns the path to the asset.
200
         *
201
         * @return string
202
         */
UNCOV
203
        public function get_src() {
×
UNCOV
204
                return $this->src;
×
205
        }
206

207
        /**
208
         * Returns the asset dependencies.
209
         *
210
         * @return array|string
211
         */
UNCOV
212
        public function get_deps() {
×
UNCOV
213
                return $this->deps;
×
214
        }
215

216
        /**
217
         * Returns the asset version.
218
         *
219
         * @return string|null
220
         */
UNCOV
221
        public function get_version() {
×
UNCOV
222
                if ( ! empty( $this->version ) ) {
×
UNCOV
223
                        return $this->version;
×
224
                }
225

UNCOV
226
                return null;
×
227
        }
228

229
        /**
230
         * Returns the media type for CSS assets.
231
         *
232
         * @return string
233
         */
UNCOV
234
        public function get_media() {
×
UNCOV
235
                return $this->media;
×
236
        }
237

238
        /**
239
         * Returns whether a script asset should be loaded in the footer of the page.
240
         *
241
         * @return bool
242
         */
UNCOV
243
        public function is_in_footer() {
×
UNCOV
244
                return $this->in_footer;
×
245
        }
246

247
        /**
248
         * Returns the script asset's async/defer loading strategy.
249
         *
250
         * @return string
251
         */
252
        public function get_strategy() {
×
253
                return $this->strategy;
×
254
        }
255

256
        /**
257
         * Returns whether this CSS has a RTL counterpart.
258
         *
259
         * @return bool
260
         */
UNCOV
261
        public function has_rtl() {
×
UNCOV
262
                return $this->rtl;
×
263
        }
264

265
        /**
266
         * Returns the file suffix.
267
         *
268
         * @return string
269
         */
UNCOV
270
        public function get_suffix() {
×
UNCOV
271
                return $this->suffix;
×
272
        }
273
}
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

© 2026 Coveralls, Inc