diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 3eba154..0000000 --- a/.eslintignore +++ /dev/null @@ -1,13 +0,0 @@ -# wp-scripts compiled block artifacts (output of `npm run build`). -# Source lives under blocks/*/src/. The compiled bundles below are checked-in -# distribution artifacts and must not be linted. -blocks/login-register/index.js -blocks/password-reset/index.js - -# Generic build / vendor / minified output (kept in sync with the upstream -# homeboy WordPress extension's defaults so local lint runs match CI). -build/ -dist/ -node_modules/ -vendor/ -*.min.js diff --git a/.github/workflows/homeboy.yml b/.github/workflows/homeboy.yml new file mode 100644 index 0000000..c5f9641 --- /dev/null +++ b/.github/workflows/homeboy.yml @@ -0,0 +1,23 @@ +name: Homeboy + +on: + pull_request: + branches: [main] + push: + branches: [main] + workflow_dispatch: + +concurrency: + group: homeboy-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + lint: + uses: Extra-Chill/homeboy-action/.github/workflows/ci.yml@v2 + with: + commands: review lint + expected-commands: review lint + secrets: inherit diff --git a/assets/js/auth-utils.js b/assets/js/auth-utils.js index 74b43d6..ede59e9 100644 --- a/assets/js/auth-utils.js +++ b/assets/js/auth-utils.js @@ -18,7 +18,7 @@ url.pathname += '/'; } return url.toString(); - } catch (err) { + } catch { return ''; } } @@ -88,7 +88,7 @@ window.localStorage.setItem(key, generated); return generated; - } catch (err) { + } catch { return ''; } } diff --git a/assets/js/google-signin.js b/assets/js/google-signin.js index bbce28d..eb36564 100644 --- a/assets/js/google-signin.js +++ b/assets/js/google-signin.js @@ -20,16 +20,19 @@ */ function init(config) { if (!config || !config.clientId) { + // eslint-disable-next-line no-console console.error('ECGoogleSignIn: clientId is required'); return; } if (!utils) { + // eslint-disable-next-line no-console console.error('ECGoogleSignIn: ECAuthUtils not loaded'); return; } if (typeof google === 'undefined' || !google.accounts) { + // eslint-disable-next-line no-console console.error('ECGoogleSignIn: Google Identity Services not loaded'); return; } @@ -181,7 +184,7 @@ try { const params = new URL(window.location.href).searchParams; return params.get('from_join') === 'true'; - } catch (e) { + } catch { return false; } } @@ -196,6 +199,7 @@ if (container && utils) { utils.renderNotice(container, 'error', message); } else { + // eslint-disable-next-line no-console console.error('ECGoogleSignIn:', message); } } diff --git a/blocks/concert-attendance/src/AttendanceButton.js b/blocks/concert-attendance/src/AttendanceButton.js index 9cba569..316b6fa 100644 --- a/blocks/concert-attendance/src/AttendanceButton.js +++ b/blocks/concert-attendance/src/AttendanceButton.js @@ -12,14 +12,21 @@ * - button-2 (green accent) when marked * - button-3 (neutral) when unmarked * - * @package ExtraChillUsers + * @package */ +/** + * WordPress dependencies + */ import { useState } from '@wordpress/element'; + +/** + * Internal dependencies + */ import useMarkAttendance from './useMarkAttendance'; /** - * @param {Object} props + * @param {Object} props Component properties. * @param {number} props.eventId Event post ID. * @param {number} props.blogId Blog ID the event lives on. * @param {boolean} props.isLoggedIn Whether a user is logged in. @@ -29,8 +36,8 @@ import useMarkAttendance from './useMarkAttendance'; * @param {string} props.labelActive Label when marked. * @param {string} props.loginUrl Login URL for logged-out users. * @param {string} props.redirectTo Optional explicit post-login return URL. - * When empty, the current request URL is - * used (prior default behavior). + * When empty, the current request URL is + * used (prior default behavior). */ const AttendanceButton = ( { eventId, diff --git a/blocks/concert-attendance/src/index.js b/blocks/concert-attendance/src/index.js index f706769..5c53d6c 100644 --- a/blocks/concert-attendance/src/index.js +++ b/blocks/concert-attendance/src/index.js @@ -11,11 +11,18 @@ * the server's first-paint state (not an imperative control surface — the * React component owns all interaction after mount). * - * @package ExtraChillUsers + * @package */ +/** + * WordPress dependencies + */ import domReady from '@wordpress/dom-ready'; import { createRoot } from '@wordpress/element'; + +/** + * Internal dependencies + */ import AttendanceButton from './AttendanceButton'; domReady( () => { diff --git a/blocks/concert-attendance/src/useMarkAttendance.js b/blocks/concert-attendance/src/useMarkAttendance.js index 6cd677e..3d47a05 100644 --- a/blocks/concert-attendance/src/useMarkAttendance.js +++ b/blocks/concert-attendance/src/useMarkAttendance.js @@ -22,9 +22,12 @@ * The hook owns ONLY the network write + its in-flight / error state. The * caller owns its own optimistic UI. * - * @package ExtraChillUsers + * @package */ +/** + * WordPress dependencies + */ import { useState, useCallback, useRef } from '@wordpress/element'; import apiFetch from '@wordpress/api-fetch'; import { __ } from '@wordpress/i18n'; diff --git a/blocks/login-register/index.js b/blocks/login-register/index.js deleted file mode 100644 index dd60ee5..0000000 --- a/blocks/login-register/index.js +++ /dev/null @@ -1 +0,0 @@ -(()=>{"use strict";const e=window.React,t=window.wp.blocks,o=window.wp.blockEditor;(0,t.registerBlockType)("extrachill/login-register",{edit:function(){const t=(0,o.useBlockProps)();return(0,e.createElement)("div",{...t},(0,e.createElement)("div",{style:{padding:"20px",background:"#f0f0f0",border:"1px solid #ddd",borderRadius:"4px",textAlign:"center"}},(0,e.createElement)("p",{style:{margin:"0",fontWeight:"bold"}},"Login/Register Form"),(0,e.createElement)("p",{style:{margin:"10px 0 0",fontSize:"12px",color:"#666"}},"This block displays a tabbed login and registration form on the frontend.")))}})})(); \ No newline at end of file diff --git a/blocks/login-register/render.php b/blocks/login-register/render.php index c254d84..0365d2a 100644 --- a/blocks/login-register/render.php +++ b/blocks/login-register/render.php @@ -93,8 +93,8 @@ $initial_notice = $registration_notice; } +// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only invite context from signed URL parameters for rendering. if ( isset( $_GET['action'] ) && 'ec_accept_invite' === $_GET['action'] && isset( $_GET['token'] ) && isset( $_GET['artist_id'] ) ) { - // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only invite context from signed URL parameters for rendering. $token_from_url = sanitize_text_field( wp_unslash( $_GET['token'] ) ); $artist_id_from_url = absint( $_GET['artist_id'] ); diff --git a/blocks/password-reset/index.js b/blocks/password-reset/index.js deleted file mode 100644 index 7f12015..0000000 --- a/blocks/password-reset/index.js +++ /dev/null @@ -1 +0,0 @@ -(()=>{"use strict";const e=window.React,t=window.wp.blocks,r=window.wp.blockEditor;(0,t.registerBlockType)("extrachill/password-reset",{edit:()=>{const t=(0,r.useBlockProps)();return(0,e.createElement)("div",{...t},(0,e.createElement)("div",{style:{padding:"20px",background:"#f0f0f0",border:"1px solid #ddd",borderRadius:"4px",textAlign:"center"}},(0,e.createElement)("p",{style:{margin:"0",fontWeight:"bold"}},"Password Reset Form"),(0,e.createElement)("p",{style:{margin:"10px 0 0",fontSize:"12px",color:"#666"}},"This block displays a password reset form on the frontend.")))}})})(); \ No newline at end of file diff --git a/composer.json b/composer.json index d6e2c81..0046236 100644 --- a/composer.json +++ b/composer.json @@ -8,15 +8,13 @@ "php": ">=8.0" }, "require-dev": { + "phpstan/phpstan": "^2.0", + "php-stubs/wp-cli-stubs": "^2.10", "squizlabs/php_codesniffer": "^3.7", + "szepeviktor/phpstan-wordpress": "^2.0", "wp-coding-standards/wpcs": "^3.0", "phpunit/phpunit": "^9.0" }, - "autoload-dev": { - "files": [ - "tests/phpstan-stubs.php" - ] - }, "scripts": { "lint:php": "vendor/bin/phpcs --standard=WordPress --extensions=php .", "lint:fix": "vendor/bin/phpcbf --standard=WordPress --extensions=php .", diff --git a/inc/artist-dispatch.php b/inc/artist-dispatch.php index 2cd32af..af18100 100644 --- a/inc/artist-dispatch.php +++ b/inc/artist-dispatch.php @@ -239,7 +239,7 @@ function ec_users_write_artist_dispatch_state( $user_id, array $next, array $cur function ec_users_acquire_artist_dispatch_lock( $user_id, $request_id ) { $user_id = absint( $user_id ); $key = EC_USERS_ARTIST_DISPATCH_LOCK_META . '_' . $user_id; - $blog_id = ec_users_get_artist_dispatch_blog_id(); + $blog_id = ec_users_get_artist_dispatch_blog_id(); for ( $attempt = 0; 5 > $attempt; ++$attempt ) { $now = time(); $lock = array( @@ -505,7 +505,7 @@ function ec_users_mark_artist_dispatch_delivery_receipt( $user_id, $channel, $ev $delivered = $receipt; $delivered['status'] = 'delivered'; $delivered['delivered_at'] = time(); - $blog_id = ec_users_get_artist_dispatch_blog_id(); + $blog_id = ec_users_get_artist_dispatch_blog_id(); switch_to_blog( $blog_id ); try { return update_option( ec_users_get_artist_dispatch_delivery_meta_key( $user_id, $channel, $event_type, $request_id ), $delivered, false ); diff --git a/inc/auth-tokens/browser-handoff-token.php b/inc/auth-tokens/browser-handoff-token.php index fca755b..0cc8e2a 100644 --- a/inc/auth-tokens/browser-handoff-token.php +++ b/inc/auth-tokens/browser-handoff-token.php @@ -16,7 +16,14 @@ const EXTRACHILL_USERS_BROWSER_HANDOFF_TTL = 60; const EXTRACHILL_USERS_BROWSER_HANDOFF_CLAIM_CLEANUP_HOOK = 'extrachill_users_cleanup_browser_handoff_claim'; -add_action( EXTRACHILL_USERS_BROWSER_HANDOFF_CLAIM_CLEANUP_HOOK, 'extrachill_users_cleanup_browser_handoff_claim', 10, 2 ); +add_action( + EXTRACHILL_USERS_BROWSER_HANDOFF_CLAIM_CLEANUP_HOOK, + static function ( $claim_key, $expected_claim ): void { + extrachill_users_cleanup_browser_handoff_claim( $claim_key, $expected_claim ); + }, + 10, + 2 +); /** * Create a single-use browser handoff token. diff --git a/inc/auth/login.php b/inc/auth/login.php index e35d6ae..dce0da4 100644 --- a/inc/auth/login.php +++ b/inc/auth/login.php @@ -235,6 +235,7 @@ function ec_rate_limit_login( $user, $username ) { * @param WP_User $user User object. */ function ec_clear_attempts_on_login( $user_login, $user ) { + unset( $user ); if ( empty( $user_login ) ) { return; } @@ -262,6 +263,7 @@ function ec_clear_attempts_on_two_factor( WP_User $user ) { * @param string $username Username attempted */ function extrachill_handle_login_failed( $username ) { + unset( $username ); if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { return; } diff --git a/inc/auth/password-reset.php b/inc/auth/password-reset.php index fc090cc..6c4e5a3 100644 --- a/inc/auth/password-reset.php +++ b/inc/auth/password-reset.php @@ -46,6 +46,7 @@ function ec_custom_lostpassword_url( $lostpassword_url, $redirect ) { * @return array Modified email content with the reset URL pointing at /reset-password/. */ function ec_filter_password_reset_email( $email, $key, $user_login, $user_data ) { + unset( $user_data ); $reset_url = add_query_arg( array( 'action' => 'reset', @@ -81,6 +82,7 @@ function ec_filter_password_reset_email( $email, $key, $user_login, $user_data ) * @return array Modified email content. */ function ec_filter_new_user_notification_email( $email, $user, $blogname ) { + unset( $user, $blogname ); if ( ! isset( $email['message'] ) || ! is_string( $email['message'] ) ) { return $email; } @@ -134,7 +136,14 @@ function extrachill_users_clear_unclaimed_after_password_reset( $user, $new_pass delete_user_meta( $user->ID, 'ec_unclaimed' ); return ! metadata_exists( 'user', $user->ID, 'ec_unclaimed' ); } -add_action( 'after_password_reset', 'extrachill_users_clear_unclaimed_after_password_reset', 10, 2 ); +add_action( + 'after_password_reset', + static function ( $user, $new_pass ): void { + extrachill_users_clear_unclaimed_after_password_reset( $user, $new_pass ); + }, + 10, + 2 +); /** * Get the transient key for password reset attempts. diff --git a/inc/auth/register.php b/inc/auth/register.php index 10d03c4..f8c6985 100644 --- a/inc/auth/register.php +++ b/inc/auth/register.php @@ -133,7 +133,7 @@ function extrachill_users_validate_password_registration( string $email, string * Production uses Extra Chill Network's verifier. Tests can substitute a * deterministic callable without making external Cloudflare requests. * - * @param callable $verifier Turnstile verifier callable. + * @param callable(string):(true|WP_Error)|string $verifier Turnstile verifier callable. */ $turnstile_verifier = apply_filters( 'extrachill_users_registration_turnstile_verifier', 'ec_turnstile_check_request' ); if ( ! is_callable( $turnstile_verifier ) ) { diff --git a/inc/concert-tracking/buttons.php b/inc/concert-tracking/buttons.php index eb5b32d..d3b5bd7 100644 --- a/inc/concert-tracking/buttons.php +++ b/inc/concert-tracking/buttons.php @@ -403,8 +403,8 @@ function ec_users_enqueue_concert_tracking_assets() { // generated .asset.php supplies dependency handles (wp-element, wp-api-fetch, // wp-dom-ready, …) and a content-hash version, so no manual dependency list // or window global is needed. Replaces the legacy data-* IIFE. - $script_path = EXTRACHILL_USERS_PLUGIN_DIR . 'build/concert-attendance/index.js'; - $asset_path = EXTRACHILL_USERS_PLUGIN_DIR . 'build/concert-attendance/index.asset.php'; + $script_path = EXTRACHILL_USERS_PLUGIN_DIR . 'build/concert-attendance/index.js'; + $asset_path = EXTRACHILL_USERS_PLUGIN_DIR . 'build/concert-attendance/index.asset.php'; if ( file_exists( $script_path ) && file_exists( $asset_path ) ) { $asset = require $asset_path; diff --git a/inc/concert-tracking/import/EventCreator.php b/inc/concert-tracking/import/EventCreator.php index 3d6f8cf..37231da 100644 --- a/inc/concert-tracking/import/EventCreator.php +++ b/inc/concert-tracking/import/EventCreator.php @@ -295,7 +295,7 @@ private static function build_event_block_content( ExternalEvent $event ): strin $attrs = array_filter( $attrs, static function ( $value ) { - return '' !== $value && null !== $value; + return '' !== $value; } ); @@ -365,7 +365,7 @@ private static function ensure_venue_term( ExternalEvent $event ): ?int { ); if ( class_exists( '\\DataMachineEvents\\Core\\Venue_Taxonomy' ) ) { - $result = \DataMachineEvents\Core\Venue_Taxonomy::find_or_create_venue( + $result = \DataMachineEvents\Core\Venue_Taxonomy::find_or_create_venue( $event->venue_name, $venue_data ); diff --git a/inc/concert-tracking/import/EventMatcher.php b/inc/concert-tracking/import/EventMatcher.php index 17507f5..3c62208 100644 --- a/inc/concert-tracking/import/EventMatcher.php +++ b/inc/concert-tracking/import/EventMatcher.php @@ -150,10 +150,10 @@ private function score_candidate( int $post_id, ExternalEvent $event ): int { $venue_terms = wp_get_post_terms( $post_id, 'venue' ); $artist_terms = wp_get_post_terms( $post_id, 'artist' ); - $venue_score = 0; - $artist_score = 0; - $venue_weight = 0.6; - $artist_weight = 0.4; + $venue_score = 0; + $artist_score = 0; + $venue_weight = 0.6; + $artist_weight = 0.4; if ( ! is_wp_error( $venue_terms ) && ! empty( $venue_terms ) ) { $best = 0; diff --git a/inc/concert-tracking/import/ImportOrchestrator.php b/inc/concert-tracking/import/ImportOrchestrator.php index bf6e75a..66ecc75 100644 --- a/inc/concert-tracking/import/ImportOrchestrator.php +++ b/inc/concert-tracking/import/ImportOrchestrator.php @@ -29,8 +29,8 @@ final class ImportOrchestrator { - public const HOOK = 'extrachill_concert_import_process'; - public const GROUP = 'extrachill-concert-import'; + public const HOOK = 'extrachill_concert_import_process'; + public const GROUP = 'extrachill-concert-import'; public const STATUS_PENDING = 'pending'; public const STATUS_RUNNING = 'running'; public const STATUS_COMPLETE = 'complete'; @@ -192,11 +192,11 @@ public static function process( int $run_id ): void { return; } - $events = isset( $result['events'] ) && is_array( $result['events'] ) ? $result['events'] : array(); - $total_pages = isset( $result['total_pages'] ) ? max( 1, (int) $result['total_pages'] ) : $page; - $matcher = new EventMatcher(); - $events_blog = $matcher->blog_id(); - $source_slug = (string) $run['source_slug']; + $events = isset( $result['events'] ) && is_array( $result['events'] ) ? $result['events'] : array(); + $total_pages = isset( $result['total_pages'] ) ? max( 1, (int) $result['total_pages'] ) : $page; + $matcher = new EventMatcher(); + $events_blog = $matcher->blog_id(); + $source_slug = (string) $run['source_slug']; $seen = 0; $matched = 0; @@ -242,9 +242,9 @@ public static function process( int $run_id ): void { } // 1. external_id idempotency check. The source's stable - // identifier is more authoritative than name similarity, so - // we look here BEFORE running the similarity matcher. - // Re-imports for previously-created events become a no-op. + // identifier is more authoritative than name similarity, so + // we look here BEFORE running the similarity matcher. + // Re-imports for previously-created events become a no-op. $resolved_id = EventCreator::find_by_external_id( $source_slug, $external->source_id ); // 2. Similarity match against existing events on the same date. @@ -255,9 +255,9 @@ public static function process( int $run_id ): void { $was_created = false; // 3. Fall through to create. Skipping is data loss — every - // other event-import path on the platform creates events, - // and we already have the user's confirmation to bring this - // history in. + // other event-import path on the platform creates events, + // and we already have the user's confirmation to bring this + // history in. if ( null === $resolved_id ) { $resolved_id = EventCreator::create( $external, $source_slug ); if ( null === $resolved_id ) { @@ -431,7 +431,7 @@ public static function get_user_runs( int $user_id, int $limit = 20 ): array { private static function update_run( int $run_id, array $changes ): void { global $wpdb; - $table = extrachill_users_concert_import_runs_table_name(); + $table = extrachill_users_concert_import_runs_table_name(); $changes['updated_at'] = current_time( 'mysql', true ); $wpdb->update( $table, $changes, array( 'id' => $run_id ) ); } diff --git a/inc/concert-tracking/import/Sources/ConcertImportAuthProvider.php b/inc/concert-tracking/import/Sources/ConcertImportAuthProvider.php index 5f6f8aa..2607a39 100644 --- a/inc/concert-tracking/import/Sources/ConcertImportAuthProvider.php +++ b/inc/concert-tracking/import/Sources/ConcertImportAuthProvider.php @@ -100,10 +100,10 @@ static function ( $providers ) { if ( ! is_array( $providers ) ) { $providers = array(); } - $slug = SetlistFmAuthProvider::PROVIDER_SLUG; + $slug = SetlistFmAuthProvider::PROVIDER_SLUG; $providers[ $slug ] = $providers[ $slug ] ?? new SetlistFmAuthProvider(); - $slug = PhishNetAuthProvider::PROVIDER_SLUG; + $slug = PhishNetAuthProvider::PROVIDER_SLUG; $providers[ $slug ] = $providers[ $slug ] ?? new PhishNetAuthProvider(); return $providers; diff --git a/inc/concert-tracking/import/Sources/PhishNetImportSource.php b/inc/concert-tracking/import/Sources/PhishNetImportSource.php index d6d9805..4633f5d 100644 --- a/inc/concert-tracking/import/Sources/PhishNetImportSource.php +++ b/inc/concert-tracking/import/Sources/PhishNetImportSource.php @@ -140,7 +140,7 @@ public function fetch_page( string $username, int $page ) { return new \WP_Error( 'invalid_json', 'phish.net returned malformed JSON.' ); } - // phish.net v5 envelope: { error: false, error_message: "", data: [...] } + // phish.net v5 wraps response rows in a data envelope with error metadata. if ( ! empty( $payload['error'] ) ) { $msg = isset( $payload['error_message'] ) ? (string) $payload['error_message'] : 'phish.net API error.'; return new \WP_Error( 'phishnet_error', $msg ); diff --git a/inc/concert-tracking/import/Sources/SetlistFmImportSource.php b/inc/concert-tracking/import/Sources/SetlistFmImportSource.php index 81a8748..d5d10fa 100644 --- a/inc/concert-tracking/import/Sources/SetlistFmImportSource.php +++ b/inc/concert-tracking/import/Sources/SetlistFmImportSource.php @@ -87,8 +87,8 @@ public function fetch_page( string $username, int $page ) { array( 'timeout' => 15, 'headers' => array( - 'Accept' => 'application/json', - 'x-api-key' => $api_key, + 'Accept' => 'application/json', + 'x-api-key' => $api_key, 'User-Agent' => 'ExtraChill-Concert-Import/1.0 (+https://extrachill.com)', ), ) diff --git a/inc/concert-tracking/notifications.php b/inc/concert-tracking/notifications.php index 5d5c99e..90bdf6c 100644 --- a/inc/concert-tracking/notifications.php +++ b/inc/concert-tracking/notifications.php @@ -97,7 +97,12 @@ add_action( 'ec_users_event_unmarked', 'ec_users_on_event_unmarked', 10, 3 ); add_action( EC_USERS_SHOW_REMINDER_ACTION, 'ec_users_deliver_show_reminder', 10, 3 ); add_action( 'init', 'ec_users_stale_reminder_sweep_maybe_schedule' ); -add_action( EC_USERS_STALE_REMINDER_SWEEP_HOOK, 'ec_users_resolve_stale_show_reminders' ); +add_action( + EC_USERS_STALE_REMINDER_SWEEP_HOOK, + static function (): void { + ec_users_resolve_stale_show_reminders(); + } +); /** * React to a newly-marked event: schedule a reminder + check milestones. diff --git a/inc/concert-tracking/service.php b/inc/concert-tracking/service.php index 34dbaac..6c42858 100644 --- a/inc/concert-tracking/service.php +++ b/inc/concert-tracking/service.php @@ -728,7 +728,6 @@ function ec_users_build_show_data( WP_Post $post, array $row ): array { $deepest = $term; } } - // @phpstan-ignore-next-line -- Defensive: $deepest is null when location_terms is empty, always set otherwise. if ( null !== $deepest ) { $city = array( 'name' => $deepest->name, @@ -1162,8 +1161,8 @@ function ec_users_events_term_archive_url( string $slug, string $taxonomy, int $ /** * Get users who marked an event. * - * @param int $event_id Event post ID. - * @param int $blog_id Blog ID (default: current blog). + * @param int $event_id Event post ID. + * @param int $blog_id Blog ID (default: current blog). * @param mixed $limit Max users to return (1-100). Default 10. * @return array Attendee data, newest mark first. */ @@ -1180,6 +1179,7 @@ function ec_users_get_event_attendees( int $event_id, int $blog_id = 0, $limit = $table = extrachill_users_concert_tracking_table_name(); + // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Identifiers are trusted WordPress table names. $user_ids = $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$table} ct @@ -1190,13 +1190,14 @@ function ec_users_get_event_attendees( int $event_id, int $blog_id = 0, $limit = AND um.meta_key = %s AND um.meta_value = 'private' ) - ORDER BY created_at DESC, id DESC LIMIT %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table names are trusted WordPress tables. + ORDER BY created_at DESC, id DESC LIMIT %d", $event_id, $blog_id, EXTRACHILL_USERS_EVENT_ATTENDANCE_VISIBILITY_META_KEY, $limit ) ); + // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared $attendees = array(); foreach ( $user_ids as $uid ) { @@ -1298,13 +1299,11 @@ function ec_users_search_events_for_marking( int $user_id, array $args = array() ); $prepare = $past['prepare']; - // Build search clause if query provided. - if ( '' !== $query ) { - $like = '%' . $wpdb->esc_like( $query ) . '%'; + $like = '%' . $wpdb->esc_like( $query ) . '%'; - // Subquery: term-ids whose names match the query, restricted to artist/venue. - // We use IN (...) against tr.term_taxonomy_id via a join in OR clause. - $where[] = '(p.post_title LIKE %s OR EXISTS ( + // Subquery: term-ids whose names match the query, restricted to artist/venue. + // We use IN (...) against tr.term_taxonomy_id via a join in OR clause. + $where[] = '(p.post_title LIKE %s OR EXISTS ( SELECT 1 FROM ' . $tr_table . ' tr2 INNER JOIN ' . $tt_table . ' tt2 ON tr2.term_taxonomy_id = tt2.term_taxonomy_id @@ -1313,9 +1312,8 @@ function ec_users_search_events_for_marking( int $user_id, array $args = array() AND tt2.taxonomy IN (\'artist\', \'venue\') AND t2.name LIKE %s ))'; - $prepare[] = $like; - $prepare[] = $like; - } + $prepare[] = $like; + $prepare[] = $like; $where_sql = implode( ' AND ', $where ); diff --git a/inc/core/abilities/artist-access.php b/inc/core/abilities/artist-access.php index 79d1310..3a2c591 100644 --- a/inc/core/abilities/artist-access.php +++ b/inc/core/abilities/artist-access.php @@ -149,8 +149,7 @@ function extrachill_users_register_artist_access_abilities() { /** * List all pending artist access requests. * - * @param array $input Unused. - * @return array Array with 'requests' key containing pending request data. + * @return array|WP_Error Array with pending request data, or a permission error. */ function extrachill_users_ability_list_artist_access_requests() { $allowed = extrachill_users_require_artist_access_admin(); diff --git a/inc/core/abilities/concert-import.php b/inc/core/abilities/concert-import.php index 95d5cef..362626f 100644 --- a/inc/core/abilities/concert-import.php +++ b/inc/core/abilities/concert-import.php @@ -184,11 +184,11 @@ function extrachill_users_shape_concert_import_source( $source, int $user_id ): $rate = $source->rate_limit(); return array( - 'slug' => $slug, - 'label' => $source->label(), - 'configured' => $source->is_configured(), - 'username' => $username, - 'rate_limit' => array( + 'slug' => $slug, + 'label' => $source->label(), + 'configured' => $source->is_configured(), + 'username' => $username, + 'rate_limit' => array( 'requests_per_second' => isset( $rate['requests_per_second'] ) ? (float) $rate['requests_per_second'] : 0.0, 'requests_per_day' => isset( $rate['requests_per_day'] ) ? (int) $rate['requests_per_day'] : 0, ), diff --git a/inc/core/abilities/entity-subscriptions.php b/inc/core/abilities/entity-subscriptions.php index 2873d73..76421cc 100644 --- a/inc/core/abilities/entity-subscriptions.php +++ b/inc/core/abilities/entity-subscriptions.php @@ -102,7 +102,7 @@ function extrachill_users_entity_subscription_recipient_ability_permission(): bo /** * Execute a self-only entity subscription operation. * - * @param array $input Ability input. + * @param array $input Ability input. * @param string $operation subscribe, unsubscribe, or status. * @return array|WP_Error */ diff --git a/inc/core/abilities/get-user-artist-access.php b/inc/core/abilities/get-user-artist-access.php index e3c0b7b..8f70623 100644 --- a/inc/core/abilities/get-user-artist-access.php +++ b/inc/core/abilities/get-user-artist-access.php @@ -69,6 +69,7 @@ function extrachill_users_register_get_user_artist_access_ability(): void { * @return array|WP_Error Artist access status or error. */ function extrachill_users_ability_get_user_artist_access( array $input ): array|WP_Error { + unset( $input ); $user_id = get_current_user_id(); if ( ! $user_id ) { diff --git a/inc/core/abilities/notifications.php b/inc/core/abilities/notifications.php index dd897c0..9b6cce3 100644 --- a/inc/core/abilities/notifications.php +++ b/inc/core/abilities/notifications.php @@ -221,8 +221,8 @@ function extrachill_users_register_notification_abilities() { 'output_schema' => array( 'type' => 'object', 'properties' => array( - 'user_id' => array( 'type' => 'integer' ), - 'emails_enabled' => array( + 'user_id' => array( 'type' => 'integer' ), + 'emails_enabled' => array( 'type' => 'boolean', 'description' => 'True when the user receives unread-notification digest emails.', ), @@ -256,7 +256,7 @@ function extrachill_users_register_notification_abilities() { 'input_schema' => array( 'type' => 'object', 'properties' => array( - 'emails_enabled' => array( + 'emails_enabled' => array( 'type' => 'boolean', 'description' => 'Set true to receive unread-notification digest emails, false to opt out.', ), diff --git a/inc/core/abilities/onboarding.php b/inc/core/abilities/onboarding.php index dbfbcae..fc74e4a 100644 --- a/inc/core/abilities/onboarding.php +++ b/inc/core/abilities/onboarding.php @@ -345,14 +345,14 @@ function ec_users_restore_onboarding_transition_meta( $user_id, array $previous_ $restored = true; foreach ( $previous_meta as $meta_key => $previous ) { if ( $previous['exists'] ) { - $write_failed = false === update_user_meta( $user_id, $meta_key, $previous['value'] ); + update_user_meta( $user_id, $meta_key, $previous['value'] ); $restored_value = get_user_meta( $user_id, $meta_key, true ); $key_restored = $restored_value === $previous['value']; } else { - $write_failed = false === delete_user_meta( $user_id, $meta_key ); + delete_user_meta( $user_id, $meta_key ); $key_restored = ! metadata_exists( 'user', $user_id, $meta_key ); } - $restored = $restored && $key_restored && ( ! $write_failed || $key_restored ); + $restored = $restored && $key_restored; } return $restored; diff --git a/inc/core/abilities/subscriptions.php b/inc/core/abilities/subscriptions.php index 5ca4476..acabe99 100644 --- a/inc/core/abilities/subscriptions.php +++ b/inc/core/abilities/subscriptions.php @@ -117,8 +117,8 @@ function extrachill_users_ability_get_subscriptions() { if ( ! empty( $results ) ) { foreach ( $results as $row ) { - $artist_id = (int) $row['artist_profile_id']; - $followed_artists[] = array( + $artist_id = (int) $row['artist_profile_id']; + $followed_artists[] = array( 'artist_id' => $artist_id, 'name' => get_the_title( $artist_id ), 'url' => get_permalink( $artist_id ), diff --git a/inc/core/abilities/user-settings.php b/inc/core/abilities/user-settings.php index c20f076..087f3f5 100644 --- a/inc/core/abilities/user-settings.php +++ b/inc/core/abilities/user-settings.php @@ -224,7 +224,7 @@ function extrachill_users_ability_get_settings() { 'display_name_options' => array_values( $display_name_options ), 'email' => $user->user_email, 'pending_email' => $pending_email, - 'onboarding_completed' => function_exists( 'ec_is_onboarding_complete' ) ? ec_is_onboarding_complete( $user_id ) : true, + 'onboarding_completed' => function_exists( 'ec_is_onboarding_complete' ) ? ec_is_onboarding_complete( $user_id ) : true, 'local_scene' => $local_scene, 'local_scene_visibility' => extrachill_users_get_local_scene_visibility( $user_id ), 'concert_history_visibility' => extrachill_users_get_concert_history_visibility( $user_id ), diff --git a/inc/core/abilities/users-leaderboard.php b/inc/core/abilities/users-leaderboard.php index 9316323..586dad9 100644 --- a/inc/core/abilities/users-leaderboard.php +++ b/inc/core/abilities/users-leaderboard.php @@ -120,7 +120,7 @@ function extrachill_users_ability_leaderboard( array $input ): array { ) ); - $total = (int) $total_query->get_total(); + $total = (int) $total_query->get_total(); // $per_page is clamped to 1..100 above, so the divisor is always > 0. $total_pages = (int) ceil( $total / $per_page ); diff --git a/inc/core/feature-rollout-admin.php b/inc/core/feature-rollout-admin.php index 72f3735..1cf4a1d 100644 --- a/inc/core/feature-rollout-admin.php +++ b/inc/core/feature-rollout-admin.php @@ -120,7 +120,7 @@ function ec_feature_rollout_render_page() {

