Skip to content

Commit

Permalink
Update PHPCompatibility and fix errors (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk authored Dec 6, 2024
1 parent cb9ceeb commit b57ecb1
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ install_wp() {
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
fi

download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
download https://raw.githubusercontent.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}

install_test_suite() {
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "A social network between WordPresses. Privacy focused, by itself a self-hosted RSS++ reader with notifications.",
"license": "GPL-2.0-or-later",
"require-dev": {
"phpcompatibility/php-compatibility": "*",
"phpcompatibility/php-compatibility": "dev-develop as 9.99.99",
"phpcompatibility/phpcompatibility-wp": "*",
"wp-coding-standards/wpcs": "*",
"yoast/phpunit-polyfills": "*",
"php-parallel-lint/php-parallel-lint": "^1.3",
Expand All @@ -21,7 +22,7 @@
"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git"
],
"check-cs": [
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --runtime-set testVersion 5.6-"
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs"
],
"fix-cs": [
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
Expand Down
8 changes: 4 additions & 4 deletions feed-parsers/class-feed-parser-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ public function discover_available_feeds( $content, $url ) {
*
* @return array An array of feed items.
*/
public function fetch_feed( $url, User_Feed $user_feed = null ) {
public function fetch_feed( $url, ?User_Feed $user_feed = null ) {
if ( $user_feed ) {
$this->disable_polling( $user_feed );
}
Expand Down Expand Up @@ -1655,7 +1655,7 @@ public function activitypub_settings( User $friend ) {
* @param User $friend_user The friend user.
* @return Feed_Item The modified feed item.
*/
public function modify_incoming_item( Feed_Item $item, User_Feed $feed = null, User $friend_user = null ) {
public function modify_incoming_item( Feed_Item $item, ?User_Feed $feed = null, ?User $friend_user = null ) {
if ( ! $feed || 'activitypub' !== $feed->get_parser() || ! $friend_user ) {
return $item;
}
Expand Down Expand Up @@ -2372,7 +2372,7 @@ public function trashed_comment( $comment_id, $comment ) {
*
* @return array The comments.
*/
public function get_remote_comments( $comments, $post_id, User $friend_user = null, User_Feed $user_feed = null ) {
public function get_remote_comments( $comments, $post_id, ?User $friend_user = null, ?User_Feed $user_feed = null ) {
if ( User_Feed::get_parser_for_post_id( $post_id ) !== self::SLUG ) {
return $comments;
}
Expand Down Expand Up @@ -2447,7 +2447,7 @@ public static function comment_form( $post_id ) {
);
}

public function append_comment_form( $content, $post_id, User $friend_user = null, User_Feed $user_feed = null ) {
public function append_comment_form( $content, $post_id, ?User $friend_user = null, ?User_Feed $user_feed = null ) {
$meta = get_post_meta( $post_id, self::SLUG, true );
if ( ! $meta ) {
if ( User_Feed::get_parser_for_post_id( $post_id ) !== self::SLUG ) {
Expand Down
4 changes: 2 additions & 2 deletions feed-parsers/class-feed-parser-simplepie.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ public function process_items( $items, $url ) {
/* See https://www.rssboard.org/rss-encoding-examples */
$title = $item->get_title();
if ( $title ) {
$title = htmlspecialchars_decode( $title );
$title = htmlspecialchars_decode( $title, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
if ( $title ) {
$title = \html_entity_decode( $title, ENT_QUOTES, 'UTF-8' );
$title = \html_entity_decode( $title, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8' );
}
}

Expand Down
4 changes: 2 additions & 2 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1347,10 +1347,10 @@ public function process_admin_edit_friend_feeds() {
update_user_option( get_current_user_id(), 'friends_hide_from_friends_page', $hide_from_friends_page );
}

if ( $friend->set_retention_number_enabled( filter_input( INPUT_POST, 'friends_enable_retention_number', FILTER_VALIDATE_BOOL ) ) && isset( $_POST['friends_retention_number'] ) ) {
if ( $friend->set_retention_number_enabled( boolval( filter_input( INPUT_POST, 'friends_enable_retention_number', FILTER_SANITIZE_NUMBER_INT ) ) ) && isset( $_POST['friends_retention_number'] ) ) {
$friend->set_retention_number( filter_input( INPUT_POST, 'friends_retention_number', FILTER_SANITIZE_NUMBER_INT ) );
}
if ( $friend->set_retention_days_enabled( filter_input( INPUT_POST, 'friends_enable_retention_days', FILTER_VALIDATE_BOOL ) ) && isset( $_POST['friends_retention_days'] ) ) {
if ( $friend->set_retention_days_enabled( boolval( filter_input( INPUT_POST, 'friends_enable_retention_days', FILTER_SANITIZE_NUMBER_INT ) ) ) && isset( $_POST['friends_retention_days'] ) ) {
$friend->set_retention_days( filter_input( INPUT_POST, 'friends_retention_days', FILTER_SANITIZE_NUMBER_INT ) );
}

Expand Down
2 changes: 1 addition & 1 deletion includes/class-friends.php
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ public static function get_link_rels() {
* @return string The text in ASCII only.
*/
private static function strip_non_ascii( $text ) {
$text = html_entity_decode( $text );
$text = html_entity_decode( $text, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
$text = str_replace( '»', '>', $text );
$text = strtr( $text, '"', '' );
return filter_var( $text, FILTER_DEFAULT, FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_NO_ENCODE_QUOTES );
Expand Down
6 changes: 6 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<description>Generally-applicable sniffs for WordPress plugins</description>

<config name="text_domain" value="friends" />
<config name="minimum_supported_wp_version" value="4.6"/>
<!-- Minimum PHP version supported by the plugin -->
<config name="testVersion" value="7.2-"/>

<rule ref="WordPress">
<properties>
Expand Down Expand Up @@ -57,10 +60,13 @@
</property>
</properties>
</rule>

<rule ref="WordPress.Security.EscapeOutput.UnsafePrintingFunction">
<type>warning</type>
</rule>

<rule ref="PHPCompatibilityWP" />

<!-- Check all PHP files in directory tree by default. -->
<arg name="extensions" value="php"/>
<file>.</file>
Expand Down

0 comments on commit b57ecb1

Please sign in to comment.