Completed
Push — master ( c63cd8...c4c8fb )
by Claudio
10:23
created

Autoloader::missing_autoloader()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 0
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
1
<?php
2
/**
3
 * Includes the composer Autoloader used for packages and classes in the src/ directory.
4
 *
5
 * @package Automattic/WooCommerce
6
 */
7
8
namespace Automattic\WooCommerce;
9
10
defined( 'ABSPATH' ) || exit;
11
12
/**
13
 * Autoloader class.
14
 *
15
 * @since 3.7.0
16
 */
17
class Autoloader {
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
18
19
	/**
20
	 * Static-only class.
21
	 */
22
	private function __construct() {}
23
24
	/**
25
	 * Require the autoloader and return the result.
26
	 *
27
	 * If the autoloader is not present, let's log the failure and display a nice admin notice.
28
	 *
29
	 * @return boolean
30
	 */
31
	public static function init() {
32
		$autoloader = dirname( __DIR__ ) . '/vendor/autoload_packages.php';
33
34
		if ( ! is_readable( $autoloader ) ) {
35
			self::missing_autoloader();
36
			return false;
37
		}
38
39
		return require $autoloader;
40
	}
41
42
	/**
43
	 * If the autoloader is missing, add an admin notice.
44
	 */
45
	protected static function missing_autoloader() {
46
		if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
47
			error_log(  // phpcs:ignore
48
				esc_html__( 'Your installation of WooCommerce is incomplete. If you installed WooCommerce from GitHub, please refer to this document to set up your development environment: https://github.com/woocommerce/woocommerce/wiki/How-to-set-up-WooCommerce-development-environment', 'woocommerce' )
49
			);
50
		}
51
		add_action(
52
			'admin_notices',
53
			function() {
54
				?>
55
				<div class="notice notice-error">
56
					<p>
57
						<?php
58
						printf(
59
							/* translators: 1: is a link to a support document. 2: closing link */
60
							esc_html__( 'Your installation of WooCommerce is incomplete. If you installed WooCommerce from GitHub, %1$splease refer to this document%2$s to set up your development environment.', 'woocommerce' ),
61
							'<a href="' . esc_url( 'https://github.com/woocommerce/woocommerce/wiki/How-to-set-up-WooCommerce-development-environment' ) . '" target="_blank" rel="noopener noreferrer">',
62
							'</a>'
63
						);
64
						?>
65
					</p>
66
				</div>
67
				<?php
68
			}
69
		);
70
	}
71
}
72