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

AxeWP / wp-graphql-rank-math / 8579202484

06 Apr 2024 06:06AM UTC coverage: 91.473% (-0.9%) from 92.396%
8579202484

push

github

web-flow
chore!: refactor plugin instantiation (#86)

1 of 32 new or added lines in 2 files covered. (3.13%)

2564 of 2803 relevant lines covered (91.47%)

11.15 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.
NEW
30
                if ( defined( 'WPGRAPHQL_SEO_AUTOLOAD' ) && false === WPGRAPHQL_SEO_AUTOLOAD ) {
×
NEW
31
                        return true;
×
32
                }
33

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

NEW
38
                $autoloader      = dirname( __DIR__ ) . '/vendor/autoload.php';
×
NEW
39
                self::$is_loaded = self::require_autoloader( $autoloader );
×
40

NEW
41
                return self::$is_loaded;
×
42
        }
43

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

NEW
55
                return (bool) require_once $autoloader_file; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable -- Autoloader is a Composer file.
×
56
        }
57

58
        /**
59
         * Displays a notice if the autoloader is missing.
60
         */
61
        protected static function missing_autoloader_notice(): void {
NEW
62
                $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' );
×
63

NEW
64
                if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
×
NEW
65
                        error_log( esc_html( $error_message ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- This is a development notice.
×
66
                }
67

NEW
68
                $hooks = [
×
NEW
69
                        'admin_notices',
×
NEW
70
                        'network_admin_notices',
×
NEW
71
                ];
×
72

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