- +

diff --git a/inc/core/local-scene-migration.php b/inc/core/local-scene-migration.php index 904d8bc..30e91b8 100644 --- a/inc/core/local-scene-migration.php +++ b/inc/core/local-scene-migration.php @@ -86,23 +86,70 @@ static function ( $candidate ) use ( $value, $search_value, $state_value ) { */ function extrachill_users_local_scene_state_abbreviations(): array { return array( - 'AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', - 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', - 'DC' => 'District of Columbia', 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', - 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', - 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', - 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', - 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', - 'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', - 'NY' => 'New York', 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', - 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', - 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', - 'UT' => 'Utah', 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', - 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming', - 'AB' => 'Alberta', 'BC' => 'British Columbia', 'MB' => 'Manitoba', 'NB' => 'New Brunswick', - 'NL' => 'Newfoundland and Labrador', 'NS' => 'Nova Scotia', 'NT' => 'Northwest Territories', - 'NU' => 'Nunavut', 'ON' => 'Ontario', 'PE' => 'Prince Edward Island', - 'QC' => 'Quebec', 'SK' => 'Saskatchewan', 'YT' => 'Yukon', + 'AL' => 'Alabama', + 'AK' => 'Alaska', + 'AZ' => 'Arizona', + 'AR' => 'Arkansas', + 'CA' => 'California', + 'CO' => 'Colorado', + 'CT' => 'Connecticut', + 'DE' => 'Delaware', + 'DC' => 'District of Columbia', + 'FL' => 'Florida', + 'GA' => 'Georgia', + 'HI' => 'Hawaii', + 'ID' => 'Idaho', + 'IL' => 'Illinois', + 'IN' => 'Indiana', + 'IA' => 'Iowa', + 'KS' => 'Kansas', + 'KY' => 'Kentucky', + 'LA' => 'Louisiana', + 'ME' => 'Maine', + 'MD' => 'Maryland', + 'MA' => 'Massachusetts', + 'MI' => 'Michigan', + 'MN' => 'Minnesota', + 'MS' => 'Mississippi', + 'MO' => 'Missouri', + 'MT' => 'Montana', + 'NE' => 'Nebraska', + 'NV' => 'Nevada', + 'NH' => 'New Hampshire', + 'NJ' => 'New Jersey', + 'NM' => 'New Mexico', + 'NY' => 'New York', + 'NC' => 'North Carolina', + 'ND' => 'North Dakota', + 'OH' => 'Ohio', + 'OK' => 'Oklahoma', + 'OR' => 'Oregon', + 'PA' => 'Pennsylvania', + 'RI' => 'Rhode Island', + 'SC' => 'South Carolina', + 'SD' => 'South Dakota', + 'TN' => 'Tennessee', + 'TX' => 'Texas', + 'UT' => 'Utah', + 'VT' => 'Vermont', + 'VA' => 'Virginia', + 'WA' => 'Washington', + 'WV' => 'West Virginia', + 'WI' => 'Wisconsin', + 'WY' => 'Wyoming', + 'AB' => 'Alberta', + 'BC' => 'British Columbia', + 'MB' => 'Manitoba', + 'NB' => 'New Brunswick', + 'NL' => 'Newfoundland and Labrador', + 'NS' => 'Nova Scotia', + 'NT' => 'Northwest Territories', + 'NU' => 'Nunavut', + 'ON' => 'Ontario', + 'PE' => 'Prince Edward Island', + 'QC' => 'Quebec', + 'SK' => 'Saskatchewan', + 'YT' => 'Yukon', ); } diff --git a/inc/core/registration-emails.php b/inc/core/registration-emails.php index df0ecd4..bf232e1 100644 --- a/inc/core/registration-emails.php +++ b/inc/core/registration-emails.php @@ -48,7 +48,7 @@ function extrachill_send_registration_email( array $args ) { } $helper = '\DataMachine\Abilities\PermissionHelper'; - if ( class_exists( $helper ) && method_exists( $helper, 'run_as_authenticated' ) ) { + if ( class_exists( $helper ) ) { return $helper::run_as_authenticated( static function () use ( $args ) { return ec_send_email( $args ); diff --git a/inc/entity-subscriptions/service.php b/inc/entity-subscriptions/service.php index f28fa71..55492f2 100644 --- a/inc/entity-subscriptions/service.php +++ b/inc/entity-subscriptions/service.php @@ -65,7 +65,7 @@ function extrachill_users_normalize_entity_subscription( $entity_type, $taxonomy /** * Subscribe a user to a canonical entity. * - * @param int $user_id User ID. + * @param int $user_id User ID. * @param string $entity_type Entity type. * @param string $taxonomy Taxonomy. * @param string $slug Entity slug. @@ -102,7 +102,7 @@ function extrachill_users_subscribe_to_entity( $user_id, $entity_type, $taxonomy /** * Unsubscribe a user from a canonical entity. * - * @param int $user_id User ID. + * @param int $user_id User ID. * @param string $entity_type Entity type. * @param string $taxonomy Taxonomy. * @param string $slug Entity slug. @@ -138,7 +138,7 @@ function extrachill_users_unsubscribe_from_entity( $user_id, $entity_type, $taxo /** * Get one user's subscription status. * - * @param int $user_id User ID. + * @param int $user_id User ID. * @param string $entity_type Entity type. * @param string $taxonomy Taxonomy. * @param string $slug Entity slug. diff --git a/inc/notifications/read-redirect.php b/inc/notifications/read-redirect.php index 7212e5f..fd7af42 100644 --- a/inc/notifications/read-redirect.php +++ b/inc/notifications/read-redirect.php @@ -398,7 +398,7 @@ function ec_notifications_read_redirect_allowed_hosts() { if ( function_exists( 'get_sites' ) && is_multisite() ) { $sites = get_sites( array( 'number' => 0 ) ); foreach ( (array) $sites as $site ) { - $domain = isset( $site->domain ) ? strtolower( (string) $site->domain ) : ''; + $domain = strtolower( (string) $site->domain ); if ( '' !== $domain ) { $hosts[] = $domain; } diff --git a/inc/rank-system/contribution-events.php b/inc/rank-system/contribution-events.php index f7c14b2..ecf6290 100644 --- a/inc/rank-system/contribution-events.php +++ b/inc/rank-system/contribution-events.php @@ -47,9 +47,9 @@ * @return array */ function ec_bucket_utc_events_by_local_day( array $utc_datetimes, $type, $since_ymd = '' ) { - $tz = wp_timezone(); - $utc_tz = new DateTimeZone( 'UTC' ); - $by_date = array(); + $tz = wp_timezone(); + $utc_tz = new DateTimeZone( 'UTC' ); + $by_date = array(); foreach ( $utc_datetimes as $dt_str ) { try { diff --git a/inc/wp-native-bridge.php b/inc/wp-native-bridge.php index 01c5f91..d783239 100644 --- a/inc/wp-native-bridge.php +++ b/inc/wp-native-bridge.php @@ -34,6 +34,7 @@ * @return null|WP_Error Null to continue, WP_Error to block login. */ function extrachill_users_wp_native_pre_login_check( null|WP_Error $result, WP_User $user, array $context ): null|WP_Error { + unset( $context ); if ( $result instanceof WP_Error ) { return $result; // Earlier filter already blocked. } @@ -83,6 +84,7 @@ function extrachill_users_wp_native_pre_login_check( null|WP_Error $result, WP_U * @return array The decorated User payload. */ function extrachill_users_wp_native_decorate_user( array $payload, WP_User $wp_user, array $context ): array { + unset( $context ); if ( function_exists( 'extrachill_get_user_profile_url' ) ) { $payload['profile_url'] = extrachill_get_user_profile_url( $wp_user->ID, $wp_user->user_email ); } @@ -114,6 +116,7 @@ function extrachill_users_wp_native_decorate_user( array $payload, WP_User $wp_u * @return null|WP_Error Null to continue, WP_Error to block. */ function extrachill_users_wp_native_pre_authenticate( null|WP_Error $result, string $identifier, array $context ): null|WP_Error { + unset( $identifier, $context ); if ( $result instanceof WP_Error ) { return $result; } @@ -180,7 +183,8 @@ function extrachill_users_wp_native_after_login( int $user_id, string $device_id * @param array $context Contextual data from wp-native-auth (device_id, etc.). * @return WP_Error Existing policy error or the fail-closed site policy error. */ -function extrachill_users_wp_native_pre_register( null|WP_Error $result, array &$registration_data, array $context ): null|WP_Error { +function extrachill_users_wp_native_pre_register( null|WP_Error $result, array &$registration_data, array $context ): WP_Error { + unset( $registration_data, $context ); if ( $result instanceof WP_Error ) { return $result; // Earlier filter already blocked. } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 964cc9f..dd583e3 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,11 +1,27 @@ +includes: + - vendor/szepeviktor/phpstan-wordpress/extension.neon + parameters: level: 5 + treatPhpDocTypesAsCertain: false # Production runs PHP 8.4. Allow PHPStan to recognise native PHP 8.0+ # union types (e.g. `null|WP_Error`) and matching narrowing semantics. phpVersion: 80000 + excludePaths: + analyseAndScan: + - %currentWorkingDirectory%/../extrachill-network/tests/* + - %currentWorkingDirectory%/../extrachill-api/tests/* + ignoreErrors: + - + identifier: require.fileNotFound + path: inc/concert-tracking/buttons.php + count: 1 paths: - - extrachill-users.php - inc - blocks - stubFiles: + scanFiles: + - extrachill-users.php - tests/phpstan-stubs.php + - vendor/php-stubs/wp-cli-stubs/wp-cli-stubs.php + stubFiles: + - tests/phpstan-wordpress-overrides.php diff --git a/tests/phpstan-stubs.php b/tests/phpstan-stubs.php index 2a695cb..cbc5980 100644 --- a/tests/phpstan-stubs.php +++ b/tests/phpstan-stubs.php @@ -1,43 +1,67 @@ $args + * @return array + */ + function ec_send_email( array $args ): array {} -if ( ! function_exists( 'ec_render_turnstile_widget' ) ) { - function ec_render_turnstile_widget(): string { - return ''; - } + /** + * @param array $args + * @return array + */ + function ec_send_email_queued( array $args ): array {} + + /** @return array{token:string,expires_at:int} */ + function wp_native_auth_generate_access_token( int $user_id, string $device_id ): array {} + + /** @return array{token:string,expires_at:int} */ + function wp_native_auth_issue_refresh_token( int $user_id, string $device_id, string $device_name = '' ): array {} + + /** @return array|\WP_Error */ + function wp_native_auth_refresh_tokens( string $refresh_token, string $device_id ): array|\WP_Error {} + + function wp_native_auth_revoke_refresh_token( int $user_id, string $device_id ): bool {} } -if ( ! function_exists( 'ec_verify_turnstile_response' ) ) { - function ec_verify_turnstile_response( string $token ): bool { - return true; +namespace DataMachine\Core\OAuth { + abstract class BaseAuthProvider { + public function __construct( string $provider_slug ) {} + + /** @return array */ + protected function get_config(): array {} } } -if ( ! function_exists( 'ec_icon' ) ) { - function ec_icon( string $name, string $class = '' ): string { - return ''; +namespace DataMachine\Abilities { + class PermissionHelper { + public static function run_as_authenticated( callable $callback, int $acting_user_id = 0 ): mixed {} } } diff --git a/tests/phpstan-wordpress-overrides.php b/tests/phpstan-wordpress-overrides.php new file mode 100644 index 0000000..808a029 --- /dev/null +++ b/tests/phpstan-wordpress-overrides.php @@ -0,0 +1,16 @@ +