Automated native_function_invocation fixes

`php php-cs-fixer --rules=native_function_invocation fix ./ --allow-risky=yes`
This commit is contained in:
Matthias Pfefferle 2019-12-01 21:20:26 +01:00
parent a4887147c6
commit 85db6f2d7e
12 changed files with 43 additions and 43 deletions

View file

@ -21,50 +21,50 @@ namespace Activitypub;
function init() { function init() {
\defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|^)#(\w*[A-Za-z_]+\w*)' ); \defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|^)#(\w*[A-Za-z_]+\w*)' );
require_once dirname( __FILE__ ) . '/includes/table/followers-list.php'; require_once \dirname( __FILE__ ) . '/includes/table/followers-list.php';
require_once dirname( __FILE__ ) . '/includes/class-signature.php'; require_once \dirname( __FILE__ ) . '/includes/class-signature.php';
require_once dirname( __FILE__ ) . '/includes/peer/class-followers.php'; require_once \dirname( __FILE__ ) . '/includes/peer/class-followers.php';
require_once dirname( __FILE__ ) . '/includes/functions.php'; require_once \dirname( __FILE__ ) . '/includes/functions.php';
require_once dirname( __FILE__ ) . '/includes/class-activity-dispatcher.php'; require_once \dirname( __FILE__ ) . '/includes/class-activity-dispatcher.php';
\Activitypub\Activity_Dispatcher::init(); \Activitypub\Activity_Dispatcher::init();
require_once dirname( __FILE__ ) . '/includes/model/class-activity.php'; require_once \dirname( __FILE__ ) . '/includes/model/class-activity.php';
require_once dirname( __FILE__ ) . '/includes/model/class-post.php'; require_once \dirname( __FILE__ ) . '/includes/model/class-post.php';
\Activitypub\Model\Post::init(); \Activitypub\Model\Post::init();
require_once dirname( __FILE__ ) . '/includes/class-activitypub.php'; require_once \dirname( __FILE__ ) . '/includes/class-activitypub.php';
\Activitypub\Activitypub::init(); \Activitypub\Activitypub::init();
// Configure the REST API route // Configure the REST API route
require_once dirname( __FILE__ ) . '/includes/rest/class-outbox.php'; require_once \dirname( __FILE__ ) . '/includes/rest/class-outbox.php';
\Activitypub\Rest\Outbox::init(); \Activitypub\Rest\Outbox::init();
require_once dirname( __FILE__ ) . '/includes/rest/class-inbox.php'; require_once \dirname( __FILE__ ) . '/includes/rest/class-inbox.php';
\Activitypub\Rest\Inbox::init(); \Activitypub\Rest\Inbox::init();
require_once dirname( __FILE__ ) . '/includes/rest/class-followers.php'; require_once \dirname( __FILE__ ) . '/includes/rest/class-followers.php';
\Activitypub\Rest\Followers::init(); \Activitypub\Rest\Followers::init();
require_once dirname( __FILE__ ) . '/includes/rest/class-following.php'; require_once \dirname( __FILE__ ) . '/includes/rest/class-following.php';
\Activitypub\Rest\Following::init(); \Activitypub\Rest\Following::init();
require_once dirname( __FILE__ ) . '/includes/rest/class-webfinger.php'; require_once \dirname( __FILE__ ) . '/includes/rest/class-webfinger.php';
\Activitypub\Rest\Webfinger::init(); \Activitypub\Rest\Webfinger::init();
require_once dirname( __FILE__ ) . '/includes/rest/class-nodeinfo.php'; require_once \dirname( __FILE__ ) . '/includes/rest/class-nodeinfo.php';
\Activitypub\Rest\NodeInfo::init(); \Activitypub\Rest\NodeInfo::init();
require_once dirname( __FILE__ ) . '/includes/class-admin.php'; require_once \dirname( __FILE__ ) . '/includes/class-admin.php';
\Activitypub\Admin::init(); \Activitypub\Admin::init();
require_once dirname( __FILE__ ) . '/includes/class-hashtag.php'; require_once \dirname( __FILE__ ) . '/includes/class-hashtag.php';
\Activitypub\Hashtag::init(); \Activitypub\Hashtag::init();
require_once dirname( __FILE__ ) . '/includes/class-debug.php'; require_once \dirname( __FILE__ ) . '/includes/class-debug.php';
\Activitypub\Debug::init(); \Activitypub\Debug::init();
require_once dirname( __FILE__ ) . '/includes/class-health-check.php'; require_once \dirname( __FILE__ ) . '/includes/class-health-check.php';
\Activitypub\Health_Check::init(); \Activitypub\Health_Check::init();
} }
add_action( 'plugins_loaded', '\Activitypub\init' ); add_action( 'plugins_loaded', '\Activitypub\init' );

