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

Yoast / whip / 7300735247

22 Dec 2023 02:07PM UTC coverage: 31.683% (+3.0%) from 28.713%
7300735247

push

github

web-flow
Merge pull request #157 from Yoast/move-to-namespace-v2

Move source classes to the `Yoast\WHIPv2` namespace

30 of 114 new or added lines in 18 files covered. (26.32%)

96 of 303 relevant lines covered (31.68%)

2.66 hits per line

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

0.0
/src/Host.php
1
<?php
2

3
namespace Yoast\WHIPv2;
4

5
/**
6
 * Represents a host.
7
 */
8
class Host {
9

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

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

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

32
                return self::filterName( $name );
×
33
        }
34

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

48
                return $name;
×
49
        }
50

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

61
                return self::filterMessage( $messageKey, $message );
×
62
        }
63

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

78
                return $message;
×
79
        }
80

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

89
                return self::filterHostingPageUrl( $url );
×
90
        }
91

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

105
                return $url;
×
106
        }
107
}
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