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

AxeWP / wp-graphql-rank-math / 5176687204

pending completion
5176687204

push

github

web-flow
chore: Implement WPGraphQL Code Standards (PHPCS) (#51)

* chore: lint for WPGraphQL-Minimum

* chore: lint for WPGraphQL-Strict

* chore: lint for WPGraphQL-Extra

* chore: lint for WPGraphQL (full)

* chore: update PHPCS ruleset

* chore: update changelog

* fix: restore `rank_math/head` hook

* chore: update composer deps (wpcli fix)

* chore: fix missed files

* chore: update composer deps

* test: bump boilerplate

* chore: update deps to final versions

93 of 93 new or added lines in 32 files covered. (100.0%)

1963 of 2274 relevant lines covered (86.32%)

5.42 hits per line

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

37.5
/src/Main.php
1
<?php
2
/**
3
 * Initializes a singleton instance of the plugin.
4
 *
5
 * @package WPGraphQL\RankMath
6
 */
7

8
namespace WPGraphQL\RankMath;
9

10
use RankMath\Helper as RMHelper;
11
use WPGraphQL\RankMath\Admin\Settings\Settings;
12
use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Helper\Helper;
13

14
if ( ! class_exists( 'WPGraphQL\RankMath\Main' ) ) :
15

16
        /**
17
         * Class - Main
18
         */
19
        final class Main {
20
                /**
21
                 * Class instances.
22
                 *
23
                 * @var ?self $instance
24
                 */
25
                private static $instance;
26

27
                /**
28
                 * Constructor
29
                 */
30
                public static function instance(): self {
31
                        if ( ! isset( self::$instance ) || ! ( is_a( self::$instance, self::class ) ) ) {
1✔
32
                                // You cant test a singleton.
33
                                // @codeCoverageIgnoreStart .
34
                                if ( ! function_exists( 'is_plugin_active' ) ) {
×
35
                                        require_once ABSPATH . 'wp-admin/includes/plugin.php';
×
36
                                }
37
                                self::$instance = new self();
×
38
                                self::$instance->includes();
×
39
                                self::$instance->setup();
×
40
                                // @codeCoverageIgnoreEnd
41
                        }
42

43
                        /**
44
                         * Fire off init action.
45
                         *
46
                         * @param self $instance the instance of the plugin class.
47
                         */
48
                        do_action( 'graphql_seo_init', self::$instance );
1✔
49

50
                        return self::$instance;
1✔
51
                }
52

53
                /**
54
                 * Includes the required files with Composer's autoload.
55
                 *
56
                 * @codeCoverageIgnore
57
                 */
58
                private function includes(): void {
59
                        if ( defined( 'WPGRAPHQL_SEO_AUTOLOAD' ) && false !== WPGRAPHQL_SEO_AUTOLOAD && defined( 'WPGRAPHQL_SEO_PLUGIN_DIR' ) ) {
60
                                require_once WPGRAPHQL_SEO_PLUGIN_DIR . 'vendor/autoload.php';
61
                        }
62
                }
63

64
                /**
65
                 * Sets up the schema.
66
                 *
67
                 * @codeCoverageIgnore
68
                 */
69
                private function setup(): void {
70
                        // // Setup boilerplate hook prefix.
71
                        Helper::set_hook_prefix( 'graphql_seo' );
72

73
                        // Force enable RankMath headless support.
74
                        $enabled = RMHelper::get_settings( 'general.headless_support' );
75

76
                        if ( empty( $enabled ) ) {
77
                                $options                     = get_option( 'rank-math-options-general', [] );
78
                                $options['headless_support'] = 'on';
79
                                update_option( 'rank-math-options-general', $options );
80
                        }
81

82
                        // Setup plugin.
83
                        CoreSchemaFilters::init();
84
                        Settings::init();
85
                        TypeRegistry::init();
86
                }
87

88
                /**
89
                 * Throw error on object clone.
90
                 * The whole idea of the singleton design pattern is that there is a single object
91
                 * therefore, we don't want the object to be cloned.
92
                 *
93
                 * @codeCoverageIgnore
94
                 *
95
                 * @return void
96
                 */
97
                public function __clone() {
98
                        // Cloning instances of the class is forbidden.
99
                        _doing_it_wrong( __FUNCTION__, esc_html__( 'The plugin Main class should not be cloned.', 'wp-graphql-rank-math' ), '0.0.1' );
100
                }
101

102
                /**
103
                 * Disable unserializing of the class.
104
                 *
105
                 * @codeCoverageIgnore
106
                 */
107
                public function __wakeup(): void {
108
                        // De-serializing instances of the class is forbidden.
109
                        _doing_it_wrong( __FUNCTION__, esc_html__( 'De-serializing instances of the plugin Main class is not allowed.', 'wp-graphql-rank-math' ), '0.0.1' );
110
                }
111
        }
112
endif;
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