@@ -3,108 +3,108 @@  | 
                                                    ||
| 3 | 3 | namespace Wordlift\Features;  | 
                                                        
| 4 | 4 | |
| 5 | 5 |  class Response_Adapter { | 
                                                        
| 6 | - const WL_FEATURES = '_wl_features';  | 
                                                        |
| 7 | - const WL_1 = 'wl1';  | 
                                                        |
| 8 | -  | 
                                                        |
| 9 | -	public function __construct() { | 
                                                        |
| 10 | -  | 
                                                        |
| 11 | - // Filter responses from the API calls to update the enabled features.  | 
                                                        |
| 12 | - add_filter( 'wl_api_service__response', array( $this, 'response' ), 10, 1 );  | 
                                                        |
| 13 | -  | 
                                                        |
| 14 | - // Initialize from `$_ENV`: this is currently required for Unit Tests, since `tests/bootstrap.php` loads WordLift  | 
                                                        |
| 15 | - // before it can actually query the enabled features via HTTP (mock), which would prevent files from being included.  | 
                                                        |
| 16 | - // $this->init_from_env();  | 
                                                        |
| 17 | -  | 
                                                        |
| 18 | -		// Register the `wl_features__enable__{feature-name}` filters. | 
                                                        |
| 19 | - $this->register_filters();  | 
                                                        |
| 20 | -  | 
                                                        |
| 21 | - // Hook to the updates to the features setting to refresh the features' filters.  | 
                                                        |
| 22 | - add_action( 'update_option_' . self::WL_FEATURES, array( $this, 'register_filters' ), 10, 0 );  | 
                                                        |
| 23 | -  | 
                                                        |
| 24 | - }  | 
                                                        |
| 25 | -  | 
                                                        |
| 26 | -	public function response( $response ) { | 
                                                        |
| 27 | -  | 
                                                        |
| 28 | - $headers = wp_remote_retrieve_headers( $response );  | 
                                                        |
| 29 | -  | 
                                                        |
| 30 | - // Bail out if the `wl1` header isn't defined.  | 
                                                        |
| 31 | -		if ( ! isset( $headers[ self::WL_1 ] ) ) { | 
                                                        |
| 32 | - return $response;  | 
                                                        |
| 33 | - }  | 
                                                        |
| 34 | - $wl1_as_base64_string = $headers[ self::WL_1 ];  | 
                                                        |
| 35 | - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode  | 
                                                        |
| 36 | - $wl1 = json_decode( base64_decode( $wl1_as_base64_string ), true );  | 
                                                        |
| 37 | -  | 
                                                        |
| 38 | - $updated_features = $wl1['features'];  | 
                                                        |
| 39 | -  | 
                                                        |
| 40 | - $existing_features = get_option( self::WL_FEATURES, array() );  | 
                                                        |
| 41 | -  | 
                                                        |
| 42 | - // Loop through updated features.  | 
                                                        |
| 43 | -		foreach ( $updated_features as $feature_slug => $new_value ) { | 
                                                        |
| 44 | -  | 
                                                        |
| 45 | - // We cant pass false because that indicates if the feature is active or not, null is used to represent the features which are  | 
                                                        |
| 46 | - // not set before.  | 
                                                        |
| 47 | - $old_value = array_key_exists( $feature_slug, $existing_features ) ? $existing_features[ $feature_slug ] : null;  | 
                                                        |
| 48 | -  | 
                                                        |
| 49 | -			if ( $old_value !== $new_value ) { | 
                                                        |
| 50 | - /**  | 
                                                        |
| 51 | - * @param $feature_slug string The feature slug.  | 
                                                        |
| 52 | - * @param $old_value null | boolean Null represents the feature flag was not set before.  | 
                                                        |
| 53 | - * @param $new_value boolean True or false.  | 
                                                        |
| 54 | - *  | 
                                                        |
| 55 | - * @since 3.32.1  | 
                                                        |
| 56 | -				 * Hook : `wl_feature__change__{feature_slug}` | 
                                                        |
| 57 | - * Action hook to be fired when there is a change in feature state.  | 
                                                        |
| 58 | - */  | 
                                                        |
| 59 | - do_action( "wl_feature__change__$feature_slug", $new_value, $old_value, $feature_slug );  | 
                                                        |
| 60 | - }  | 
                                                        |
| 61 | - }  | 
                                                        |
| 62 | -  | 
                                                        |
| 63 | -		if ( isset( $updated_features ) ) { | 
                                                        |
| 64 | -  | 
                                                        |
| 65 | -			if ( update_option( self::WL_FEATURES, (array) $updated_features, true ) ) { | 
                                                        |
| 66 | - $this->register_filters();  | 
                                                        |
| 67 | - }  | 
                                                        |
| 68 | - }  | 
                                                        |
| 69 | -  | 
                                                        |
| 70 | - return $response;  | 
                                                        |
| 71 | - }  | 
                                                        |
| 72 | -  | 
                                                        |
| 73 | - /**  | 
                                                        |
| 74 | - * Registers the feature filters.  | 
                                                        |
| 75 | - */  | 
                                                        |
| 76 | -	public function register_filters() { | 
                                                        |
| 77 | -  | 
                                                        |
| 78 | -		foreach ( (array) get_option( self::WL_FEATURES, array() ) as $name => $enabled ) { | 
                                                        |
| 79 | - // Remove previous filters.  | 
                                                        |
| 80 | -			remove_filter( "wl_feature__enable__${name}", '__return_true' ); | 
                                                        |
| 81 | -			remove_filter( "wl_feature__enable__${name}", '__return_false' ); | 
                                                        |
| 82 | -  | 
                                                        |
| 83 | - $callback = ( $enabled ? '__return_true' : '__return_false' );  | 
                                                        |
| 84 | -			add_filter( "wl_feature__enable__${name}", $callback ); | 
                                                        |
| 85 | - }  | 
                                                        |
| 86 | -  | 
                                                        |
| 87 | - }  | 
                                                        |
| 88 | -  | 
                                                        |
| 89 | -	private function init_from_env() { | 
                                                        |
| 90 | - $features = array_reduce(  | 
                                                        |
| 91 | - array_filter(  | 
                                                        |
| 92 | - array_keys( $_ENV ),  | 
                                                        |
| 93 | -				function ( $key ) { | 
                                                        |
| 94 | - return preg_match( '~^WL_FEATURES__.*~', $key );  | 
                                                        |
| 95 | - }  | 
                                                        |
| 96 | - ),  | 
                                                        |
| 97 | -			function ( $features, $env ) { | 
                                                        |
| 98 | - $name = strtolower( str_replace( '_', '-', substr( $env, strlen( 'WL_FEATURES__' ) ) ) );  | 
                                                        |
| 99 | - $value = wp_validate_boolean( getenv( $env ) );  | 
                                                        |
| 100 | - $features[ $name ] = $value;  | 
                                                        |
| 101 | -  | 
                                                        |
| 102 | - return $features;  | 
                                                        |
| 103 | - },  | 
                                                        |
| 104 | - array()  | 
                                                        |
| 105 | - );  | 
                                                        |
| 106 | -  | 
                                                        |
| 107 | - update_option( self::WL_FEATURES, (array) $features, true );  | 
                                                        |
| 108 | - }  | 
                                                        |
| 6 | + const WL_FEATURES = '_wl_features';  | 
                                                        |
| 7 | + const WL_1 = 'wl1';  | 
                                                        |
| 8 | +  | 
                                                        |
| 9 | +    public function __construct() { | 
                                                        |
| 10 | +  | 
                                                        |
| 11 | + // Filter responses from the API calls to update the enabled features.  | 
                                                        |
| 12 | + add_filter( 'wl_api_service__response', array( $this, 'response' ), 10, 1 );  | 
                                                        |
| 13 | +  | 
                                                        |
| 14 | + // Initialize from `$_ENV`: this is currently required for Unit Tests, since `tests/bootstrap.php` loads WordLift  | 
                                                        |
| 15 | + // before it can actually query the enabled features via HTTP (mock), which would prevent files from being included.  | 
                                                        |
| 16 | + // $this->init_from_env();  | 
                                                        |
| 17 | +  | 
                                                        |
| 18 | +        // Register the `wl_features__enable__{feature-name}` filters. | 
                                                        |
| 19 | + $this->register_filters();  | 
                                                        |
| 20 | +  | 
                                                        |
| 21 | + // Hook to the updates to the features setting to refresh the features' filters.  | 
                                                        |
| 22 | + add_action( 'update_option_' . self::WL_FEATURES, array( $this, 'register_filters' ), 10, 0 );  | 
                                                        |
| 23 | +  | 
                                                        |
| 24 | + }  | 
                                                        |
| 25 | +  | 
                                                        |
| 26 | +    public function response( $response ) { | 
                                                        |
| 27 | +  | 
                                                        |
| 28 | + $headers = wp_remote_retrieve_headers( $response );  | 
                                                        |
| 29 | +  | 
                                                        |
| 30 | + // Bail out if the `wl1` header isn't defined.  | 
                                                        |
| 31 | +        if ( ! isset( $headers[ self::WL_1 ] ) ) { | 
                                                        |
| 32 | + return $response;  | 
                                                        |
| 33 | + }  | 
                                                        |
| 34 | + $wl1_as_base64_string = $headers[ self::WL_1 ];  | 
                                                        |
| 35 | + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode  | 
                                                        |
| 36 | + $wl1 = json_decode( base64_decode( $wl1_as_base64_string ), true );  | 
                                                        |
| 37 | +  | 
                                                        |
| 38 | + $updated_features = $wl1['features'];  | 
                                                        |
| 39 | +  | 
                                                        |
| 40 | + $existing_features = get_option( self::WL_FEATURES, array() );  | 
                                                        |
| 41 | +  | 
                                                        |
| 42 | + // Loop through updated features.  | 
                                                        |
| 43 | +        foreach ( $updated_features as $feature_slug => $new_value ) { | 
                                                        |
| 44 | +  | 
                                                        |
| 45 | + // We cant pass false because that indicates if the feature is active or not, null is used to represent the features which are  | 
                                                        |
| 46 | + // not set before.  | 
                                                        |
| 47 | + $old_value = array_key_exists( $feature_slug, $existing_features ) ? $existing_features[ $feature_slug ] : null;  | 
                                                        |
| 48 | +  | 
                                                        |
| 49 | +            if ( $old_value !== $new_value ) { | 
                                                        |
| 50 | + /**  | 
                                                        |
| 51 | + * @param $feature_slug string The feature slug.  | 
                                                        |
| 52 | + * @param $old_value null | boolean Null represents the feature flag was not set before.  | 
                                                        |
| 53 | + * @param $new_value boolean True or false.  | 
                                                        |
| 54 | + *  | 
                                                        |
| 55 | + * @since 3.32.1  | 
                                                        |
| 56 | +                 * Hook : `wl_feature__change__{feature_slug}` | 
                                                        |
| 57 | + * Action hook to be fired when there is a change in feature state.  | 
                                                        |
| 58 | + */  | 
                                                        |
| 59 | + do_action( "wl_feature__change__$feature_slug", $new_value, $old_value, $feature_slug );  | 
                                                        |
| 60 | + }  | 
                                                        |
| 61 | + }  | 
                                                        |
| 62 | +  | 
                                                        |
| 63 | +        if ( isset( $updated_features ) ) { | 
                                                        |
| 64 | +  | 
                                                        |
| 65 | +            if ( update_option( self::WL_FEATURES, (array) $updated_features, true ) ) { | 
                                                        |
| 66 | + $this->register_filters();  | 
                                                        |
| 67 | + }  | 
                                                        |
| 68 | + }  | 
                                                        |
| 69 | +  | 
                                                        |
| 70 | + return $response;  | 
                                                        |
| 71 | + }  | 
                                                        |
| 72 | +  | 
                                                        |
| 73 | + /**  | 
                                                        |
| 74 | + * Registers the feature filters.  | 
                                                        |
| 75 | + */  | 
                                                        |
| 76 | +    public function register_filters() { | 
                                                        |
| 77 | +  | 
                                                        |
| 78 | +        foreach ( (array) get_option( self::WL_FEATURES, array() ) as $name => $enabled ) { | 
                                                        |
| 79 | + // Remove previous filters.  | 
                                                        |
| 80 | +            remove_filter( "wl_feature__enable__${name}", '__return_true' ); | 
                                                        |
| 81 | +            remove_filter( "wl_feature__enable__${name}", '__return_false' ); | 
                                                        |
| 82 | +  | 
                                                        |
| 83 | + $callback = ( $enabled ? '__return_true' : '__return_false' );  | 
                                                        |
| 84 | +            add_filter( "wl_feature__enable__${name}", $callback ); | 
                                                        |
| 85 | + }  | 
                                                        |
| 86 | +  | 
                                                        |
| 87 | + }  | 
                                                        |
| 88 | +  | 
                                                        |
| 89 | +    private function init_from_env() { | 
                                                        |
| 90 | + $features = array_reduce(  | 
                                                        |
| 91 | + array_filter(  | 
                                                        |
| 92 | + array_keys( $_ENV ),  | 
                                                        |
| 93 | +                function ( $key ) { | 
                                                        |
| 94 | + return preg_match( '~^WL_FEATURES__.*~', $key );  | 
                                                        |
| 95 | + }  | 
                                                        |
| 96 | + ),  | 
                                                        |
| 97 | +            function ( $features, $env ) { | 
                                                        |
| 98 | + $name = strtolower( str_replace( '_', '-', substr( $env, strlen( 'WL_FEATURES__' ) ) ) );  | 
                                                        |
| 99 | + $value = wp_validate_boolean( getenv( $env ) );  | 
                                                        |
| 100 | + $features[ $name ] = $value;  | 
                                                        |
| 101 | +  | 
                                                        |
| 102 | + return $features;  | 
                                                        |
| 103 | + },  | 
                                                        |
| 104 | + array()  | 
                                                        |
| 105 | + );  | 
                                                        |
| 106 | +  | 
                                                        |
| 107 | + update_option( self::WL_FEATURES, (array) $features, true );  | 
                                                        |
| 108 | + }  | 
                                                        |
| 109 | 109 | |
| 110 | 110 | }  | 
                                                        