View file

@ -57,14 +57,14 @@ class Activitypub {
$accept_header = $_SERVER['HTTP_ACCEPT']; $accept_header = $_SERVER['HTTP_ACCEPT'];
if ( if (
stristr( $accept_header, 'application/activity+json' ) || \stristr( $accept_header, 'application/activity+json' ) ||
stristr( $accept_header, 'application/ld+json' ) \stristr( $accept_header, 'application/ld+json' )
) { ) {
return $json_template; return $json_template;
} }
// accept header as an array // accept header as an array
$accept = \explode( ',', trim( $accept_header ) ); $accept = \explode( ',', \trim( $accept_header ) );
if ( if (
\in_array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', $accept, true ) || \in_array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', $accept, true ) ||
@ -113,11 +113,11 @@ class Activitypub {
} }
if ( 'publish' === $new_status && 'publish' !== $old_status ) { if ( 'publish' === $new_status && 'publish' !== $old_status ) {
\wp_schedule_single_event( time(), 'activitypub_send_post_activity', array( $post->ID ) ); \wp_schedule_single_event( \time(), 'activitypub_send_post_activity', array( $post->ID ) );
} elseif ( 'publish' === $new_status ) { } elseif ( 'publish' === $new_status ) {
\wp_schedule_single_event( time(), 'activitypub_send_update_activity', array( $post->ID ) ); \wp_schedule_single_event( \time(), 'activitypub_send_update_activity', array( $post->ID ) );
} elseif ( 'trash' === $new_status ) { } elseif ( 'trash' === $new_status ) {
\wp_schedule_single_event( time(), 'activitypub_send_delete_activity', array( get_permalink( $post ) ) ); \wp_schedule_single_event( \time(), 'activitypub_send_delete_activity', array( get_permalink( $post ) ) );
} }
} }

View file

