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

Yoast / whip / 6985375056

24 Nov 2023 10:53PM UTC coverage: 28.713% (+1.2%) from 27.5%
6985375056

push

github

web-flow
Merge pull request #152 from Yoast/JRF/ghactions-switch-to-coveralls-reporter

GH Actions: switch to Coveralls action runner to upload reports

87 of 303 relevant lines covered (28.71%)

2.62 hits per line

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

0.0
/src/Whip_Host.php
1
<?php
2
/**
3
 * WHIP libary file.
4
 *
5
 * @package Yoast\WHIP
6
 */
7

8
/**
9
 * Represents a host.
10
 */
11
class Whip_Host {
12

13
        /**
14
         * Key to an environment variable which should be set to the name of the host.
15
         *
16
         * @var string
17
         */
18
        const HOST_NAME_KEY = 'WHIP_NAME_OF_HOST';
19

20
        /**
21
         * Filter name for the filter which allows for pointing to the WP hosting page instead of the Yoast version.
22
         *
23
         * @var string
24
         */
25
        const HOSTING_PAGE_FILTER_KEY = 'whip_hosting_page_url_wordpress';
26

27
        /**
28
         * Retrieves the name of the host if set.
29
         *
30
         * @return string The name of the host.
31
         */
32
        public static function name() {
×
33
                $name = (string) getenv( self::HOST_NAME_KEY );
×
34

35
                return self::filterName( $name );
×
36
        }
37

38
        /**
39
         * Filters the name if we are in a WordPress context.
40
         * In a non-WordPress content this function just returns the passed name.
41
         *
42
         * @param string $name The current name of the host.
43
         *
44
         * @return string The filtered name of the host.
45
         */
46
        private static function filterName( $name ) {
×
47
                if ( function_exists( 'apply_filters' ) ) {
×
48
                        return (string) apply_filters( strtolower( self::HOST_NAME_KEY ), $name );
×
49
                }
50

51
                return $name;
×
52
        }
53

54
        /**
55
         * Retrieves the message from the host if set.
56
         *
57
         * @param string $messageKey The key to use as the environment variable.
58
         *
59
         * @return string The message as set by the host.
60
         */
61
        public static function message( $messageKey ) {
×
62
                $message = (string) getenv( $messageKey );
×
63

64
                return self::filterMessage( $messageKey, $message );
×
65
        }
66

67
        /**
68
         * Filters the message if we are in a WordPress context.
69
         * In a non-WordPress content this function just returns the passed message.
70
         *
71
         * @param string $messageKey The key used for the environment variable.
72
         * @param string $message    The current message from the host.
73
         *
74
         * @return string
75
         */
76
        private static function filterMessage( $messageKey, $message ) {
×
77
                if ( function_exists( 'apply_filters' ) ) {
×
78
                        return (string) apply_filters( strtolower( $messageKey ), $message );
×
79
                }
80

81
                return $message;
×
82
        }
83

84
        /**
85
         * Returns the URL for the hosting page.
86
         *
87
         * @return string The URL to the hosting overview page.
88
         */
89
        public static function hostingPageUrl() {
×
90
                $url = 'https://yoa.st/w3';
×
91

92
                return self::filterHostingPageUrl( $url );
×
93
        }
94

95
        /**
96
         * Filters the hosting page url if we are in a WordPress context.
97
         * In a non-WordPress context this function just returns a link to the Yoast hosting page.
98
         *
99
         * @param string $url The previous URL.
100
         *
101
         * @return string The new URL to the hosting overview page.
102
         */
103
        private static function filterHostingPageUrl( $url ) {
×
104
                if ( function_exists( 'apply_filters' ) && apply_filters( self::HOSTING_PAGE_FILTER_KEY, false ) ) {
×
105
                        return 'https://wordpress.org/hosting/';
×
106
                }
107

108
                return $url;
×
109
        }
110
}
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