@@ -9,7 +9,7 @@ discard block  | 
                                                    ||
| 9 | 9 |  	public function __construct() { | 
                                                        
| 10 | 10 | |
| 11 | 11 | // Filter responses from the API calls to update the enabled features.  | 
                                                        
| 12 | - add_filter( 'wl_api_service__response', array( $this, 'response' ), 10, 1 );  | 
                                                        |
| 12 | +		add_filter('wl_api_service__response', array($this, 'response'), 10, 1); | 
                                                        |
| 13 | 13 | |
| 14 | 14 | // Initialize from `$_ENV`: this is currently required for Unit Tests, since `tests/bootstrap.php` loads WordLift  | 
                                                        
| 15 | 15 | // before it can actually query the enabled features via HTTP (mock), which would prevent files from being included.  | 
                                                        
@@ -19,34 +19,34 @@ discard block  | 
                                                    ||
| 19 | 19 | $this->register_filters();  | 
                                                        
| 20 | 20 | |
| 21 | 21 | // Hook to the updates to the features setting to refresh the features' filters.  | 
                                                        
| 22 | - add_action( 'update_option_' . self::WL_FEATURES, array( $this, 'register_filters' ), 10, 0 );  | 
                                                        |
| 22 | +		add_action('update_option_'.self::WL_FEATURES, array($this, 'register_filters'), 10, 0); | 
                                                        |
| 23 | 23 | |
| 24 | 24 | }  | 
                                                        