@ -39,14 +39,14 @@ class Admin {
* Load settings page * Load settings page
*/ */
public static function settings_page() { public static function settings_page() {
\load_template( dirname( __FILE__ ) . '/../templates/settings.php' ); \load_template( \dirname( __FILE__ ) . '/../templates/settings.php' );
} }
/** /**
* Load user settings page * Load user settings page
*/ */
public static function followers_list_page() { public static function followers_list_page() {
\load_template( dirname( __FILE__ ) . '/../templates/followers-list.php' ); \load_template( \dirname( __FILE__ ) . '/../templates/followers-list.php' );
} }
/** /**

View file

@ -21,7 +21,7 @@ class Debug {
} }
public static function write_log( $log ) { public static function write_log( $log ) {
if ( is_array( $log ) || is_object( $log ) ) { if ( \is_array( $log ) || \is_object( $log ) ) {
\error_log( \print_r( $log, true ) ); \error_log( \print_r( $log, true ) );
} else { } else {
\error_log( $log ); \error_log( $log );

View file

@ -194,7 +194,7 @@ function get_identifier_settings( $user_id ) {
<td> <td>
<p><code><?php echo \esc_html( \Activitypub\get_webfinger_resource( $user_id ) ); ?></code> or <code><?php echo \esc_url( \get_author_posts_url( $user_id ) ); ?></code></p> <p><code><?php echo \esc_html( \Activitypub\get_webfinger_resource( $user_id ) ); ?></code> or <code><?php echo \esc_url( \get_author_posts_url( $user_id ) ); ?></code></p>
<?php // translators: the webfinger resource ?> <?php // translators: the webfinger resource ?>
<p class="description"><?php printf( \esc_html__( 'Try to follow "@%s" in the Mastodon/Friendica search field.', 'activitypub' ), \esc_html( \Activitypub\get_webfinger_resource( $user_id ) ) ); ?></p> <p class="description"><?php \printf( \esc_html__( 'Try to follow "@%s" in the Mastodon/Friendica search field.', 'activitypub' ), \esc_html( \Activitypub\get_webfinger_resource( $user_id ) ) ); ?></p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -236,7 +236,7 @@ function url_to_authorid( $url ) {
} }
// first, check to see if there is a 'author=N' to match against // first, check to see if there is a 'author=N' to match against
if ( preg_match( '/[?&]author=(\d+)/i', $url, $values ) ) { if ( \preg_match( '/[?&]author=(\d+)/i', $url, $values ) ) {
$id = absint( $values[1] ); $id = absint( $values[1] );
if ( $id ) { if ( $id ) {
return $id; return $id;
@ -253,10 +253,10 @@ function url_to_authorid( $url ) {
// generate rewrite rule for the author url // generate rewrite rule for the author url
$author_rewrite = $wp_rewrite->get_author_permastruct(); $author_rewrite = $wp_rewrite->get_author_permastruct();
$author_regexp = str_replace( '%author%', '', $author_rewrite ); $author_regexp = \str_replace( '%author%', '', $author_rewrite );
// match the rewrite rule with the passed url // match the rewrite rule with the passed url
if ( preg_match( '/https?:\/\/(.+)' . preg_quote( $author_regexp, '/' ) . '([^\/]+)/i', $url, $match ) ) { if ( \preg_match( '/https?:\/\/(.+)' . \preg_quote( $author_regexp, '/' ) . '([^\/]+)/i', $url, $match ) ) {
$user = get_user_by( 'slug', $match[2] ); $user = get_user_by( 'slug', $match[2] );
if ( $user ) { if ( $user ) {
return $user->ID; return $user->ID;

View file

@ -30,7 +30,7 @@ class Activity {
} }
$this->type = \ucfirst( $type ); $this->type = \ucfirst( $type );
$this->published = \date( 'Y-m-d\TH:i:s\Z', strtotime( 'now' ) ); $this->published = \date( 'Y-m-d\TH:i:s\Z', \strtotime( 'now' ) );
} }
public function __call( $method, $params ) { public function __call( $method, $params ) {

View file

@ -252,7 +252,7 @@ class Inbox {
'comment_author_email' => '', 'comment_author_email' => '',
'comment_author_url' => \esc_url_raw( $object['actor'] ), 'comment_author_url' => \esc_url_raw( $object['actor'] ),
'comment_content' => \esc_url_raw( $object['actor'] ), 'comment_content' => \esc_url_raw( $object['actor'] ),
'comment_type' => \esc_attr( strtolower( $object['type'] ) ), 'comment_type' => \esc_attr( \strtolower( $object['type'] ) ),
'comment_parent' => 0, 'comment_parent' => 0,
'comment_meta' => array( 'comment_meta' => array(
'source_url' => \esc_url_raw( $object['id'] ), 'source_url' => \esc_url_raw( $object['id'] ),

View file

@ -78,7 +78,7 @@ class Outbox {
$json->first = \add_query_arg( 'page', 0, $json->partOf ); // phpcs:ignore $json->first = \add_query_arg( 'page', 0, $json->partOf ); // phpcs:ignore
$json->last = \add_query_arg( 'page', ( \ceil ( $json->totalItems / 10 ) ) - 1, $json->partOf ); // phpcs:ignore $json->last = \add_query_arg( 'page', ( \ceil ( $json->totalItems / 10 ) ) - 1, $json->partOf ); // phpcs:ignore
if ( ( ceil ( $json->totalItems / 10 ) ) - 1 > $page ) { // phpcs:ignore if ( ( \ceil ( $json->totalItems / 10 ) ) - 1 > $page ) { // phpcs:ignore
$json->next = \add_query_arg( 'page', ++$page, $json->partOf ); // phpcs:ignore $json->next = \add_query_arg( 'page', ++$page, $json->partOf ); // phpcs:ignore
} }

View file

@ -1,7 +1,7 @@
<?php <?php
namespace Activitypub\Table; namespace Activitypub\Table;
if ( ! class_exists( '\WP_List_Table' ) ) { if ( ! \class_exists( '\WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
} }

View file

@ -61,7 +61,7 @@
<ul> <ul>
<?php foreach ( $post_types as $post_type ) { ?> <?php foreach ( $post_types as $post_type ) { ?>
<li> <li>
<input type="checkbox" id="activitypub_support_post_types" name="activitypub_support_post_types[]" value="<?php echo \esc_attr( $post_type->name ); ?>" <?php echo \checked( true, in_array( $post_type->name, $support_post_types, true ) ); ?> /> <input type="checkbox" id="activitypub_support_post_types" name="activitypub_support_post_types[]" value="<?php echo \esc_attr( $post_type->name ); ?>" <?php echo \checked( true, \in_array( $post_type->name, $support_post_types, true ) ); ?> />
<label for="<?php echo \esc_attr( $post_type->name ); ?>"><?php echo \esc_html( $post_type->label ); ?></label> <label for="<?php echo \esc_attr( $post_type->name ); ?>"><?php echo \esc_html( $post_type->label ); ?></label>
</li> </li>
<?php } ?> <?php } ?>

View file

@ -1,10 +1,10 @@
<?php <?php
error_reporting( E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING ); \error_reporting( E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING );
define( 'WP_DEBUG', false ); \define( 'WP_DEBUG', false );
$_tests_dir = getenv( 'WP_TESTS_DIR' ); $_tests_dir = \getenv( 'WP_TESTS_DIR' );
if ( ! $_tests_dir ) { if ( ! $_tests_dir ) {
$_tests_dir = '/tmp/wordpress-tests-lib'; $_tests_dir = '/tmp/wordpress-tests-lib';
} }
@ -12,10 +12,10 @@ if ( ! $_tests_dir ) {
require_once $_tests_dir . '/includes/functions.php'; require_once $_tests_dir . '/includes/functions.php';
function _manually_load_plugin() { function _manually_load_plugin() {
require dirname( dirname( __FILE__ ) ) . '/activitypub.php'; require \dirname( \dirname( __FILE__ ) ) . '/activitypub.php';
} }
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
require $_tests_dir . '/includes/bootstrap.php'; require $_tests_dir . '/includes/bootstrap.php';
error_reporting( E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING ); \error_reporting( E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING );

View file

@ -11,13 +11,13 @@ class Test_Db_Activitypub_Followers extends WP_UnitTestCase {
$db_followers = \Activitypub\Peer\Followers::get_followers( 1 ); $db_followers = \Activitypub\Peer\Followers::get_followers( 1 );
$this->assertEquals( 3, count( $db_followers ) ); $this->assertEquals( 3, \count( $db_followers ) );
$this->assertSame( array( 'https://example.com/author/jon', 'https://example.org/author/doe', 'http://sally.example.org' ), $db_followers ); $this->assertSame( array( 'https://example.com/author/jon', 'https://example.org/author/doe', 'http://sally.example.org' ), $db_followers );
} }
public function test_add_follower() { public function test_add_follower() {
$follower = 'https://example.com/author/' . time(); $follower = 'https://example.com/author/' . \time();
\Activitypub\Peer\Followers::add_follower( $follower, 1 ); \Activitypub\Peer\Followers::add_follower( $follower, 1 );
$db_followers = \Activitypub\Peer\Followers::get_followers( 1 ); $db_followers = \Activitypub\Peer\Followers::get_followers( 1 );