• 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
/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
         */
UNCOV
20
        public function get( WP_REST_Request $request ) {
×
21
                try {
UNCOV
22
                        $file_url = $this->get_file_url( $request );
×
23

UNCOV
24
                        return new WP_REST_Response(
×
UNCOV
25
                                [
×
UNCOV
26
                                        'type'          => 'success',
×
UNCOV
27
                                        'size_in_bytes' => $this->get_file_size( $file_url ),
×
UNCOV
28
                                ],
×
UNCOV
29
                                200
×
UNCOV
30
                        );
×
31
                }
UNCOV
32
                catch ( WPSEO_File_Size_Exception $exception ) {
×
UNCOV
33
                        return new WP_REST_Response(
×
UNCOV
34
                                [
×
UNCOV
35
                                        'type'     => 'failure',
×
UNCOV
36
                                        'response' => $exception->getMessage(),
×
UNCOV
37
                                ],
×
UNCOV
38
                                404
×
UNCOV
39
                        );
×
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
         */
UNCOV
51
        protected function get_file_url( WP_REST_Request $request ) {
×
UNCOV
52
                $file_url = rawurldecode( $request->get_param( 'url' ) );
×
53

UNCOV
54
                if ( ! $this->is_externally_hosted( $file_url ) ) {
×
UNCOV
55
                        return $file_url;
×
56
                }
57

UNCOV
58
                throw WPSEO_File_Size_Exception::externally_hosted( $file_url );
×
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(
×
UNCOV
101
                        [
×
102
                                'path' => $file_url,
×
UNCOV
103
                        ]
×
UNCOV
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

© 2025 Coveralls, Inc