| 25 | 25 | |
| 26 | -	public function response( $response ) { | 
                                                        |
| 26 | +	public function response($response) { | 
                                                        |
| 27 | 27 | |
| 28 | - $headers = wp_remote_retrieve_headers( $response );  | 
                                                        |
| 28 | + $headers = wp_remote_retrieve_headers($response);  | 
                                                        |
| 29 | 29 | |
| 30 | 30 | // Bail out if the `wl1` header isn't defined.  | 
                                                        
| 31 | -		if ( ! isset( $headers[ self::WL_1 ] ) ) { | 
                                                        |
| 31 | +		if ( ! isset($headers[self::WL_1])) { | 
                                                        |
| 32 | 32 | return $response;  | 
                                                        
| 33 | 33 | }  | 
                                                        
| 34 | - $wl1_as_base64_string = $headers[ self::WL_1 ];  | 
                                                        |
| 34 | + $wl1_as_base64_string = $headers[self::WL_1];  | 
                                                        |
| 35 | 35 | // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode  | 
                                                        
| 36 | - $wl1 = json_decode( base64_decode( $wl1_as_base64_string ), true );  | 
                                                        |
| 36 | + $wl1 = json_decode(base64_decode($wl1_as_base64_string), true);  | 
                                                        |
| 37 | 37 | |
| 38 | 38 | $updated_features = $wl1['features'];  | 
                                                        
| 39 | 39 | |
| 40 | - $existing_features = get_option( self::WL_FEATURES, array() );  | 
                                                        |
| 40 | + $existing_features = get_option(self::WL_FEATURES, array());  | 
                                                        |
| 41 | 41 | |
| 42 | 42 | // Loop through updated features.  | 
                                                        
| 43 | -		foreach ( $updated_features as $feature_slug => $new_value ) { | 
                                                        |
| 43 | +		foreach ($updated_features as $feature_slug => $new_value) { | 
                                                        |
| 44 | 44 | |
| 45 | 45 | // We cant pass false because that indicates if the feature is active or not, null is used to represent the features which are  | 
                                                        
| 46 | 46 | // not set before.  | 
                                                        
| 47 | - $old_value = array_key_exists( $feature_slug, $existing_features ) ? $existing_features[ $feature_slug ] : null;  | 
                                                        |
| 47 | + $old_value = array_key_exists($feature_slug, $existing_features) ? $existing_features[$feature_slug] : null;  | 
                                                        |
| 48 | 48 | |
| 49 | -			if ( $old_value !== $new_value ) { | 
                                                        |
| 49 | +			if ($old_value !== $new_value) { | 
                                                        |
| 50 | 50 | /**  | 
                                                        
| 51 | 51 | * @param $feature_slug string The feature slug.  | 
                                                        
| 52 | 52 | * @param $old_value null | boolean Null represents the feature flag was not set before.  | 
                                                        
@@ -56,13 +56,13 @@ discard block  | 
                                                    ||
| 56 | 56 |  				 * Hook : `wl_feature__change__{feature_slug}` | 
                                                        
| 57 | 57 | * Action hook to be fired when there is a change in feature state.  | 
                                                        
| 58 | 58 | */  | 
                                                        
| 59 | - do_action( "wl_feature__change__$feature_slug", $new_value, $old_value, $feature_slug );  | 
                                                        |
| 59 | +				do_action("wl_feature__change__$feature_slug", $new_value, $old_value, $feature_slug); | 
                                                        |
| 60 | 60 | }  | 
                                                        
| 61 | 61 | }  | 
                                                        
| 62 | 62 | |
| 63 | -		if ( isset( $updated_features ) ) { | 
                                                        |
| 63 | +		if (isset($updated_features)) { | 
                                                        |
| 64 | 64 | |
| 65 | -			if ( update_option( self::WL_FEATURES, (array) $updated_features, true ) ) { | 
                                                        |
| 65 | +			if (update_option(self::WL_FEATURES, (array) $updated_features, true)) { | 
                                                        |
| 66 | 66 | $this->register_filters();  | 
                                                        
| 67 | 67 | }  | 
                                                        
| 68 | 68 | }  | 
                                                        
@@ -75,13 +75,13 @@ discard block  | 
                                                    ||
| 75 | 75 | */  | 
                                                        
| 76 | 76 |  	public function register_filters() { | 
                                                        
| 77 | 77 | |
| 78 | -		foreach ( (array) get_option( self::WL_FEATURES, array() ) as $name => $enabled ) { | 
                                                        |
| 78 | +		foreach ((array) get_option(self::WL_FEATURES, array()) as $name => $enabled) { | 
                                                        |
| 79 | 79 | // Remove previous filters.  | 
                                                        
| 80 | -			remove_filter( "wl_feature__enable__${name}", '__return_true' ); | 
                                                        |
| 81 | -			remove_filter( "wl_feature__enable__${name}", '__return_false' ); | 
                                                        |
| 80 | +			remove_filter("wl_feature__enable__${name}", '__return_true'); | 
                                                        |
| 81 | +			remove_filter("wl_feature__enable__${name}", '__return_false'); | 
                                                        |
| 82 | 82 | |
| 83 | - $callback = ( $enabled ? '__return_true' : '__return_false' );  | 
                                                        |
| 84 | -			add_filter( "wl_feature__enable__${name}", $callback ); | 
                                                        |
| 83 | + $callback = ($enabled ? '__return_true' : '__return_false');  | 
                                                        |
| 84 | +			add_filter("wl_feature__enable__${name}", $callback); | 
                                                        |
| 85 | 85 | }  | 
                                                        
| 86 | 86 | |
| 87 | 87 | }  | 
                                                        
@@ -89,22 +89,22 @@ discard block  | 
                                                    ||
| 89 | 89 |  	private function init_from_env() { | 
                                                        
| 90 | 90 | $features = array_reduce(  | 
                                                        
| 91 | 91 | array_filter(  | 
                                                        
| 92 | - array_keys( $_ENV ),  | 
                                                        |
| 93 | -				function ( $key ) { | 
                                                        |
| 94 | - return preg_match( '~^WL_FEATURES__.*~', $key );  | 
                                                        |
| 92 | + array_keys($_ENV),  | 
                                                        |
| 93 | +				function($key) { | 
                                                        |
| 94 | +					return preg_match('~^WL_FEATURES__.*~', $key); | 
                                                        |
| 95 | 95 | }  | 
                                                        
| 96 | 96 | ),  | 
                                                        
| 97 | -			function ( $features, $env ) { | 
                                                        |
| 98 | - $name = strtolower( str_replace( '_', '-', substr( $env, strlen( 'WL_FEATURES__' ) ) ) );  | 
                                                        |
| 99 | - $value = wp_validate_boolean( getenv( $env ) );  | 
                                                        |
| 100 | - $features[ $name ] = $value;  | 
                                                        |
| 97 | +			function($features, $env) { | 
                                                        |
| 98 | +				$name              = strtolower(str_replace('_', '-', substr($env, strlen('WL_FEATURES__')))); | 
                                                        |
| 99 | + $value = wp_validate_boolean(getenv($env));  | 
                                                        |
| 100 | + $features[$name] = $value;  | 
                                                        |
| 101 | 101 | |
| 102 | 102 | return $features;  | 
                                                        
| 103 | 103 | },  | 
                                                        
| 104 | 104 | array()  | 
                                                        
| 105 | 105 | );  | 
                                                        
| 106 | 106 | |
| 107 | - update_option( self::WL_FEATURES, (array) $features, true );  | 
                                                        |
| 107 | + update_option(self::WL_FEATURES, (array) $features, true);  | 
                                                        |
| 108 | 108 | }  | 
                                                        
| 109 | 109 | |
| 110 | 110 | }  | 
                                                        
@@ -6,44 +6,44 @@  | 
                                                    ||
| 6 | 6 | |
| 7 | 7 |  class Api_Headers_Service { | 
                                                        
| 8 | 8 | |
| 9 | - private static $instance = null;  | 
                                                        |
| 10 | -  | 
                                                        |
| 11 | -	protected function __construct() { | 
                                                        |
| 12 | -  | 
                                                        |
| 13 | - }  | 
                                                        |
| 14 | -  | 
                                                        |
| 15 | - /**  | 
                                                        |
| 16 | - * This function is used to append WordPress endpoint data to every request made.  | 
                                                        |
| 17 | - *  | 
                                                        |
| 18 | - * @return array  | 
                                                        |
| 19 | - */  | 
                                                        |
| 20 | -	public function get_wp_headers() { | 
                                                        |
| 21 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores  | 
                                                        |
| 22 | - $is_plugin_subscription = apply_filters( 'wl_feature__enable__entity-types-professional', false ) ||  | 
                                                        |
| 23 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores  | 
                                                        |
| 24 | - apply_filters( 'wl_feature__enable__entity-types-business', false ) ||  | 
                                                        |
| 25 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores  | 
                                                        |
| 26 | - apply_filters( 'wl_feature__enable__entity-types-starter', false );  | 
                                                        |
| 27 | -  | 
                                                        |
| 28 | -		try { | 
                                                        |
| 29 | - return $is_plugin_subscription ? array(  | 
                                                        |
| 30 | - 'X-Wordlift-Plugin-Wp-Admin' => untrailingslashit( get_admin_url() ),  | 
                                                        |
| 31 | - 'X-Wordlift-Plugin-Wp-Json' => untrailingslashit( get_rest_url() ),  | 
                                                        |
| 32 | - ) : array();  | 
                                                        |
| 33 | -		} catch ( Exception $e ) { | 
                                                        |
| 34 | - return array();  | 
                                                        |
| 35 | - }  | 
                                                        |
| 36 | - }  | 
                                                        |
| 37 | -  | 
                                                        |
| 38 | - /**  | 
                                                        |
| 39 | - * @return Api_Headers_Service  | 
                                                        |
| 40 | - */  | 
                                                        |
| 41 | -	public static function get_instance() { | 
                                                        |
| 42 | -		if ( null === self::$instance ) { | 
                                                        |
| 43 | - self::$instance = new Api_Headers_Service();  | 
                                                        |
| 44 | - }  | 
                                                        |
| 45 | -  | 
                                                        |
| 46 | - return self::$instance;  | 
                                                        |
| 47 | - }  | 
                                                        |
| 9 | + private static $instance = null;  | 
                                                        |
| 10 | +  | 
                                                        |
| 11 | +    protected function __construct() { | 
                                                        |
| 12 | +  | 
                                                        |
| 13 | + }  | 
                                                        |
| 14 | +  | 
                                                        |
| 15 | + /**  | 
                                                        |
| 16 | + * This function is used to append WordPress endpoint data to every request made.  | 
                                                        |
| 17 | + *  | 
                                                        |
| 18 | + * @return array  | 
                                                        |
| 19 | + */  | 
                                                        |
| 20 | +    public function get_wp_headers() { | 
                                                        |
| 21 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores  | 
                                                        |
| 22 | + $is_plugin_subscription = apply_filters( 'wl_feature__enable__entity-types-professional', false ) ||  | 
                                                        |
| 23 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores  | 
                                                        |
| 24 | + apply_filters( 'wl_feature__enable__entity-types-business', false ) ||  | 
                                                        |
| 25 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores  | 
                                                        |
| 26 | + apply_filters( 'wl_feature__enable__entity-types-starter', false );  | 
                                                        |
| 27 | +  | 
                                                        |
| 28 | +        try { | 
                                                        |
| 29 | + return $is_plugin_subscription ? array(  | 
                                                        |
| 30 | + 'X-Wordlift-Plugin-Wp-Admin' => untrailingslashit( get_admin_url() ),  | 
                                                        |
| 31 | + 'X-Wordlift-Plugin-Wp-Json' => untrailingslashit( get_rest_url() ),  | 
                                                        |
| 32 | + ) : array();  | 
                                                        |
| 33 | +        } catch ( Exception $e ) { | 
                                                        |
| 34 | + return array();  | 
                                                        |
| 35 | + }  | 
                                                        |
| 36 | + }  | 
                                                        |
| 37 | +  | 
                                                        |
| 38 | + /**  | 
                                                        |
| 39 | + * @return Api_Headers_Service  | 
                                                        |
| 40 | + */  | 
                                                        |
| 41 | +    public static function get_instance() { | 
                                                        |
| 42 | +        if ( null === self::$instance ) { | 
                                                        |
| 43 | + self::$instance = new Api_Headers_Service();  | 
                                                        |
| 44 | + }  | 
                                                        |
| 45 | +  | 
                                                        |
| 46 | + return self::$instance;  | 
                                                        |
| 47 | + }  | 
                                                        |
| 48 | 48 | |
| 49 | 49 | }  | 
                                                        
@@ -19,18 +19,18 @@ discard block  | 
                                                    ||
| 19 | 19 | */  | 
                                                        
| 20 | 20 |  	public function get_wp_headers() { | 
                                                        
| 21 | 21 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores  | 
                                                        
| 22 | - $is_plugin_subscription = apply_filters( 'wl_feature__enable__entity-types-professional', false ) ||  | 
                                                        |
| 22 | +		$is_plugin_subscription = apply_filters('wl_feature__enable__entity-types-professional', false) || | 
                                                        |
| 23 | 23 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores  | 
                                                        
| 24 | - apply_filters( 'wl_feature__enable__entity-types-business', false ) ||  | 
                                                        |
| 24 | +								  apply_filters('wl_feature__enable__entity-types-business', false) || | 
                                                        |
| 25 | 25 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores  | 
                                                        
| 26 | - apply_filters( 'wl_feature__enable__entity-types-starter', false );  | 
                                                        |
| 26 | +								  apply_filters('wl_feature__enable__entity-types-starter', false); | 
                                                        |
| 27 | 27 | |
| 28 | 28 |  		try { | 
                                                        
| 29 | 29 | return $is_plugin_subscription ? array(  | 
                                                        
| 30 | - 'X-Wordlift-Plugin-Wp-Admin' => untrailingslashit( get_admin_url() ),  | 
                                                        |
| 31 | - 'X-Wordlift-Plugin-Wp-Json' => untrailingslashit( get_rest_url() ),  | 
                                                        |
| 30 | + 'X-Wordlift-Plugin-Wp-Admin' => untrailingslashit(get_admin_url()),  | 
                                                        |
| 31 | + 'X-Wordlift-Plugin-Wp-Json' => untrailingslashit(get_rest_url()),  | 
                                                        |
| 32 | 32 | ) : array();  | 
                                                        
| 33 | -		} catch ( Exception $e ) { | 
                                                        |
| 33 | +		} catch (Exception $e) { | 
                                                        |
| 34 | 34 | return array();  | 
                                                        
| 35 | 35 | }  | 
                                                        
| 36 | 36 | }  | 
                                                        
@@ -39,7 +39,7 @@ discard block  | 
                                                    ||
| 39 | 39 | * @return Api_Headers_Service  | 
                                                        
| 40 | 40 | */  | 
                                                        
| 41 | 41 |  	public static function get_instance() { | 
                                                        
| 42 | -		if ( null === self::$instance ) { | 
                                                        |
| 42 | +		if (null === self::$instance) { | 
                                                        |
| 43 | 43 | self::$instance = new Api_Headers_Service();  | 
                                                        
| 44 | 44 | }  | 
                                                        
| 45 | 45 | |
@@ -3,14 +3,14 @@ discard block  | 
                                                    ||
| 3 | 3 | // autoload.php @generated by Composer  | 
                                                        
| 4 | 4 | |
| 5 | 5 |  if (PHP_VERSION_ID < 50600) { | 
                                                        
| 6 | -    if (!headers_sent()) { | 
                                                        |
| 6 | +    if ( ! headers_sent()) { | 
                                                        |
| 7 | 7 |          header('HTTP/1.1 500 Internal Server Error'); | 
                                                        
| 8 | 8 | }  | 
                                                        
| 9 | 9 | $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;  | 
                                                        
| 10 | -    if (!ini_get('display_errors')) { | 
                                                        |
| 10 | +    if ( ! ini_get('display_errors')) { | 
                                                        |
| 11 | 11 |          if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { | 
                                                        
| 12 | 12 | fwrite(STDERR, $err);  | 
                                                        
| 13 | -        } elseif (!headers_sent()) { | 
                                                        |
| 13 | +        } elseif ( ! headers_sent()) { | 
                                                        |
| 14 | 14 | echo $err;  | 
                                                        
| 15 | 15 | }  | 
                                                        
| 16 | 16 | }  | 
                                                        
@@ -20,6 +20,6 @@ discard block  | 
                                                    ||
| 20 | 20 | );  | 
                                                        
| 21 | 21 | }  | 
                                                        
| 22 | 22 | |
| 23 | -require_once __DIR__ . '/composer/autoload_real.php';  | 
                                                        |
| 23 | +require_once __DIR__.'/composer/autoload_real.php';  | 
                                                        |
| 24 | 24 | |
| 25 | 25 | return ComposerAutoloaderInitef483cd71d95713e835d5bdb5fbb7144::getLoader();  | 
                                                        
@@ -9,7 +9,7 @@ discard block  | 
                                                    ||
| 9 | 9 | public static function loadClassLoader($class)  | 
                                                        
| 10 | 10 |      { | 
                                                        
| 11 | 11 |          if ('Wordlift_Modules_Plugin_Diagnostics_Composer\Autoload\ClassLoader' === $class) { | 
                                                        
| 12 | - require __DIR__ . '/ClassLoader.php';  | 
                                                        |
| 12 | + require __DIR__.'/ClassLoader.php';  | 
                                                        |
| 13 | 13 | }  | 
                                                        
| 14 | 14 | }  | 
                                                        
| 15 | 15 | |
@@ -26,7 +26,7 @@ discard block  | 
                                                    ||
| 26 | 26 | self::$loader = $loader = new \Wordlift_Modules_Plugin_Diagnostics_Composer\Autoload\ClassLoader(\dirname(__DIR__));  | 
                                                        
| 27 | 27 |          spl_autoload_unregister(array('ComposerAutoloaderInitef483cd71d95713e835d5bdb5fbb7144', 'loadClassLoader')); | 
                                                        
| 28 | 28 | |
| 29 | - require __DIR__ . '/autoload_static.php';  | 
                                                        |
| 29 | + require __DIR__.'/autoload_static.php';  | 
                                                        |
| 30 | 30 | call_user_func(\Wordlift_Modules_Plugin_Diagnostics_Composer\Autoload\ComposerStaticInitef483cd71d95713e835d5bdb5fbb7144::getInitializer($loader));  | 
                                                        
| 31 | 31 | |
| 32 | 32 | $loader->setClassMapAuthoritative(true);  | 
                                                        
@@ -114,7 +114,7 @@ discard block  | 
                                                    ||
| 114 | 114 | */  | 
                                                        
| 115 | 115 | public function getPrefixes()  | 
                                                        
| 116 | 116 |      { | 
                                                        
| 117 | -        if (!empty($this->prefixesPsr0)) { | 
                                                        |
| 117 | +        if ( ! empty($this->prefixesPsr0)) { | 
                                                        |
| 118 | 118 |              return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); | 
                                                        
| 119 | 119 | }  | 
                                                        
| 120 | 120 | |
@@ -180,7 +180,7 @@ discard block  | 
                                                    ||
| 180 | 180 | public function add($prefix, $paths, $prepend = false)  | 
                                                        
| 181 | 181 |      { | 
                                                        
| 182 | 182 | $paths = (array) $paths;  | 
                                                        
| 183 | -        if (!$prefix) { | 
                                                        |
| 183 | +        if ( ! $prefix) { | 
                                                        |
| 184 | 184 |              if ($prepend) { | 
                                                        
| 185 | 185 | $this->fallbackDirsPsr0 = array_merge(  | 
                                                        
| 186 | 186 | $paths,  | 
                                                        
@@ -197,7 +197,7 @@ discard block  | 
                                                    ||
| 197 | 197 | }  | 
                                                        
| 198 | 198 | |
| 199 | 199 | $first = $prefix[0];  | 
                                                        
| 200 | -        if (!isset($this->prefixesPsr0[$first][$prefix])) { | 
                                                        |
| 200 | +        if ( ! isset($this->prefixesPsr0[$first][$prefix])) { | 
                                                        |
| 201 | 201 | $this->prefixesPsr0[$first][$prefix] = $paths;  | 
                                                        
| 202 | 202 | |
| 203 | 203 | return;  | 
                                                        
@@ -230,7 +230,7 @@ discard block  | 
                                                    ||
| 230 | 230 | public function addPsr4($prefix, $paths, $prepend = false)  | 
                                                        
| 231 | 231 |      { | 
                                                        
| 232 | 232 | $paths = (array) $paths;  | 
                                                        
| 233 | -        if (!$prefix) { | 
                                                        |
| 233 | +        if ( ! $prefix) { | 
                                                        |
| 234 | 234 | // Register directories for the root namespace.  | 
                                                        
| 235 | 235 |              if ($prepend) { | 
                                                        
| 236 | 236 | $this->fallbackDirsPsr4 = array_merge(  | 
                                                        
@@ -243,7 +243,7 @@ discard block  | 
                                                    ||
| 243 | 243 | $paths  | 
                                                        
| 244 | 244 | );  | 
                                                        
| 245 | 245 | }  | 
                                                        
| 246 | -        } elseif (!isset($this->prefixDirsPsr4[$prefix])) { | 
                                                        |
| 246 | +        } elseif ( ! isset($this->prefixDirsPsr4[$prefix])) { | 
                                                        |
| 247 | 247 | // Register directories for a new namespace.  | 
                                                        
| 248 | 248 | $length = strlen($prefix);  | 
                                                        
| 249 | 249 |              if ('\\' !== $prefix[$length - 1]) { | 
                                                        
@@ -277,7 +277,7 @@ discard block  | 
                                                    ||
| 277 | 277 | */  | 
                                                        
| 278 | 278 | public function set($prefix, $paths)  | 
                                                        
| 279 | 279 |      { | 
                                                        
| 280 | -        if (!$prefix) { | 
                                                        |
| 280 | +        if ( ! $prefix) { | 
                                                        |
| 281 | 281 | $this->fallbackDirsPsr0 = (array) $paths;  | 
                                                        
| 282 | 282 |          } else { | 
                                                        
| 283 | 283 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;  | 
                                                        
@@ -297,7 +297,7 @@ discard block  | 
                                                    ||
| 297 | 297 | */  | 
                                                        
| 298 | 298 | public function setPsr4($prefix, $paths)  | 
                                                        
| 299 | 299 |      { | 
                                                        
| 300 | -        if (!$prefix) { | 
                                                        |
| 300 | +        if ( ! $prefix) { | 
                                                        |
| 301 | 301 | $this->fallbackDirsPsr4 = (array) $paths;  | 
                                                        
| 302 | 302 |          } else { | 
                                                        
| 303 | 303 | $length = strlen($prefix);  | 
                                                        
@@ -492,18 +492,18 @@ discard block  | 
                                                    ||
| 492 | 492 | private function findFileWithExtension($class, $ext)  | 
                                                        
| 493 | 493 |      { | 
                                                        
| 494 | 494 | // PSR-4 lookup  | 
                                                        
| 495 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;  | 
                                                        |
| 495 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext;  | 
                                                        |
| 496 | 496 | |
| 497 | 497 | $first = $class[0];  | 
                                                        
| 498 | 498 |          if (isset($this->prefixLengthsPsr4[$first])) { | 
                                                        
| 499 | 499 | $subPath = $class;  | 
                                                        
| 500 | 500 |              while (false !== $lastPos = strrpos($subPath, '\\')) { | 
                                                        
| 501 | 501 | $subPath = substr($subPath, 0, $lastPos);  | 
                                                        
| 502 | - $search = $subPath . '\\';  | 
                                                        |
| 502 | + $search = $subPath.'\\';  | 
                                                        |
| 503 | 503 |                  if (isset($this->prefixDirsPsr4[$search])) { | 
                                                        
| 504 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);  | 
                                                        |
| 504 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1);  | 
                                                        |
| 505 | 505 |                      foreach ($this->prefixDirsPsr4[$search] as $dir) { | 
                                                        
| 506 | -                        if (file_exists($file = $dir . $pathEnd)) { | 
                                                        |
| 506 | +                        if (file_exists($file = $dir.$pathEnd)) { | 
                                                        |
| 507 | 507 | return $file;  | 
                                                        
| 508 | 508 | }  | 
                                                        
| 509 | 509 | }  | 
                                                        
@@ -513,7 +513,7 @@ discard block  | 
                                                    ||
| 513 | 513 | |
| 514 | 514 | // PSR-4 fallback dirs  | 
                                                        
| 515 | 515 |          foreach ($this->fallbackDirsPsr4 as $dir) { | 
                                                        
| 516 | -            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { | 
                                                        |
| 516 | +            if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { | 
                                                        |
| 517 | 517 | return $file;  | 
                                                        
| 518 | 518 | }  | 
                                                        
| 519 | 519 | }  | 
                                                        
@@ -525,14 +525,14 @@ discard block  | 
                                                    ||
| 525 | 525 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);  | 
                                                        
| 526 | 526 |          } else { | 
                                                        
| 527 | 527 | // PEAR-like class name  | 
                                                        
| 528 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;  | 
                                                        |
| 528 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext;  | 
                                                        |
| 529 | 529 | }  | 
                                                        
| 530 | 530 | |
| 531 | 531 |          if (isset($this->prefixesPsr0[$first])) { | 
                                                        
| 532 | 532 |              foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { | 
                                                        
| 533 | 533 |                  if (0 === strpos($class, $prefix)) { | 
                                                        
| 534 | 534 |                      foreach ($dirs as $dir) { | 
                                                        
| 535 | -                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { | 
                                                        |
| 535 | +                        if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { | 
                                                        |
| 536 | 536 | return $file;  | 
                                                        
| 537 | 537 | }  | 
                                                        
| 538 | 538 | }  | 
                                                        
@@ -542,7 +542,7 @@ discard block  | 
                                                    ||
| 542 | 542 | |
| 543 | 543 | // PSR-0 fallback dirs  | 
                                                        
| 544 | 544 |          foreach ($this->fallbackDirsPsr0 as $dir) { | 
                                                        
| 545 | -            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { | 
                                                        |
| 545 | +            if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { | 
                                                        |
| 546 | 546 | return $file;  | 
                                                        
| 547 | 547 | }  | 
                                                        
| 548 | 548 | }  | 
                                                        
@@ -6,17 +6,17 @@  | 
                                                    ||
| 6 | 6 | |
| 7 | 7 | class ComposerStaticInitef483cd71d95713e835d5bdb5fbb7144  | 
                                                        
| 8 | 8 |  { | 
                                                        
| 9 | - public static $classMap = array (  | 
                                                        |
| 10 | - 'ComposerAutoloaderInitef483cd71d95713e835d5bdb5fbb7144' => __DIR__ . '/..' . '/composer/autoload_real.php',  | 
                                                        |
| 11 | - 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',  | 
                                                        |
| 12 | - 'Wordlift\\Modules\\Plugin_Diagnostics\\Plugin_Diagnostics_API' => __DIR__ . '/../..' . '/Plugin_Diagnostics_API.php',  | 
                                                        |
| 13 | - 'Wordlift_Modules_Plugin_Diagnostics_Composer\\Autoload\\ClassLoader' => __DIR__ . '/..' . '/composer/ClassLoader.php',  | 
                                                        |
| 14 | - 'Wordlift_Modules_Plugin_Diagnostics_Composer\\Autoload\\ComposerStaticInitef483cd71d95713e835d5bdb5fbb7144' => __DIR__ . '/..' . '/composer/autoload_static.php',  | 
                                                        |
| 9 | + public static $classMap = array(  | 
                                                        |
| 10 | + 'ComposerAutoloaderInitef483cd71d95713e835d5bdb5fbb7144' => __DIR__.'/..'.'/composer/autoload_real.php',  | 
                                                        |
| 11 | + 'Composer\\InstalledVersions' => __DIR__.'/..'.'/composer/InstalledVersions.php',  | 
                                                        |
| 12 | + 'Wordlift\\Modules\\Plugin_Diagnostics\\Plugin_Diagnostics_API' => __DIR__.'/../..'.'/Plugin_Diagnostics_API.php',  | 
                                                        |
| 13 | + 'Wordlift_Modules_Plugin_Diagnostics_Composer\\Autoload\\ClassLoader' => __DIR__.'/..'.'/composer/ClassLoader.php',  | 
                                                        |
| 14 | + 'Wordlift_Modules_Plugin_Diagnostics_Composer\\Autoload\\ComposerStaticInitef483cd71d95713e835d5bdb5fbb7144' => __DIR__.'/..'.'/composer/autoload_static.php',  | 
                                                        |
| 15 | 15 | );  | 
                                                        
| 16 | 16 | |
| 17 | 17 | public static function getInitializer(ClassLoader $loader)  | 
                                                        
| 18 | 18 |      { | 
                                                        
| 19 | -        return \Closure::bind(function () use ($loader) { | 
                                                        |
| 19 | +        return \Closure::bind(function() use ($loader) { | 
                                                        |
| 20 | 20 | $loader->classMap = ComposerStaticInitef483cd71d95713e835d5bdb5fbb7144::$classMap;  | 
                                                        
| 21 | 21 | |
| 22 | 22 | }, null, ClassLoader::class);  | 
                                                        
@@ -6,9 +6,9 @@  | 
                                                    ||
| 6 | 6 | $baseDir = dirname($vendorDir);  | 
                                                        
| 7 | 7 | |
| 8 | 8 | return array(  | 
                                                        
| 9 | - 'ComposerAutoloaderInitef483cd71d95713e835d5bdb5fbb7144' => $vendorDir . '/composer/autoload_real.php',  | 
                                                        |
| 10 | - 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',  | 
                                                        |
| 11 | - 'Wordlift\\Modules\\Plugin_Diagnostics\\Plugin_Diagnostics_API' => $baseDir . '/Plugin_Diagnostics_API.php',  | 
                                                        |
| 12 | - 'Wordlift_Modules_Plugin_Diagnostics_Composer\\Autoload\\ClassLoader' => $vendorDir . '/composer/ClassLoader.php',  | 
                                                        |
| 13 | - 'Wordlift_Modules_Plugin_Diagnostics_Composer\\Autoload\\ComposerStaticInitef483cd71d95713e835d5bdb5fbb7144' => $vendorDir . '/composer/autoload_static.php',  | 
                                                        |
| 9 | + 'ComposerAutoloaderInitef483cd71d95713e835d5bdb5fbb7144' => $vendorDir.'/composer/autoload_real.php',  | 
                                                        |
| 10 | + 'Composer\\InstalledVersions' => $vendorDir.'/composer/InstalledVersions.php',  | 
                                                        |
| 11 | + 'Wordlift\\Modules\\Plugin_Diagnostics\\Plugin_Diagnostics_API' => $baseDir.'/Plugin_Diagnostics_API.php',  | 
                                                        |
| 12 | + 'Wordlift_Modules_Plugin_Diagnostics_Composer\\Autoload\\ClassLoader' => $vendorDir.'/composer/ClassLoader.php',  | 
                                                        |
| 13 | + 'Wordlift_Modules_Plugin_Diagnostics_Composer\\Autoload\\ComposerStaticInitef483cd71d95713e835d5bdb5fbb7144' => $vendorDir.'/composer/autoload_static.php',  | 
                                                        |
| 14 | 14 | );  | 
                                                        
@@ -6,29 +6,29 @@  | 
                                                    ||
| 6 | 6 | |
| 7 | 7 |  class Plugin_Diagnostics_API { | 
                                                        
| 8 | 8 | |
| 9 | - /**  | 
                                                        |
| 10 | - * @var Api_Service  | 
                                                        |
| 11 | - */  | 
                                                        |
| 12 | - private $api_service;  | 
                                                        |
| 9 | + /**  | 
                                                        |
| 10 | + * @var Api_Service  | 
                                                        |
| 11 | + */  | 
                                                        |
| 12 | + private $api_service;  | 
                                                        |
| 13 | 13 | |
| 14 | - /**  | 
                                                        |
| 15 | - * @param Api_Service $api_service  | 
                                                        |
| 16 | - */  | 
                                                        |
| 17 | -	public function __construct( Api_Service $api_service ) { | 
                                                        |
| 18 | - $this->api_service = $api_service;  | 
                                                        |
| 19 | - }  | 
                                                        |
| 14 | + /**  | 
                                                        |
| 15 | + * @param Api_Service $api_service  | 
                                                        |
| 16 | + */  | 
                                                        |
| 17 | +    public function __construct( Api_Service $api_service ) { | 
                                                        |
| 18 | + $this->api_service = $api_service;  | 
                                                        |
| 19 | + }  | 
                                                        |
| 20 | 20 | |
| 21 | - /**  | 
                                                        |
| 22 | - * Update.  | 
                                                        |
| 23 | - *  | 
                                                        |
| 24 | - * @param $payload  | 
                                                        |
| 25 | - */  | 
                                                        |
| 26 | -	public function update( $payload ) { | 
                                                        |
| 27 | - $this->api_service->request(  | 
                                                        |
| 28 | - 'PUT',  | 
                                                        |
| 29 | - '/accounts/me/plugin/diagnostics/plugins-collection',  | 
                                                        |
| 30 | - array( 'content-type' => 'application/json' ),  | 
                                                        |
| 31 | - wp_json_encode( $payload )  | 
                                                        |
| 32 | - );  | 
                                                        |
| 33 | - }  | 
                                                        |
| 21 | + /**  | 
                                                        |
| 22 | + * Update.  | 
                                                        |
| 23 | + *  | 
                                                        |
| 24 | + * @param $payload  | 
                                                        |
| 25 | + */  | 
                                                        |
| 26 | +    public function update( $payload ) { | 
                                                        |
| 27 | + $this->api_service->request(  | 
                                                        |
| 28 | + 'PUT',  | 
                                                        |
| 29 | + '/accounts/me/plugin/diagnostics/plugins-collection',  | 
                                                        |
| 30 | + array( 'content-type' => 'application/json' ),  | 
                                                        |
| 31 | + wp_json_encode( $payload )  | 
                                                        |
| 32 | + );  | 
                                                        |
| 33 | + }  | 
                                                        |
| 34 | 34 | }  | 
                                                        
@@ -14,7 +14,7 @@ discard block  | 
                                                    ||
| 14 | 14 | /**  | 
                                                        
| 15 | 15 | * @param Api_Service $api_service  | 
                                                        
| 16 | 16 | */  | 
                                                        
| 17 | -	public function __construct( Api_Service $api_service ) { | 
                                                        |
| 17 | +	public function __construct(Api_Service $api_service) { | 
                                                        |
| 18 | 18 | $this->api_service = $api_service;  | 
                                                        
| 19 | 19 | }  | 
                                                        
| 20 | 20 | |
@@ -23,12 +23,12 @@ discard block  | 
                                                    ||
| 23 | 23 | *  | 
                                                        
| 24 | 24 | * @param $payload  | 
                                                        
| 25 | 25 | */  | 
                                                        
| 26 | -	public function update( $payload ) { | 
                                                        |
| 26 | +	public function update($payload) { | 
                                                        |
| 27 | 27 | $this->api_service->request(  | 
                                                        
| 28 | 28 | 'PUT',  | 
                                                        
| 29 | 29 | '/accounts/me/plugin/diagnostics/plugins-collection',  | 
                                                        
| 30 | - array( 'content-type' => 'application/json' ),  | 
                                                        |
| 31 | - wp_json_encode( $payload )  | 
                                                        |
| 30 | +			array('content-type' => 'application/json'), | 
                                                        |
| 31 | + wp_json_encode($payload)  | 
                                                        |
| 32 | 32 | );  | 
                                                        
| 33 | 33 | }  | 
                                                        
| 34 | 34 | }  | 
                                                        
@@ -86,7 +86,7 @@ discard block  | 
                                                    ||
| 86 | 86 | */  | 
                                                        
| 87 | 87 | public function checkPatches(Event $event)  | 
                                                        
| 88 | 88 |      { | 
                                                        
| 89 | -        if (!$this->isPatchingEnabled()) { | 
                                                        |
| 89 | +        if ( ! $this->isPatchingEnabled()) { | 
                                                        |
| 90 | 90 | return;  | 
                                                        
| 91 | 91 | }  | 
                                                        
| 92 | 92 |          try { | 
                                                        
@@ -119,14 +119,14 @@ discard block  | 
                                                    ||
| 119 | 119 | // Remove packages for which the patch set has changed.  | 
                                                        
| 120 | 120 | $promises = array();  | 
                                                        
| 121 | 121 |              foreach ($packages as $package) { | 
                                                        
| 122 | -                if (!$package instanceof AliasPackage) { | 
                                                        |
| 122 | +                if ( ! $package instanceof AliasPackage) { | 
                                                        |
| 123 | 123 | $package_name = $package->getName();  | 
                                                        
| 124 | 124 | $extra = $package->getExtra();  | 
                                                        
| 125 | 125 | $has_patches = isset($tmp_patches[$package_name]);  | 
                                                        
| 126 | 126 | $has_applied_patches = isset($extra['patches_applied']) && \count($extra['patches_applied']) > 0;  | 
                                                        
| 127 | -                    if ($has_patches && !$has_applied_patches || !$has_patches && $has_applied_patches || $has_patches && $has_applied_patches && $tmp_patches[$package_name] !== $extra['patches_applied']) { | 
                                                        |
| 127 | +                    if ($has_patches && ! $has_applied_patches || ! $has_patches && $has_applied_patches || $has_patches && $has_applied_patches && $tmp_patches[$package_name] !== $extra['patches_applied']) { | 
                                                        |
| 128 | 128 | $uninstallOperation = new UninstallOperation($package, 'Removing package so it can be re-installed and re-patched.');  | 
                                                        
| 129 | -                        $this->io->write('<info>Removing package ' . $package_name . ' so that it can be re-installed and re-patched.</info>'); | 
                                                        |
| 129 | +                        $this->io->write('<info>Removing package '.$package_name.' so that it can be re-installed and re-patched.</info>'); | 
                                                        |
| 130 | 130 | $promises[] = $installationManager->uninstall($localRepository, $uninstallOperation);  | 
                                                        
| 131 | 131 | }  | 
                                                        
| 132 | 132 | }  | 
                                                        
@@ -150,7 +150,7 @@ discard block  | 
                                                    ||
| 150 | 150 |          if (isset($this->patches['_patchesGathered'])) { | 
                                                        
| 151 | 151 |              $this->io->write('<info>Patches already gathered. Skipping</info>', \TRUE, IOInterface::VERBOSE); | 
                                                        
| 152 | 152 | return;  | 
                                                        
| 153 | -        } elseif (!$this->isPatchingEnabled()) { | 
                                                        |
| 153 | +        } elseif ( ! $this->isPatchingEnabled()) { | 
                                                        |
| 154 | 154 |              $this->io->write('<info>Patching is disabled. Skipping.</info>', \TRUE, IOInterface::VERBOSE); | 
                                                        
| 155 | 155 | return;  | 
                                                        
| 156 | 156 | }  | 
                                                        
@@ -191,7 +191,7 @@ discard block  | 
                                                    ||
| 191 | 191 |          if ($this->io->isVerbose()) { | 
                                                        
| 192 | 192 |              foreach ($this->patches as $package => $patches) { | 
                                                        
| 193 | 193 | $number = \count($patches);  | 
                                                        
| 194 | -                $this->io->write('<info>Found ' . $number . ' patches for ' . $package . '.</info>'); | 
                                                        |
| 194 | +                $this->io->write('<info>Found '.$number.' patches for '.$package.'.</info>'); | 
                                                        |
| 195 | 195 | }  | 
                                                        
| 196 | 196 | }  | 
                                                        
| 197 | 197 | // Make sure we don't gather patches again. Extra keys in $this->patches  | 
                                                        
@@ -237,12 +237,12 @@ discard block  | 
                                                    ||
| 237 | 237 | $msg = ' - Unknown error';  | 
                                                        
| 238 | 238 | break;  | 
                                                        
| 239 | 239 | }  | 
                                                        
| 240 | -                throw new \Exception('There was an error in the supplied patches file:' . $msg); | 
                                                        |
| 240 | +                throw new \Exception('There was an error in the supplied patches file:'.$msg); | 
                                                        |
| 241 | 241 | }  | 
                                                        
| 242 | 242 |              if (isset($patches['patches'])) { | 
                                                        
| 243 | 243 | $patches = $patches['patches'];  | 
                                                        
| 244 | 244 | return $patches;  | 
                                                        
| 245 | -            } elseif (!$patches) { | 
                                                        |
| 245 | +            } elseif ( ! $patches) { | 
                                                        |
| 246 | 246 |                  throw new \Exception('There was an error in the supplied patch file'); | 
                                                        
| 247 | 247 | }  | 
                                                        
| 248 | 248 |          } else { | 
                                                        
@@ -257,20 +257,20 @@ discard block  | 
                                                    ||
| 257 | 257 |      { | 
                                                        
| 258 | 258 | // Check if we should exit in failure.  | 
                                                        
| 259 | 259 | $extra = $this->composer->getPackage()->getExtra();  | 
                                                        
| 260 | -        $exitOnFailure = \getenv('COMPOSER_EXIT_ON_PATCH_FAILURE') || !empty($extra['composer-exit-on-patch-failure']); | 
                                                        |
| 261 | -        $skipReporting = \getenv('COMPOSER_PATCHES_SKIP_REPORTING') || !empty($extra['composer-patches-skip-reporting']); | 
                                                        |
| 260 | +        $exitOnFailure = \getenv('COMPOSER_EXIT_ON_PATCH_FAILURE') || ! empty($extra['composer-exit-on-patch-failure']); | 
                                                        |
| 261 | +        $skipReporting = \getenv('COMPOSER_PATCHES_SKIP_REPORTING') || ! empty($extra['composer-patches-skip-reporting']); | 
                                                        |
| 262 | 262 | // Get the package object for the current operation.  | 
                                                        
| 263 | 263 | $operation = $event->getOperation();  | 
                                                        
| 264 | 264 | /** @var PackageInterface $package */  | 
                                                        
| 265 | 265 | $package = $this->getPackageFromOperation($operation);  | 
                                                        
| 266 | 266 | $package_name = $package->getName();  | 
                                                        
| 267 | -        if (!isset($this->patches[$package_name])) { | 
                                                        |
| 267 | +        if ( ! isset($this->patches[$package_name])) { | 
                                                        |
| 268 | 268 |              if ($this->io->isVerbose()) { | 
                                                        
| 269 | -                $this->io->write('<info>No patches found for ' . $package_name . '.</info>'); | 
                                                        |
| 269 | +                $this->io->write('<info>No patches found for '.$package_name.'.</info>'); | 
                                                        |
| 270 | 270 | }  | 
                                                        
| 271 | 271 | return;  | 
                                                        
| 272 | 272 | }  | 
                                                        
| 273 | -        $this->io->write('  - Applying patches for <info>' . $package_name . '</info>'); | 
                                                        |
| 273 | +        $this->io->write('  - Applying patches for <info>'.$package_name.'</info>'); | 
                                                        |
| 274 | 274 | // Get the install path from the package object.  | 
                                                        
| 275 | 275 | $manager = $event->getComposer()->getInstallationManager();  | 
                                                        
| 276 | 276 | $install_path = $manager->getInstaller($package->getType())->getInstallPath($package);  | 
                                                        
@@ -282,14 +282,14 @@ discard block  | 
                                                    ||
| 282 | 282 | $extra = $localPackage->getExtra();  | 
                                                        
| 283 | 283 | $extra['patches_applied'] = array();  | 
                                                        
| 284 | 284 |          foreach ($this->patches[$package_name] as $description => $url) { | 
                                                        
| 285 | -            $this->io->write('    <info>' . $url . '</info> (<comment>' . $description . '</comment>)'); | 
                                                        |
| 285 | +            $this->io->write('    <info>'.$url.'</info> (<comment>'.$description.'</comment>)'); | 
                                                        |
| 286 | 286 |              try { | 
                                                        
| 287 | 287 | $this->eventDispatcher->dispatch(NULL, new PatchEvent(PatchEvents::PRE_PATCH_APPLY, $package, $url, $description));  | 
                                                        
| 288 | 288 | $this->getAndApplyPatch($downloader, $install_path, $url, $package);  | 
                                                        
| 289 | 289 | $this->eventDispatcher->dispatch(NULL, new PatchEvent(PatchEvents::POST_PATCH_APPLY, $package, $url, $description));  | 
                                                        
| 290 | 290 | $extra['patches_applied'][$description] = $url;  | 
                                                        
| 291 | 291 |              } catch (\Exception $e) { | 
                                                        
| 292 | -                $this->io->write('   <error>Could not apply patch! Skipping. The error was: ' . $e->getMessage() . '</error>'); | 
                                                        |
| 292 | +                $this->io->write('   <error>Could not apply patch! Skipping. The error was: '.$e->getMessage().'</error>'); | 
                                                        |
| 293 | 293 |                  if ($exitOnFailure) { | 
                                                        
| 294 | 294 |                      throw new \Exception("Cannot apply patch {$description} ({$url})!"); | 
                                                        
| 295 | 295 | }  | 
                                                        
@@ -315,7 +315,7 @@ discard block  | 
                                                    ||
| 315 | 315 |          } elseif ($operation instanceof UpdateOperation) { | 
                                                        
| 316 | 316 | $package = $operation->getTargetPackage();  | 
                                                        
| 317 | 317 |          } else { | 
                                                        
| 318 | -            throw new \Exception('Unknown operation: ' . \get_class($operation)); | 
                                                        |
| 318 | +            throw new \Exception('Unknown operation: '.\get_class($operation)); | 
                                                        |
| 319 | 319 | }  | 
                                                        
| 320 | 320 | return $package;  | 
                                                        
| 321 | 321 | }  | 
                                                        
@@ -335,7 +335,7 @@ discard block  | 
                                                    ||
| 335 | 335 | $filename = \realpath($patch_url);  | 
                                                        
| 336 | 336 |          } else { | 
                                                        
| 337 | 337 | // Generate random (but not cryptographically so) filename.  | 
                                                        
| 338 | - $filename = \uniqid(\sys_get_temp_dir() . '/') . ".patch";  | 
                                                        |
| 338 | + $filename = \uniqid(\sys_get_temp_dir().'/').".patch";  | 
                                                        |
| 339 | 339 | // Download file from remote filesystem to this location.  | 
                                                        
| 340 | 340 | $hostname = \parse_url($patch_url, \PHP_URL_HOST);  | 
                                                        
| 341 | 341 |              try { | 
                                                        
@@ -352,14 +352,14 @@ discard block  | 
                                                    ||
| 352 | 352 |          $patch_levels = array('-p1', '-p0', '-p2', '-p4'); | 
                                                        
| 353 | 353 | // Check for specified patch level for this package.  | 
                                                        
| 354 | 354 | $extra = $this->composer->getPackage()->getExtra();  | 
                                                        
| 355 | -        if (!empty($extra['patchLevel'][$package->getName()])) { | 
                                                        |
| 355 | +        if ( ! empty($extra['patchLevel'][$package->getName()])) { | 
                                                        |
| 356 | 356 | $patch_levels = array($extra['patchLevel'][$package->getName()]);  | 
                                                        
| 357 | 357 | }  | 
                                                        
| 358 | 358 | // Attempt to apply with git apply.  | 
                                                        
| 359 | 359 | $patched = $this->applyPatchWithGit($install_path, $patch_levels, $filename);  | 
                                                        
| 360 | 360 | // In some rare cases, git will fail to apply a patch, fallback to using  | 
                                                        
| 361 | 361 | // the 'patch' command.  | 
                                                        
| 362 | -        if (!$patched) { | 
                                                        |
| 362 | +        if ( ! $patched) { | 
                                                        |
| 363 | 363 |              foreach ($patch_levels as $patch_level) { | 
                                                        
| 364 | 364 | // --no-backup-if-mismatch here is a hack that fixes some  | 
                                                        
| 365 | 365 | // differences between how patch works on windows and unix.  | 
                                                        
@@ -374,7 +374,7 @@ discard block  | 
                                                    ||
| 374 | 374 | }  | 
                                                        
| 375 | 375 | // If the patch *still* isn't applied, then give up and throw an Exception.  | 
                                                        
| 376 | 376 | // Otherwise, let the user know it worked.  | 
                                                        
| 377 | -        if (!$patched) { | 
                                                        |
| 377 | +        if ( ! $patched) { | 
                                                        |
| 378 | 378 |              throw new \Exception("Cannot apply patch {$patch_url}"); | 
                                                        
| 379 | 379 | }  | 
                                                        
| 380 | 380 | }  | 
                                                        
@@ -387,7 +387,7 @@ discard block  | 
                                                    ||
| 387 | 387 | protected function isPatchingEnabled()  | 
                                                        
| 388 | 388 |      { | 
                                                        
| 389 | 389 | $extra = $this->composer->getPackage()->getExtra();  | 
                                                        
| 390 | -        if (empty($extra['patches']) && empty($extra['patches-ignore']) && !isset($extra['patches-file'])) { | 
                                                        |
| 390 | +        if (empty($extra['patches']) && empty($extra['patches-ignore']) && ! isset($extra['patches-file'])) { | 
                                                        |
| 391 | 391 | // The root package has no patches of its own, so only allow patching if  | 
                                                        
| 392 | 392 | // it has specifically opted in.  | 
                                                        
| 393 | 393 | return isset($extra['enable-patching']) ? $extra['enable-patching'] : \FALSE;  | 
                                                        
@@ -406,10 +406,10 @@ discard block  | 
                                                    ||
| 406 | 406 | $output = "This file was automatically generated by Composer Patches (https://github.com/cweagans/composer-patches)\n";  | 
                                                        
| 407 | 407 | $output .= "Patches applied to this directory:\n\n";  | 
                                                        
| 408 | 408 |          foreach ($patches as $description => $url) { | 
                                                        
| 409 | - $output .= $description . "\n";  | 
                                                        |
| 410 | - $output .= 'Source: ' . $url . "\n\n\n";  | 
                                                        |
| 409 | + $output .= $description."\n";  | 
                                                        |
| 410 | + $output .= 'Source: '.$url."\n\n\n";  | 
                                                        |
| 411 | 411 | }  | 
                                                        
| 412 | - \file_put_contents($directory . "/PATCHES.txt", $output);  | 
                                                        |
| 412 | + \file_put_contents($directory."/PATCHES.txt", $output);  | 
                                                        |
| 413 | 413 | }  | 
                                                        
| 414 | 414 | /**  | 
                                                        
| 415 | 415 | * Executes a shell command with escaping.  | 
                                                        
@@ -430,13 +430,13 @@ discard block  | 
                                                    ||
| 430 | 430 |          $command = \call_user_func_array('sprintf', $args); | 
                                                        
| 431 | 431 | $output = '';  | 
                                                        
| 432 | 432 |          if ($this->io->isVerbose()) { | 
                                                        
| 433 | -            $this->io->write('<comment>' . $command . '</comment>'); | 
                                                        |
| 433 | +            $this->io->write('<comment>'.$command.'</comment>'); | 
                                                        |
| 434 | 434 | $io = $this->io;  | 
                                                        
| 435 | -            $output = function ($type, $data) use($io) { | 
                                                        |
| 435 | +            $output = function($type, $data) use($io) { | 
                                                        |
| 436 | 436 |                  if ($type == Process::ERR) { | 
                                                        
| 437 | -                    $io->write('<error>' . $data . '</error>'); | 
                                                        |
| 437 | +                    $io->write('<error>'.$data.'</error>'); | 
                                                        |
| 438 | 438 |                  } else { | 
                                                        
| 439 | -                    $io->write('<comment>' . $data . '</comment>'); | 
                                                        |
| 439 | +                    $io->write('<comment>'.$data.'</comment>'); | 
                                                        |
| 440 | 440 | }  | 
                                                        
| 441 | 441 | };  | 
                                                        
| 442 | 442 | }  | 
                                                        
@@ -484,7 +484,7 @@ discard block  | 
                                                    ||
| 484 | 484 |      { | 
                                                        
| 485 | 485 | // Do not use git apply unless the install path is itself a git repo  | 
                                                        
| 486 | 486 | // @see https://stackoverflow.com/a/27283285  | 
                                                        
| 487 | -        if (!\is_dir($install_path . '/.git')) { | 
                                                        |
| 487 | +        if ( ! \is_dir($install_path.'/.git')) { | 
                                                        |
| 488 | 488 | return \FALSE;  | 
                                                        
| 489 | 489 | }  | 
                                                        
| 490 | 490 | $patched = \FALSE;  | 
                                                        
@@ -492,7 +492,7 @@ discard block  | 
                                                    ||
| 492 | 492 |              if ($this->io->isVerbose()) { | 
                                                        
| 493 | 493 | $comment = 'Testing ability to patch with git apply.';  | 
                                                        
| 494 | 494 | $comment .= ' This command may produce errors that can be safely ignored.';  | 
                                                        
| 495 | -                $this->io->write('<comment>' . $comment . '</comment>'); | 
                                                        |
| 495 | +                $this->io->write('<comment>'.$comment.'</comment>'); | 
                                                        |
| 496 | 496 | }  | 
                                                        
| 497 | 497 |              $checked = $this->executeCommand('git -C %s apply --check -v %s %s', $install_path, $patch_level, $filename); | 
                                                        
| 498 | 498 | $output = $this->executor->getErrorOutput();  |