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

AxeWP / wp-graphql-rank-math / 10338994492

11 Aug 2024 10:22AM UTC coverage: 89.142% (-0.06%) from 89.203%
10338994492

push

github

web-flow
release: 0.3.1 (#107)

* chore: version bump

* chore: regenerate autoloader

* fix: ensure autoloader compatibility when installed as Composer package.

* chore: phpcs issues

* chore: regenerate Composer autoloader

0 of 2 new or added lines in 1 file covered. (0.0%)

2586 of 2901 relevant lines covered (89.14%)

10.88 hits per line

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

0.0
/src/Autoloader.php
1
<?php
2
/**
3
 * Includes the composer Autoloader used for packages and classes in the src/ directory.
4
 *
5
 * @package WPGraphQL\RankMath
6
 */
7

8
declare( strict_types = 1 );
9

10
namespace WPGraphQL\RankMath;
11

12
/**
13
 * Class - Autoloader
14
 *
15
 * @internal
16
 */
17
class Autoloader {
18
        /**
19
         * Whether the autoloader has been loaded.
20
         *
21
         * @var bool
22
         */
23
        protected static bool $is_loaded = false;
24

25
        /**
26
         * Attempts to autoload the Composer dependencies.
27
         */
28
        public static function autoload(): bool {
29
                // If we're not *supposed* to autoload anything, then return true.
30
                if ( defined( 'WPGRAPHQL_SEO_AUTOLOAD' ) && false === WPGRAPHQL_SEO_AUTOLOAD ) {
×
31
                        return true;
×
32
                }
33

34
                if ( self::$is_loaded ) {
×
35
                        return self::$is_loaded;
×
36
                }
37

38
                // If the main class has already been loaded, then they must be using a different autoloader.
NEW
39
                if ( class_exists( 'WPGraphQL\RankMath\Main' ) ) {
×
NEW
40
                        return true;
×
41
                }
42

43
                $autoloader      = dirname( __DIR__ ) . '/vendor/autoload.php';
×
44
                self::$is_loaded = self::require_autoloader( $autoloader );
×
45

46
                return self::$is_loaded;
×
47
        }
48

49
        /**
50
         * Attempts to load the autoloader file, if it exists.
51
         *
52
         * @param string $autoloader_file The path to the autoloader file.
53
         */
54
        protected static function require_autoloader( string $autoloader_file ): bool {
55
                if ( ! is_readable( $autoloader_file ) ) {
×
56
                        self::missing_autoloader_notice();
×
57
                        return false;
×
58
                }
59

60
                return (bool) require_once $autoloader_file; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable -- Autoloader is a Composer file.
×
61
        }
62

63
        /**
64
         * Displays a notice if the autoloader is missing.
65
         */
66
        protected static function missing_autoloader_notice(): void {
67
                $error_message = __( 'WPGraphQL for RankMath: The Composer autoloader was not found. If you installed the plugin from the GitHub source code, make sure to run `composer install`.', 'wp-graphql-rank-math' );
×
68

69
                if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
×
70
                        error_log( esc_html( $error_message ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- This is a development notice.
×
71
                }
72

73
                $hooks = [
×
74
                        'admin_notices',
×
75
                        'network_admin_notices',
×
76
                ];
×
77

78
                foreach ( $hooks as $hook ) {
×
79
                        add_action(
×
80
                                $hook,
×
81
                                static function () use ( $error_message ) {
×
82
                                        ?>
×
83
                                        <div class="error notice">
×
84
                                                <p>
×
85
                                                        <?php echo esc_html( $error_message ); ?>
×
86
                                                </p>
×
87
                                        </div>
×
88
                                        <?php
×
89
                                }
×
90
                        );
×
91
                }
92
        }
93
}
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