Skip to content

Commit

Permalink
PHPCS: Implement ClassStructure rule (#12912)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedmonkey committed Jan 9, 2023
1 parent d06a10b commit 731f64a
Show file tree
Hide file tree
Showing 61 changed files with 2,614 additions and 2,590 deletions.
70 changes: 35 additions & 35 deletions includes/AMP/Sanitization.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,41 @@ public function sanitize_document( Document $document ): void {
$this->ensure_required_markup( $document, $result['scripts'] );
}

/**
* Validation error callback.
*
* @since 1.1.0
*
* @see AMP_Validation_Error_Taxonomy::get_validation_error_sanitization
*
* @param array{code: string} $error Error info, especially code.
* @param array{node?: DOMElement|DOMNode} $data Additional data, including the node.
* @return bool Whether the validation error should be sanitized.
*/
public function validation_error_callback( array $error, array $data = [] ): bool {
/**
* Filters whether the validation error should be sanitized.
*
* Returning true this indicates that the validation error is acceptable
* and should not be considered a blocker to render AMP. Returning null
* means that the default status should be used.
*
* Note that the $node is not passed here to ensure that the filter can be
* applied on validation errors that have been stored. Likewise, the $sources
* are also omitted because these are only available during an explicit
* validation request and so they are not suitable for plugins to vary
* sanitization by.
*
* @since 1.1.0
*
* @see AMP_Validation_Manager::is_sanitization_auto_accepted() Which controls whether an error is initially accepted or rejected for sanitization.
*
* @param bool $sanitized Whether the validation error should be sanitized.
* @param array $error Validation error being sanitized.
*/
return apply_filters( 'web_stories_amp_validation_error_sanitized', true, $error );
}

/**
* Adds missing scripts.
*
Expand Down Expand Up @@ -509,39 +544,4 @@ protected function get_sanitizers(): array {

return $sanitizers;
}

/**
* Validation error callback.
*
* @since 1.1.0
*
* @see AMP_Validation_Error_Taxonomy::get_validation_error_sanitization
*
* @param array{code: string} $error Error info, especially code.
* @param array{node?: DOMElement|DOMNode} $data Additional data, including the node.
* @return bool Whether the validation error should be sanitized.
*/
public function validation_error_callback( array $error, array $data = [] ): bool {
/**
* Filters whether the validation error should be sanitized.
*
* Returning true this indicates that the validation error is acceptable
* and should not be considered a blocker to render AMP. Returning null
* means that the default status should be used.
*
* Note that the $node is not passed here to ensure that the filter can be
* applied on validation errors that have been stored. Likewise, the $sources
* are also omitted because these are only available during an explicit
* validation request and so they are not suitable for plugins to vary
* sanitization by.
*
* @since 1.1.0
*
* @see AMP_Validation_Manager::is_sanitization_auto_accepted() Which controls whether an error is initially accepted or rejected for sanitization.
*
* @param bool $sanitized Whether the validation error should be sanitized.
* @param array $error Validation error being sanitized.
*/
return apply_filters( 'web_stories_amp_validation_error_sanitized', true, $error );
}
}
56 changes: 28 additions & 28 deletions includes/AdSense.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,34 @@ public static function get_requirements(): array {
return [ 'settings' ];
}

/**
* Prints the <amp-story-auto-ads> tag for single stories.
*
* @since 1.3.0
*/
public function print_adsense_tag(): void {
$publisher = $this->get_publisher_id();
$slot = $this->get_slot_id();
$enabled = $this->is_enabled();

if ( ! $enabled || ! $publisher || ! $slot ) {
return;
}
?>
<amp-story-auto-ads>
<script type="application/json">
{
"ad-attributes": {
"type": "adsense",
"data-ad-client": "<?php echo esc_js( $publisher ); ?>",
"data-ad-slot": "<?php echo esc_js( $slot ); ?>"
}
}
</script>
</amp-story-auto-ads>
<?php
}

/**
* Returns the Google AdSense publisher ID.
*
Expand Down Expand Up @@ -116,32 +144,4 @@ private function get_slot_id(): string {
private function is_enabled(): bool {
return ( 'adsense' === $this->settings->get_setting( $this->settings::SETTING_NAME_AD_NETWORK, 'none' ) );
}

/**
* Prints the <amp-story-auto-ads> tag for single stories.
*
* @since 1.3.0
*/
public function print_adsense_tag(): void {
$publisher = $this->get_publisher_id();
$slot = $this->get_slot_id();
$enabled = $this->is_enabled();

if ( ! $enabled || ! $publisher || ! $slot ) {
return;
}
?>
<amp-story-auto-ads>
<script type="application/json">
{
"ad-attributes": {
"type": "adsense",
"data-ad-client": "<?php echo esc_js( $publisher ); ?>",
"data-ad-slot": "<?php echo esc_js( $slot ); ?>"
}
}
</script>
</amp-story-auto-ads>
<?php
}
}
50 changes: 25 additions & 25 deletions includes/Ad_Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,6 @@ public static function get_requirements(): array {
return [ 'settings' ];
}

