PHPCS: Enable UnusedFunctionParameter sniff (#911)

* PHPCS: Enable UnusedFunctionParameter sniff

* Add unit test for at_title shortcode

* Remove unused variables in at_title shortcode

* Remove remaining unused function parameters.

* PHPCS: Enable UnusedVariable sniff (#912)

---------

Co-authored-by: Matthias Pfefferle <pfefferle@users.noreply.github.com>
This commit is contained in:
Konstantin Obenland 2024-10-04 11:28:31 -05:00 committed by GitHub
parent 204afdfb9d
commit 2538a2f1b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 41 additions and 70 deletions

View file

@ -65,13 +65,9 @@ class Shortcodes {
/**
* Generates output for the 'ap_title' Shortcode
*
* @param array $atts The Shortcode attributes.
* @param string $content The ActivityPub post-content.
* @param string $tag The tag/name of the Shortcode.
*
* @return string The post title.
*/
public static function title( $atts, $content, $tag ) {
public static function title() {
$item = self::get_item();
if ( ! $item ) {
@ -283,13 +279,9 @@ class Shortcodes {
/**
* Generates output for the 'ap_hashcats' Shortcode
*
* @param array $atts The Shortcode attributes.
* @param string $content The ActivityPub post-content.
* @param string $tag The tag/name of the Shortcode.
*
* @return string The post categories as hashtags.
*/
public static function hashcats( $atts, $content, $tag ) {
public static function hashcats() {
$item = self::get_item();
if ( ! $item ) {
@ -318,13 +310,9 @@ class Shortcodes {
/**
* Generates output for the 'ap_author' Shortcode
*
* @param array $atts The Shortcode attributes.
* @param string $content The ActivityPub post-content.
* @param string $tag The tag/name of the Shortcode.
*
* @return string The author name.
*/
public static function author( $atts, $content, $tag ) {
public static function author() {
$item = self::get_item();
if ( ! $item ) {
@ -344,13 +332,9 @@ class Shortcodes {
/**
* Generates output for the 'ap_authorurl' Shortcode
*
* @param array $atts The Shortcode attributes.
* @param string $content The ActivityPub post-content.
* @param string $tag The tag/name of the Shortcode.
*
* @return string The author URL.
*/
public static function authorurl( $atts, $content, $tag ) {
public static function authorurl() {
$item = self::get_item();
if ( ! $item ) {
@ -370,52 +354,36 @@ class Shortcodes {
/**
* Generates output for the 'ap_blogurl' Shortcode
*
* @param array $atts The Shortcode attributes.
* @param string $content The ActivityPub post-content.
* @param string $tag The tag/name of the Shortcode.
*
* @return string The site URL.
*/
public static function blogurl( $atts, $content, $tag ) {
public static function blogurl() {
return \esc_url( \get_bloginfo( 'url' ) );
}
/**
* Generates output for the 'ap_blogname' Shortcode
*
* @param array $atts The Shortcode attributes.
* @param string $content The ActivityPub post-content.
* @param string $tag The tag/name of the Shortcode.
*
* @return string
*/
public static function blogname( $atts, $content, $tag ) {
public static function blogname() {
return \wp_strip_all_tags( \get_bloginfo( 'name' ) );
}
/**
* Generates output for the 'ap_blogdesc' Shortcode
*
* @param array $atts The Shortcode attributes.
* @param string $content The ActivityPub post-content.
* @param string $tag The tag/name of the Shortcode.
*
* @return string The site description.
*/
public static function blogdesc( $atts, $content, $tag ) {
public static function blogdesc() {
return \wp_strip_all_tags( \get_bloginfo( 'description' ) );
}
/**
* Generates output for the 'ap_date' Shortcode
*
* @param array $atts The Shortcode attributes.
* @param string $content The ActivityPub post-content.
* @param string $tag The tag/name of the Shortcode.
*
* @return string The post date.
*/
public static function date( $atts, $content, $tag ) {
public static function date() {
$item = self::get_item();
if ( ! $item ) {
@ -424,7 +392,6 @@ class Shortcodes {
$datetime = \get_post_datetime( $item );
$dateformat = \get_option( 'date_format' );
$timeformat = \get_option( 'time_format' );
$date = $datetime->format( $dateformat );
@ -438,13 +405,9 @@ class Shortcodes {
/**
* Generates output for the 'ap_time' Shortcode
*
* @param array $atts The Shortcode attributes.
* @param string $content The ActivityPub post-content.
* @param string $tag The tag/name of the Shortcode.
*
* @return string The post time.
*/
public static function time( $atts, $content, $tag ) {
public static function time() {
$item = self::get_item();
if ( ! $item ) {
@ -452,7 +415,6 @@ class Shortcodes {
}
$datetime = \get_post_datetime( $item );
$dateformat = \get_option( 'date_format' );
$timeformat = \get_option( 'time_format' );
$date = $datetime->format( $timeformat );
@ -467,13 +429,9 @@ class Shortcodes {
/**
* Generates output for the 'ap_datetime' Shortcode
*
* @param array $atts The Shortcode attributes.
* @param string $content The ActivityPub post-content.
* @param string $tag The tag/name of the Shortcode.
*
* @return string The post date/time.
*/
public static function datetime( $atts, $content, $tag ) {
public static function datetime() {
$item = self::get_item();
if ( ! $item ) {

View file

@ -256,11 +256,9 @@ class Collection {
/**
* Moderators endpoint
*
* @param WP_REST_Request $request The request object.
*
* @return WP_REST_Response The response object.
*/
public static function moderators_get( $request ) {
public static function moderators_get() {
$response = array(
'@context' => Actor::JSON_LD_CONTEXT,
'id' => get_rest_url_by_path( 'collections/moderators' ),

View file

@ -80,8 +80,6 @@ class Inbox {
return $user;
}
$page = $request->get_param( 'page', 0 );
/*
* Action triggerd prior to the ActivityPub profile being created and sent to the client
*/

View file

@ -67,11 +67,9 @@ class Nodeinfo {
/**
* Render NodeInfo file
*
* @param WP_REST_Request $request
*
* @return WP_REST_Response
*/
public static function nodeinfo( $request ) {
public static function nodeinfo() {
/*
* Action triggerd prior to the ActivityPub profile being created and sent to the client
*/
@ -118,11 +116,9 @@ class Nodeinfo {
/**
* Render NodeInfo file
*
* @param WP_REST_Request $request
*
* @return WP_REST_Response
*/
public static function nodeinfo2( $request ) {
public static function nodeinfo2() {
/*
* Action triggerd prior to the ActivityPub profile being created and sent to the client
*/
@ -165,11 +161,9 @@ class Nodeinfo {
/**
* Render NodeInfo discovery file
*
* @param WP_REST_Request $request
*
* @return WP_REST_Response
*/
public static function discovery( $request ) {
public static function discovery() {
$discovery = array();
$discovery['links'] = array(
array(

View file

@ -24,12 +24,9 @@
<config name="text_domain" value="activitypub,default"/>
<rule ref="WordPress">
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter"/>
<exclude name="Squiz.Commenting"/>
</rule>
<rule ref="VariableAnalysis">
<exclude name="VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable"/>
</rule>
<rule ref="VariableAnalysis"/>
<rule ref="WordPress.WP.Capabilities">
<properties>

View file

@ -92,4 +92,30 @@ class Test_Activitypub_Shortcodes extends WP_UnitTestCase {
$this->assertEquals( "<p>Lorem ipsum dolor […]</p>\n", $content );
Shortcodes::unregister();
}
/**
* Tests 'ap_title' shortcode.
*
* @covers Activitypub\Shortcodes::title
*/
public function test_title() {
Shortcodes::register();
global $post;
$post = self::factory()->post->create_and_get(
array(
'post_title' => 'Test title for shortcode',
)
);
$content = '[ap_title]';
// Fill in the shortcodes.
setup_postdata( $post );
$content = do_shortcode( $content );
wp_reset_postdata();
Shortcodes::unregister();
$this->assertEquals( 'Test title for shortcode', $content );
}
}