diff --git a/assets/src/admin/onboarding/page.tsx b/assets/src/admin/onboarding/page.tsx index b50e09c..ec4d129 100644 --- a/assets/src/admin/onboarding/page.tsx +++ b/assets/src/admin/onboarding/page.tsx @@ -27,8 +27,11 @@ interface NoticeState { } // WordPress provides snake_case keys here. Using them intentionally. -// eslint-disable-next-line camelcase -const { nonce, setup_url, site_type } = window.OneUpdateOnboarding; +const { + nonce, + setup_url: setupUrl, + site_type: initialSiteType, +} = window.OneUpdateOnboarding; /** * Create NONCE middleware for apiFetch @@ -65,7 +68,7 @@ const SiteTypeSelector = ( { const OnboardingScreen = () => { const [ siteType, setSiteType ] = useState< SiteType | '' >( - site_type || '' + initialSiteType || '' ); const [ notice, setNotice ] = useState< NoticeState | null >( null ); const [ isSaving, setIsSaving ] = useState( false ); @@ -105,8 +108,8 @@ const OnboardingScreen = () => { setSiteType( settings.oneupdate_site_type ); // Redirect user to setup page. - if ( setup_url ) { - window.location.href = setup_url; + if ( setupUrl ) { + window.location.href = setupUrl; } } ); } catch { diff --git a/assets/src/admin/plugin-manager/index.js b/assets/src/admin/plugin-manager/index.js index 008fff9..59e9168 100644 --- a/assets/src/admin/plugin-manager/index.js +++ b/assets/src/admin/plugin-manager/index.js @@ -108,14 +108,14 @@ const PluginManager = () => { } else { setIsValidS3Credentials( false ); } - } catch ( error ) { + } catch { setIsValidS3Credentials( false ); } }, [] ); useEffect( () => { performHealthCheckOnS3Credentials(); - }, [] ); + }, [ performHealthCheckOnS3Credentials ] ); const fetchSitesWithPluginLoader = useCallback( async () => { try { @@ -139,7 +139,7 @@ const PluginManager = () => { const data = await response.json(); setAllAvailableSites( data.shared_sites || [] ); // Store all available sites for later use return data.success ? data.shared_sites : []; - } catch ( error ) { + } catch { return []; } }, [] ); @@ -170,7 +170,7 @@ const PluginManager = () => { const data = await response.json(); return data.success ? data.plugins : {}; - } catch ( error ) { + } catch { return {}; } }, [] ); @@ -588,6 +588,7 @@ const PluginManager = () => { typeFilter, updateFilter, siteFilter, + allAvailableSites.length, ] ); const getUpdateTooltipText = ( plugin ) => { @@ -946,7 +947,7 @@ const PluginManager = () => { // Refresh plugins data await fetchRealTimePluginsData(); - } catch ( error ) { + } catch { setGlobalNotice( { status: 'error', message: sprintf( @@ -1098,7 +1099,7 @@ const PluginManager = () => { status: 'success', message: noticeMessage, } ); - } catch ( error ) { + } catch { setGlobalNotice( { status: 'error', message: __( 'Failed to update plugins.', 'oneupdate' ), @@ -1114,7 +1115,7 @@ const PluginManager = () => { setSelectedSites( ( prev ) => [ ...prev, url ] ); } else { setSelectedSites( ( prev ) => - prev.filter( ( url ) => url !== url ) + prev.filter( ( siteUrl ) => siteUrl !== url ) ); } }; diff --git a/assets/src/admin/settings/page.tsx b/assets/src/admin/settings/page.tsx index 6ba3ef3..260dd47 100644 --- a/assets/src/admin/settings/page.tsx +++ b/assets/src/admin/settings/page.tsx @@ -79,7 +79,7 @@ const SettingsPage = () => { if ( SITE_TYPE === 'governing-site' ) { fetchAllAvailableGitHubRepos(); } - }, [ SITE_TYPE ] ); + }, [ fetchAllAvailableGitHubRepos ] ); useEffect( () => { apiFetch< { shared_sites?: BrandSite[] } >( { diff --git a/assets/src/components/GitHubRepoToken.tsx b/assets/src/components/GitHubRepoToken.tsx index d35ba41..e0cccf2 100644 --- a/assets/src/components/GitHubRepoToken.tsx +++ b/assets/src/components/GitHubRepoToken.tsx @@ -37,6 +37,7 @@ const GitHubRepoToken = ( { } ); if ( ! response.ok ) { + // eslint-disable-next-line no-console console.error( 'Error fetching GitHub token:', response.statusText @@ -52,50 +53,56 @@ const GitHubRepoToken = ( { useEffect( () => { getRepoToken(); - }, [] ); - - const setGitHubRepoToken = useCallback( async ( token: string ) => { - const response = await fetch( `${ API_NAMESPACE }/github-token`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-WP-NONCE': NONCE, - }, - body: JSON.stringify( { token } ), - } ); + }, [ getRepoToken ] ); - if ( response.ok === false || response.status === 400 ) { - setNotice( { - type: 'error', - message: __( - 'Please enter valid GitHub PAT token.', - 'oneupdate' - ), + const setGitHubRepoToken = useCallback( + async ( token: string ) => { + const response = await fetch( `${ API_NAMESPACE }/github-token`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-WP-NONCE': NONCE, + }, + body: JSON.stringify( { token } ), } ); - return; - } - const data = await response.json(); - if ( data?.status === '400' ) { - setNotice( { - type: 'error', - message: - data?.message || - __( 'Enter valid PAT token.', 'oneupdate' ), - } ); - return; - } + if ( response.ok === false || response.status === 400 ) { + setNotice( { + type: 'error', + message: __( + 'Please enter valid GitHub PAT token.', + 'oneupdate' + ), + } ); + return; + } + const data = await response.json(); - if ( data?.success ) { - setNotice( { - type: 'success', - message: __( 'GitHub token saved successfully.', 'oneupdate' ), - } ); - await fetchAllAvailableGitHubRepos(); - } else { - console.error( 'Error setting GitHub token:', data ); // eslint-disable-line no-console - } - }, [] ); + if ( data?.status === '400' ) { + setNotice( { + type: 'error', + message: + data?.message || + __( 'Enter valid PAT token.', 'oneupdate' ), + } ); + return; + } + + if ( data?.success ) { + setNotice( { + type: 'success', + message: __( + 'GitHub token saved successfully.', + 'oneupdate' + ), + } ); + await fetchAllAvailableGitHubRepos(); + } else { + console.error( 'Error setting GitHub token:', data ); // eslint-disable-line no-console + } + }, + [ fetchAllAvailableGitHubRepos, setNotice ] + ); return ( diff --git a/assets/src/components/PluginGrid.js b/assets/src/components/PluginGrid.js index ea94bbc..5a0e454 100644 --- a/assets/src/components/PluginGrid.js +++ b/assets/src/components/PluginGrid.js @@ -17,8 +17,8 @@ import { */ import PluginCard from './PluginCard'; -const API_NAMESPACE = OneUpdatePlugins.restUrl + '/oneupdate/v1'; -const API_KEY = OneUpdatePlugins.api_key; +const API_NAMESPACE = window.OneUpdatePlugins.restUrl + '/oneupdate/v1'; +const API_KEY = window.OneUpdatePlugins.api_key; const PluginGrid = () => { const [ page, setPage ] = useState( 1 ); @@ -105,7 +105,7 @@ const PluginGrid = () => { useEffect( () => { fetchSharedSitesData(); - }, [] ); + }, [ fetchSharedSitesData ] ); const handleSearchSubmit = () => { setPage( 1 ); @@ -355,7 +355,7 @@ const ApplyPluginsModal = ( { ), } ); } - } catch ( error ) { + } catch { setIsNoticeVisible( true ); setNoticeMessage( { type: 'error', diff --git a/assets/src/components/PluginsSharing.js b/assets/src/components/PluginsSharing.js index f88695f..06e792d 100644 --- a/assets/src/components/PluginsSharing.js +++ b/assets/src/components/PluginsSharing.js @@ -17,8 +17,8 @@ import { } from '@wordpress/components'; import { decodeEntities } from '@wordpress/html-entities'; -const API_NAMESPACE = OneUpdatePlugins.restUrl + '/oneupdate/v1'; -const RestNonce = OneUpdatePlugins.restNonce; +const API_NAMESPACE = window.OneUpdatePlugins.restUrl + '/oneupdate/v1'; +const RestNonce = window.OneUpdatePlugins.restNonce; const PluginCard = ( { plugin, @@ -315,7 +315,7 @@ const PluginGrid = () => { if ( searchQuery ) { fetchPlugins(); } - }, [ fetchPlugins ] ); + }, [ fetchPlugins, searchQuery ] ); const handleRetry = () => fetchPlugins(); @@ -358,7 +358,7 @@ const PluginGrid = () => { useEffect( () => { fetchSharedSitesData(); - }, [] ); + }, [ fetchSharedSitesData ] ); const handleSearchSubmit = () => { if ( ! searchInput.trim() ) { @@ -749,7 +749,7 @@ const ApplyPluginsModal = ( { ), } ); } - } catch ( error ) { + } catch { setIsNoticeVisible( true ); setNoticeMessage( { type: 'error', diff --git a/assets/src/components/S3Credentials.tsx b/assets/src/components/S3Credentials.tsx index f8c6542..34134b8 100644 --- a/assets/src/components/S3Credentials.tsx +++ b/assets/src/components/S3Credentials.tsx @@ -71,11 +71,11 @@ const S3Credentials = ( { setS3Credentials( data.s3_credentials ); } setIsLoading( false ); - }, [] ); + }, [ setNotice ] ); useEffect( () => { getS3Credentials(); - }, [] ); + }, [ getS3Credentials ] ); const saveS3Credentials = useCallback( async () => { setIsSaving( true ); diff --git a/assets/src/components/S3ZipUploader.js b/assets/src/components/S3ZipUploader.js index 41c675e..041f40f 100644 --- a/assets/src/components/S3ZipUploader.js +++ b/assets/src/components/S3ZipUploader.js @@ -587,7 +587,7 @@ const ApplyPluginsModal = ( { useEffect( () => { fetchSharedSitesData(); - }, [] ); + }, [ fetchSharedSitesData ] ); const applySelectedPlugins = useCallback( async () => { setApplyingPlugins( true ); @@ -665,7 +665,7 @@ const ApplyPluginsModal = ( { data.message, } ); } - } catch ( error ) { + } catch { setCurrentNotice( { status: 'error', message: __( @@ -681,6 +681,7 @@ const ApplyPluginsModal = ( { setShowApplyPluginsModal, selectedSiteInfo, setCurrentNotice, + setApplyingPlugins, ] ); const handleClose = () => { @@ -788,13 +789,13 @@ const S3ZipUploader = () => { } else { setSharedSites( [] ); } - } catch ( error ) { + } catch { setSharedSites( [] ); } }, [] ); // Fetch upload history - const fetchHistory = () => { + const fetchHistory = useCallback( () => { setLoadingHistory( true ); apiFetch( { path: '/oneupdate/v1/history' } ) .then( ( data ) => { @@ -813,12 +814,12 @@ const S3ZipUploader = () => { .catch( () => { setLoadingHistory( false ); } ); - }; + }, [] ); useEffect( () => { fetchHistory(); fetchSharedSitesData(); - }, [] ); + }, [ fetchHistory, fetchSharedSitesData ] ); // Handle file selection const handleFileChange = ( event ) => { diff --git a/assets/src/components/SiteModal.tsx b/assets/src/components/SiteModal.tsx index 4ad3df2..d21df1a 100644 --- a/assets/src/components/SiteModal.tsx +++ b/assets/src/components/SiteModal.tsx @@ -195,7 +195,7 @@ const SiteModal = ( { } ); setShowNotice( true ); } - } catch ( error ) { + } catch { setErrors( { ...newErrors, message: __( diff --git a/assets/src/components/SiteSettings.tsx b/assets/src/components/SiteSettings.tsx index 5cd713f..5d93dc1 100644 --- a/assets/src/components/SiteSettings.tsx +++ b/assets/src/components/SiteSettings.tsx @@ -28,7 +28,7 @@ const NONCE = window.OneUpdateSettings.restNonce; const API_KEY = window.OneUpdateSettings.api_key; const SiteSettings = () => { - const [ api_key, setApiKey ] = useState( '' ); + const [ apiKey, setApiKey ] = useState( '' ); const [ isLoading, setIsLoading ] = useState( false ); const [ notice, setNotice ] = useState< NoticeType | null >( null ); const [ governingSite, setGoverningSite ] = useState( '' ); @@ -51,7 +51,7 @@ const SiteSettings = () => { } const data = await response.json(); setApiKey( data?.secret_key || '' ); - } catch ( error ) { + } catch { setNotice( { type: 'error', message: __( @@ -96,7 +96,7 @@ const SiteSettings = () => { ), } ); } - } catch ( error ) { + } catch { setNotice( { type: 'error', message: __( @@ -117,7 +117,7 @@ const SiteSettings = () => { headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': NONCE, - 'X-OneUpdate-Token': api_key, + 'X-OneUpdate-Token': apiKey, }, } ); @@ -126,7 +126,7 @@ const SiteSettings = () => { } const data = await response.json(); setGoverningSite( data?.governing_site_url || '' ); - } catch ( error ) { + } catch { setNotice( { type: 'error', message: __( @@ -137,7 +137,7 @@ const SiteSettings = () => { } finally { setIsLoading( false ); } - }, [ api_key ] ); + }, [ apiKey ] ); const deleteGoverningSiteConnection = useCallback( async () => { try { @@ -146,7 +146,7 @@ const SiteSettings = () => { headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': NONCE, - 'X-OneUpdate-Token': api_key, + 'X-OneUpdate-Token': apiKey, }, } ); if ( ! response.ok ) { @@ -160,7 +160,7 @@ const SiteSettings = () => { 'oneupdate' ), } ); - } catch ( error ) { + } catch { setNotice( { type: 'error', message: __( @@ -171,7 +171,7 @@ const SiteSettings = () => { } finally { setShowDisconnectionModal( false ); } - }, [ api_key ] ); + }, [ apiKey ] ); const handleDisconnectGoverningSite = useCallback( async () => { setShowDisconnectionModal( true ); @@ -207,7 +207,7 @@ const SiteSettings = () => { variant="primary" onClick={ () => { navigator?.clipboard - ?.writeText( api_key ) + ?.writeText( apiKey ) .then( () => { setNotice( { type: 'success', @@ -217,16 +217,13 @@ const SiteSettings = () => { ), } ); } ) - .catch( ( error ) => { + .catch( () => { setNotice( { type: 'error', - message: - __( - 'Failed to copy api key. Please try again.', - 'oneupdate' - ) + - ' ' + - error, + message: __( + 'Failed to copy api key. Please try again.', + 'oneupdate' + ), } ); } ); } } @@ -246,7 +243,7 @@ const SiteSettings = () => {
{ try { const parsedUrl = new URL( url ); return isURL( parsedUrl.href ); - } catch ( e ) { + } catch { return false; } }; diff --git a/inc/Modules/Plugin/Cache.php b/inc/Modules/Plugin/Cache.php index 7806745..ce1e200 100644 --- a/inc/Modules/Plugin/Cache.php +++ b/inc/Modules/Plugin/Cache.php @@ -77,10 +77,10 @@ public function remove_plugin_from_transient(): void { /** * Clear the cache after plugin update. * - * @param \WP_Upgrader $upgrader The upgrader instance. + * @param \WP_Upgrader $upgrader The upgrader instance. * @param array $hook_extra Extra hook data. */ - public function clear_update_plugin_cache( $upgrader, $hook_extra ): void { + public function clear_update_plugin_cache( $upgrader, $hook_extra ): void { // phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter // Check if the plugin being updated is the OneUpdate plugin. if ( ! isset( $hook_extra['action'] ) || 'update' !== $hook_extra['action'] || ! isset( $hook_extra['type'] ) || 'plugin' !== $hook_extra['type'] ) { return; @@ -92,6 +92,8 @@ public function clear_update_plugin_cache( $upgrader, $hook_extra ): void { /** * Build the plugins transient. + * + * @return array|\WP_Error */ public static function build_plugins_transient(): array|\WP_Error { if ( ! function_exists( 'get_plugins' ) ) { diff --git a/inc/Modules/Rest/Abstract_REST_Controller.php b/inc/Modules/Rest/Abstract_REST_Controller.php index be72828..7c8d8ef 100644 --- a/inc/Modules/Rest/Abstract_REST_Controller.php +++ b/inc/Modules/Rest/Abstract_REST_Controller.php @@ -154,6 +154,8 @@ private function get_stored_api_key( ?string $site_url = null ): string { * Get GitHub API headers with authorization. * * @param string $github_token GitHub personal access token. + * + * @return array GitHub API headers. */ protected static function get_github_headers( string $github_token ): array { return array_merge( diff --git a/inc/Modules/Rest/GH_Pull_Request_Controller.php b/inc/Modules/Rest/GH_Pull_Request_Controller.php index 908b927..3a1c990 100644 --- a/inc/Modules/Rest/GH_Pull_Request_Controller.php +++ b/inc/Modules/Rest/GH_Pull_Request_Controller.php @@ -342,9 +342,9 @@ private static function search_pull_requests_with_query_and_state( string $gh_ow /** * Extract total count from Link headers when using pulls API * - * @param array|\WpOrg\Requests\Utility\CaseInsensitiveDictionary $headers Response headers. - * @param int $current_count Current count of items fetched. - * @param int $per_page Number of items per page. Default is 25. + * @param array|\WpOrg\Requests\Utility\CaseInsensitiveDictionary $headers Response headers. + * @param int $current_count Current count of items fetched. + * @param int $per_page Number of items per page. Default is 25. * * @return int Total count of items. */ @@ -410,9 +410,9 @@ private static function get_specific_pull_request( string $gh_owner, string $gh_ /** * Format GitHub pull requests info to return only necessary fields. * - * @param array $pull_requests Array of pull requests from GitHub API. + * @param array> $pull_requests Array of pull requests from GitHub API. * - * @return array Formatted array of pull requests. + * @return array> Formatted array of pull requests. */ private static function format_github_pull_requests_info( array $pull_requests ): array { $formatted_prs = []; @@ -463,7 +463,7 @@ private static function format_github_pull_requests_info( array $pull_requests ) * * @param string $endpoint GitHub API endpoint. * - * @return array Array containing success status, data, headers, status_code, and message. + * @return array Array containing success status, data, headers, status_code, and message. */ private static function gh_api_request_with_validation( string $endpoint ): array { $response = self::gh_api_request( $endpoint ); @@ -524,7 +524,7 @@ private static function gh_api_request_with_validation( string $endpoint ): arra * * @param string $endpoint GitHub API endpoint. * - * @return array|\WP_Error Response array or WP_Error on failure. + * @return array|\WP_Error Response array or WP_Error on failure. */ private static function gh_api_request( string $endpoint ): array|\WP_Error { $gh_token = Plugin_Settings::get_github_token(); diff --git a/inc/Modules/Rest/Workflow_Controller.php b/inc/Modules/Rest/Workflow_Controller.php index 3959f45..95a5159 100644 --- a/inc/Modules/Rest/Workflow_Controller.php +++ b/inc/Modules/Rest/Workflow_Controller.php @@ -609,6 +609,8 @@ public function apply_private_plugins_to_selected_sites( \WP_REST_Request $reque * @param string $private_plugin The private plugin zip URL. * @param string $branch The branch to create PR against. * @param string $site_name The site name for which the action is triggered. + * + * @return array|\WP_Error Result array or WP_Error on failure. */ private function trigger_github_action_for_private_plugin( string $repo, string $private_plugin, string $branch, string $site_name ): array|\WP_Error { $github_token = Plugin_Settings::get_github_token(); @@ -875,6 +877,8 @@ public function apply_plugins_to_selected_sites( \WP_REST_Request $request ): \W * @param string $version The plugin version. * @param string $plugin_type The type of plugin action (add_update, deactivate, remove). * @param string $site_name The site name for which the action is triggered. + * + * @return array|\WP_Error Result array or WP_Error on failure. */ private function trigger_github_action_for_pr_creation( string $repo, string $branch, string $plugin_slug, string $version, string $plugin_type, string $site_name ): array|\WP_Error { $github_token = Plugin_Settings::get_github_token(); diff --git a/inc/Modules/Settings/Settings.php b/inc/Modules/Settings/Settings.php index 49c80ba..c778693 100644 --- a/inc/Modules/Settings/Settings.php +++ b/inc/Modules/Settings/Settings.php @@ -168,7 +168,7 @@ public function register_settings(): void { * @param mixed $old_value The old value. * @param mixed $new_value The new value. */ - public function on_site_type_change( $old_value, $new_value ): void { + public function on_site_type_change( $old_value, $new_value ): void { // phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter if ( self::SITE_TYPE_CONSUMER !== $new_value ) { return; }