/**
* Returns the Google Ad_Manager slot ID.
*
* @since 1.3.0
*
* @return string Slot ID.
*/
private function get_slot_id(): string {
/**
* Slot ID.
*
* @var string
*/
return $this->settings->get_setting( $this->settings::SETTING_NAME_AD_MANAGER_SLOT_ID );
}

/**
* Returns if Google manager is enabled.
*
* @since 1.3.0
*/
private function is_enabled(): bool {
return ( 'admanager' === $this->settings->get_setting( $this->settings::SETTING_NAME_AD_NETWORK, 'none' ) );
}

/**
* Prints the <amp-story-auto-ads> tag for single stories.
*
Expand Down Expand Up @@ -138,4 +113,29 @@ public function print_ad_manager_tag(): void {
</amp-story-auto-ads>
<?php
}

/**
* Returns the Google Ad_Manager slot ID.
*
* @since 1.3.0
*
* @return string Slot ID.
*/
private function get_slot_id(): string {
/**
* Slot ID.
*
* @var string
*/
return $this->settings->get_setting( $this->settings::SETTING_NAME_AD_MANAGER_SLOT_ID );
}

/**
* Returns if Google manager is enabled.
*
* @since 1.3.0
*/
private function is_enabled(): bool {
return ( 'admanager' === $this->settings->get_setting( $this->settings::SETTING_NAME_AD_NETWORK, 'none' ) );
}
}
74 changes: 37 additions & 37 deletions includes/Admin/Activation_Notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,43 @@ public function enqueue_assets( string $hook_suffix ): void {
);
}

/**
* Renders the plugin activation notice.
*
* @since 1.0.0
*/
public function render_notice(): void {
global $hook_suffix;

if ( ! $this->is_plugins_page( $hook_suffix ) ) {
return;
}

$network_wide = is_network_admin();
$flag = $this->get_activation_flag( $network_wide );

if ( ! $flag ) {
return;
}

// Unset the flag so that the notice only shows once.
$this->delete_activation_flag( $network_wide );

require_once WEBSTORIES_PLUGIN_DIR_PATH . 'includes/templates/admin/activation-notice.php';
}

/**
* Deletes the flag that the plugin has just been uninstalled.
*
* @since 1.26.0
*/
public function on_plugin_uninstall(): void {
if ( is_multisite() ) {
delete_site_option( self::OPTION_SHOW_ACTIVATION_NOTICE );
}
delete_option( self::OPTION_SHOW_ACTIVATION_NOTICE );
}

/**
* Returns script settings as an array.
*
Expand Down Expand Up @@ -183,31 +220,6 @@ protected function get_script_settings(): array {
];
}

/**
* Renders the plugin activation notice.
*
* @since 1.0.0
*/
public function render_notice(): void {
global $hook_suffix;

if ( ! $this->is_plugins_page( $hook_suffix ) ) {
return;
}

$network_wide = is_network_admin();
$flag = $this->get_activation_flag( $network_wide );

if ( ! $flag ) {
return;
}

// Unset the flag so that the notice only shows once.
$this->delete_activation_flag( $network_wide );

require_once WEBSTORIES_PLUGIN_DIR_PATH . 'includes/templates/admin/activation-notice.php';
}

/**
* Determines whether we're currently on the Plugins page or not.
*
Expand Down Expand Up @@ -272,16 +284,4 @@ protected function delete_activation_flag( bool $network_wide = false ): bool {

return delete_option( self::OPTION_SHOW_ACTIVATION_NOTICE );
}

/**
* Deletes the flag that the plugin has just been uninstalled.
*
* @since 1.26.0
*/
public function on_plugin_uninstall(): void {
if ( is_multisite() ) {
delete_site_option( self::OPTION_SHOW_ACTIVATION_NOTICE );
}
delete_option( self::OPTION_SHOW_ACTIVATION_NOTICE );
}
}

0 comments on commit 731f64a

Please sign in to comment.