Skip to content

Commit

Permalink
"Add PHP Code Sniffer ignores for snake case naming checks
Browse files Browse the repository at this point in the history
The project has been updated to add comments to ignore the 'not using snake case' warnings from PHP Code Sniffer. This was necessary as the property names used in the Node class provided by the core PHP library, do not follow snake case convention. These warnings were leading to unnecessary noise in the linting reports and were misleading as it could lead developers to think that there's something wrong with the project's own codebase. As this convention is not something developer can change, it is now simply ignored by the linter."
  • Loading branch information
attackant committed Oct 31, 2023
1 parent 4cb16ac commit d5f0ea9
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 30 deletions.
2 changes: 1 addition & 1 deletion includes/REST/apple-news-get-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @param array $data data from query args.
* @return array updated response.
*/
function get_settings_response( $data ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
function get_settings_response( $data ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
// Ensure Apple News is first initialized.
\Apple_News::has_uninitialized_error();

Expand Down
2 changes: 2 additions & 0 deletions includes/apple-exporter/class-component-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public static function get_component( $shortname, $html ) {
* @return array An array of components contained in the node.
*/
public static function get_components_from_node( $node ) {
/* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
$result = [];

foreach ( self::$components as $shortname => $class ) {
Expand Down Expand Up @@ -241,5 +242,6 @@ public static function get_components_from_node( $node ) {
}

return $result;
/* phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
}
}
2 changes: 1 addition & 1 deletion includes/apple-exporter/class-exporter-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,6 @@ public function nodes() {

// Find the first-level nodes of the body tag.
$body = $dom->getElementsByTagName( 'body' )->item( 0 );
return $body ? $body->childNodes : new \DOMNodeList();
return $body ? $body->childNodes : new \DOMNodeList(); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
}
}
3 changes: 3 additions & 0 deletions includes/apple-exporter/class-markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* @since 0.2.0
*/

/* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */

namespace Apple_Exporter;

use DOMElement;
Expand Down Expand Up @@ -306,3 +308,4 @@ private function parse_node_unordered_list( $node ) {
return $text . "\n\n";
}
}
/* phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
12 changes: 7 additions & 5 deletions includes/apple-exporter/components/class-body.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Body extends Component {
* @return array|null The node on success, or null on no match.
*/
public static function node_matches( $node ) {
/* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
// We are only interested in p, pre, ul and ol.
if ( ! in_array( $node->nodeName, [ 'p', 'pre', 'ul', 'ol' ], true ) ) {
return null;
Expand Down Expand Up @@ -88,6 +89,7 @@ public static function node_matches( $node ) {
$open,
$close
);
/* phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
}

/**
Expand Down Expand Up @@ -441,7 +443,7 @@ public function set_default_style() {

/**
* Determine whether to apply a dropcap style for the component.
*
*
* @param \Apple_Exporter\Theme $theme Object that stores theme level dropcap configuration.
* @param string $html The HTML to check for dropcap conditions. Should be the first paragraph of the post content.
*
Expand Down Expand Up @@ -471,17 +473,17 @@ private function dropcap_determination( $theme, $html ) {
$use_dropcap = false;
}

/**
/**
* Allows for filtering of the dropcap content before return.
*
*
* @since 2.4.0
*
*
* @param bool $use_dropcap Whether to apply a dropcap to this paragraph or not.
* @param string $html The post content to filter.
* @param \Apple_Exporter\Theme $theme The theme whose dropcap options are used.
* @param string $post_id The id of the post whose content we're parsing.
*/
return apply_filters( 'apple_news_dropcap', $use_dropcap, $html, $theme, $this->workspace->content_id );
return apply_filters( 'apple_news_dropcap', $use_dropcap, $html, $theme, $this->workspace->content_id );
}

/**
Expand Down
3 changes: 2 additions & 1 deletion includes/apple-exporter/components/class-embed-generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Embed_Generic extends Component {
* @return \DOMElement|null The node on success, or null on no match.
*/
public static function node_matches( $node ) {

/* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
// If we aren't on an element node, bail out.
if ( 1 !== $node->nodeType ) {
return null;
Expand All @@ -51,6 +51,7 @@ public static function node_matches( $node ) {
&& 'iframe' === $node->childNodes->item( 0 )->nodeName
) {
return $node;
/* phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
}

// Anything else isn't supported out of the box.
Expand Down
2 changes: 2 additions & 0 deletions includes/apple-exporter/components/class-facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function register_specs() {
*/
public static function node_matches( $node ) {

/* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
// Handling for a Gutenberg Facebook embed.
if (
'figure' === $node->nodeName
Expand Down Expand Up @@ -105,6 +106,7 @@ public static function node_matches( $node ) {
) {
return $node;
}
/* phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
}

// facebook not found.
Expand Down
6 changes: 3 additions & 3 deletions includes/apple-exporter/components/class-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ protected function build( $html ) {
}

// Determine if we have items.
if ( empty( $container->childNodes ) ) {
if ( empty( $container->childNodes ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
return;
}

// Loop through items and construct slides.
$theme = \Apple_Exporter\Theme::get_used();
$items = [];
foreach ( $container->childNodes as $item ) {
foreach ( $container->childNodes as $item ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase

// Convert item into HTML for regex matching.
$item_html = $item->ownerDocument->saveXML( $item );
$item_html = $item->ownerDocument->saveXML( $item ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase

// Try to get URL.
if ( ! preg_match( '/src="([^"]+)"/', $item_html, $matches ) ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/apple-exporter/components/class-heading.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public static function node_matches( $node ) {
self::$levels[ count( self::$levels ) - 1 ]
);

if ( ! preg_match( $regex, $node->nodeName ) ) {
if ( ! preg_match( $regex, $node->nodeName ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
return null;
}

$html = $node->ownerDocument->saveXML( $node );
$html = $node->ownerDocument->saveXML( $node ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
if ( preg_match( '#<img.*?>#si', $html ) ) {
return self::split_image( $html );
}
Expand Down
2 changes: 2 additions & 0 deletions includes/apple-exporter/components/class-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Image extends Component {
* @return \DOMElement|null The node on success, or null on no match.
*/
public static function node_matches( $node ) {
/* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */

$has_image_child = false;
// If this is a figure and it has children, see if we can find an image.
Expand All @@ -48,6 +49,7 @@ public static function node_matches( $node ) {
}

return null;
/* phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
}

/**
Expand Down
4 changes: 2 additions & 2 deletions includes/apple-exporter/components/class-instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public static function node_matches( $node ) {

// Handling for a Gutenberg Instagram embed.
if (
'figure' === $node->nodeName
'figure' === $node->nodeName // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
&& self::node_has_class( $node, 'wp-block-embed-instagram' )
) {
return $node;
}

// Handle Instagram oEmbed URLs.
if ( false !== self::get_instagram_url( $node->nodeValue ) ) {
if ( false !== self::get_instagram_url( $node->nodeValue ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
return $node;
}

Expand Down
4 changes: 2 additions & 2 deletions includes/apple-exporter/components/class-link-button.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Link_Button extends Component {
* @return \DOMElement|null The node on success, or null on no match.
*/
public static function node_matches( $node ) {
return 'a' === $node->nodeName
return 'a' === $node->nodeName // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
&& self::node_has_class( $node, 'wp-block-button__link' )
&& ! empty( $node->getAttribute( 'href' ) )
&& ! empty( $node->nodeValue )
&& ! empty( $node->nodeValue ) // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
? $node
: null;
}
Expand Down
6 changes: 3 additions & 3 deletions includes/apple-exporter/components/class-podcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Podcast extends Component {
* Look for node matches for this component.
*
* @param \DOMElement $node The node to examine for matches.
*
*
* @return \DOMElement|null The node on success, or null on no match.
*/
public static function node_matches( $node ) {
Expand Down Expand Up @@ -100,9 +100,9 @@ private static function get_podcast_url( $node ) {

// Remove iframe specific `embed.` prefix on podcast url.
$url = str_replace( 'embed.podcasts.apple.com', 'podcasts.apple.com', $url );

// Parse url into component parts.
$url_comps = parse_url( $url );
$url_comps = wp_parse_url( $url );

// Reassemble url without query params.
$url = sprintf(
Expand Down
2 changes: 1 addition & 1 deletion includes/apple-exporter/components/class-quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Quote extends Component {
* @return \DOMElement|null The node on success, or null on no match.
*/
public static function node_matches( $node ) {
return ( 'blockquote' === $node->nodeName || ( isset( $node->firstChild->tagName ) && 'blockquote' === $node->firstChild->tagName ) ) ? $node : null;
return ( 'blockquote' === $node->nodeName || ( isset( $node->firstChild->tagName ) && 'blockquote' === $node->firstChild->tagName ) ) ? $node : null; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
}

/**
Expand Down
4 changes: 2 additions & 2 deletions includes/apple-exporter/components/class-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public static function node_matches( $node ) {
(
self::node_has_class( $node, 'wp-block-table' ) &&
$node->hasChildNodes() &&
'table' === $node->firstChild->nodeName
'table' === $node->firstChild->nodeName // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
) ||
'table' === $node->nodeName ) {
'table' === $node->nodeName ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
return $node;
}

Expand Down
2 changes: 2 additions & 0 deletions includes/apple-exporter/components/class-tiktok.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TikTok extends Component {
* @return \DOMElement|null The node on success, or null on no match.
*/
public static function node_matches( $node ) {
/* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */

// Handling for a Gutenberg TikTok embed.
if (
Expand All @@ -45,6 +46,7 @@ public static function node_matches( $node ) {
&& self::node_has_class( $node, 'tiktok-embed' )
) {
return $node;
/* phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
}

return null;
Expand Down
10 changes: 5 additions & 5 deletions includes/apple-push-api/class-mime-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ private function build_attachment( $name, $filename, $content, $mime_type, $size
throw new Request_Exception(
sprintf(
// translators: token is an attachment filename.
__( 'The attachment %s could not be included in the request because it was empty.', 'apple-news' ),
esc_html( $filename )
esc_html__( 'The attachment %s could not be included in the request because it was empty.', 'apple-news' ),
$filename // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
)
);
}
Expand All @@ -221,9 +221,9 @@ private function build_attachment( $name, $filename, $content, $mime_type, $size
throw new Request_Exception(
sprintf(
// translators: first token is the filename, second is the file size.
__( 'The attachment %1$s could not be included in the request because its size was %2$s.', 'apple-news' ),
esc_html( $filename ),
esc_html( $size )
esc_html__( 'The attachment %1$s could not be included in the request because its size was %2$s.', 'apple-news' ),
$filename, // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
$size // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/admin/test-class-admin-apple-themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Apple_Exporter\Theme;

/**
*
* A class to test the Admin_Apple_Themes class.
*/
class Admin_Apple_Themes_Test extends Apple_News_Testcase {

Expand Down
2 changes: 1 addition & 1 deletion tests/mocks/class-bc-cms-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BC_CMS_API {
*
* @return array Array of the video's images retrieved.
*/
public function video_get_images( $video_id ) {
public function video_get_images( $video_id ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
return [
'poster' => [
'src' => 'https://cf-images.us-east-1.prod.boltdns.net/v1/jit/1234567890/abcd1234-ef56-ab78-cd90-efabcd123456/main/1280x720/1s234ms/match/image.jpg',
Expand Down

0 comments on commit d5f0ea9

Please sign in to comment.