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

Yoast / wordpress-seo / 0fdb51d5ef87fb55b55da5a950cf7350c155980d

11 Mar 2025 10:16AM UTC coverage: 53.422% (-1.3%) from 54.687%
0fdb51d5ef87fb55b55da5a950cf7350c155980d

push

github

web-flow
Merge pull request #22086 from Yoast/add-pregnant-women-to-potentially-non-inclusive-phrases

Inclusive language: Add 'pregnant women' to potentially non-inclusive phrases

7918 of 13987 branches covered (56.61%)

Branch coverage included in aggregate %.

30526 of 57976 relevant lines covered (52.65%)

41097.18 hits per line

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

59.46
/admin/services/class-file-size.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin\Services
6
 */
7

8
/**
9
 * Represents the file size service.
10
 */
11
class WPSEO_File_Size_Service {
12

13
        /**
14
         * Retrieves an indexable.
15
         *
16
         * @param WP_REST_Request $request The request object.
17
         *
18
         * @return WP_REST_Response The response.
19
         */
20
        public function get( WP_REST_Request $request ) {
10✔
21
                try {
22
                        $file_url = $this->get_file_url( $request );
10✔
23

24
                        return new WP_REST_Response(
6✔
25
                                [
6✔
26
                                        'type'          => 'success',
6✔
27
                                        'size_in_bytes' => $this->get_file_size( $file_url ),
6✔
28
                                ],
6✔
29
                                200
6✔
30
                        );
6✔
31
                }
32
                catch ( WPSEO_File_Size_Exception $exception ) {
6✔
33
                        return new WP_REST_Response(
6✔
34
                                [
6✔
35
                                        'type'     => 'failure',
6✔
36
                                        'response' => $exception->getMessage(),
6✔
37
                                ],
6✔
38
                                404
6✔
39
                        );
6✔
40
                }
41
        }
42

43
        /**
44
         * Retrieves the file url.
45
         *
46
         * @param WP_REST_Request $request The request to retrieve file url from.
47
         *
48
         * @return string The file url.
49
         * @throws WPSEO_File_Size_Exception The file is hosted externally.
50
         */
51
        protected function get_file_url( WP_REST_Request $request ) {
4✔
52
                $file_url = rawurldecode( $request->get_param( 'url' ) );
4✔
53

54
                if ( ! $this->is_externally_hosted( $file_url ) ) {
4✔
55
                        return $file_url;
2✔
56
                }
57

58
                throw WPSEO_File_Size_Exception::externally_hosted( $file_url );
2✔
59
        }
60

61
        /**
62
         * Checks if the file is hosted externally.
63
         *
64
         * @param string $file_url The file url.
65
         *
66
         * @return bool True if it is hosted externally.
67
         */
68
        protected function is_externally_hosted( $file_url ) {
×
69
                return wp_parse_url( home_url(), PHP_URL_HOST ) !== wp_parse_url( $file_url, PHP_URL_HOST );
×
70
        }
71

72
        /**
73
         * Returns the file size.
74
         *
75
         * @param string $file_url The file url to get the size for.
76
         *
77
         * @return int The file size.
78
         * @throws WPSEO_File_Size_Exception Retrieval of file size went wrong for unknown reasons.
79
         */
80
        protected function get_file_size( $file_url ) {
×
81
                $file_config = wp_upload_dir();
×
82
                $file_url    = str_replace( $file_config['baseurl'], '', $file_url );
×
83
                $file_size   = $this->calculate_file_size( $file_url );
×
84

85
                if ( ! $file_size ) {
×
86
                        throw WPSEO_File_Size_Exception::unknown_error( $file_url );
×
87
                }
88

89
                return $file_size;
×
90
        }
91

92
        /**
93
         * Calculates the file size using the Utils class.
94
         *
95
         * @param string $file_url The file to retrieve the size for.
96
         *
97
         * @return int|bool The file size or False if it could not be retrieved.
98
         */
99
        protected function calculate_file_size( $file_url ) {
×
100
                return WPSEO_Image_Utils::get_file_size(
×
101
                        [
×
102
                                'path' => $file_url,
×
103
                        ]
×
104
                );
×
105
        }
106
}
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