Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
"php-stubs/wordpress-tests-stubs": "^6.8 || ^7.0",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"szepeviktor/phpstan-wordpress": "^1.3",
"yoast/phpunit-polyfills": "^4.0"
"yoast/phpunit-polyfills": "^4.0",
"silverassist/coding-standards": "^1.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -63,6 +65,9 @@
"optimize-autoloader": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
},
"platform": {
"php": "8.2.0"
}
},
"extra": {
Expand Down
27 changes: 12 additions & 15 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
<phpcs>
<!--
WP GitHub Updater - PHP Coding Standards Configuration

This configuration enforces the coding standards defined in our
project instructions, specifically:

🚨 MANDATORY STANDARDS:
- ALL strings MUST use double quotes: "string" not 'string'

Uses the shared SilverAssist ruleset (PSR-12 + mandatory PHPDoc)
from silverassist/coding-standards. This is a library, not a
WordPress plugin (no main plugin file, no plugins_loaded hook,
no WordPress dependency in composer.json's require), so PSR-12
applies instead of WordPress-Extra. A handful of WordPress-aware
sniffs are still layered on top since this package does call
WordPress functions:

- WordPress security best practices (escaping, sanitization)
- Text domain validation for i18n functions
- PSR-12 compliance for modern PHP 8+ conventions
- Proper documentation standards for public APIs

Package-specific allowances:
- PSR-4 naming conventions (not WordPress file naming)
- Namespace usage instead of global prefixes
- String interpolation with variables in double quotes
- Double-quote string enforcement (this package's own convention,
predates the shared ruleset)
- Reasonable line length limits (120/160 characters)
-->
<arg name="basepath" value="."/>
Expand All @@ -33,8 +31,7 @@
<file>src</file>
<file>tests</file>

<!-- Base PSR12 standard -->
<rule ref="PSR12"/>
<rule ref="SilverAssist"/>

<!-- 🚨 CRITICAL RULE: Enforce double quotes for strings -->
<!-- This is our MANDATORY string quotation standard -->
Expand Down
47 changes: 28 additions & 19 deletions src/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Updater
*
* Sets up plugin identification, version information and WordPress hooks.
*
* @param UpdaterConfig $config Updater configuration object
* @param UpdaterConfig $config Updater configuration object.
*
* @since 1.0.0
*/
Expand All @@ -106,6 +106,7 @@ public function __construct(UpdaterConfig $config)
*
*
* @since 1.0.0
* @return void
*/
private function initHooks(): void
{
Expand All @@ -132,12 +133,12 @@ private function initHooks(): void
* Compares the current plugin version with the latest GitHub release
* and adds update information to the WordPress update transient if needed.
*
* @param mixed $transient The update_plugins transient containing current plugin versions
* @param mixed $transient The update_plugins transient containing current plugin versions.
* @return mixed The modified transient with update information added if available
*
* @since 1.0.0
*/
public function checkForUpdate($transient)
public function checkForUpdate(mixed $transient)
{
if (empty($transient->checked)) {
return $transient;
Expand Down Expand Up @@ -167,9 +168,9 @@ public function checkForUpdate($transient)
* Provides detailed plugin information when WordPress requests it,
* including version, changelog, and download information.
*
* @param false|object|array $result The result object or array
* @param string $action The type of information being requested
* @param object $args Plugin API arguments
* @param false|object|array $result The result object or array.
* @param string $action The type of information being requested.
* @param object $args Plugin API arguments.
* @return false|object|array Plugin information object or original result
*
* @since 1.0.0
Expand Down Expand Up @@ -249,9 +250,10 @@ public function getLatestVersion(): string|false
/**
* Get download URL for a specific version
*
* @param string $version The version to download
* @param string $version The version to download.
*
* @since 1.0.0
* @return string
*/
private function getDownloadUrl(string $version): string
{
Expand All @@ -275,7 +277,7 @@ private function getDownloadUrl(string $version): string
/**
* Get actual asset download URL from GitHub API
*
* @param string $version The version to get asset URL for
* @param string $version The version to get asset URL for.
* @return string|null Asset download URL or null if not found
*
* @since 1.1.0
Expand Down Expand Up @@ -393,8 +395,9 @@ private function getLastUpdated(): string
/**
* Clear version cache after update
*
* @param WP_Upgrader $upgrader WP_Upgrader instance
* @param array $data Array of update data
* @param WP_Upgrader $upgrader WP_Upgrader instance.
* @param array $data Array of update data.
* @return void
*/
public function clearVersionCache(WP_Upgrader $upgrader, array $data): void
{
Expand All @@ -407,6 +410,7 @@ public function clearVersionCache(WP_Upgrader $upgrader, array $data): void

/**
* Manual version check via AJAX
* @return void
*/
public function manualVersionCheck(): void
{
Expand Down Expand Up @@ -494,6 +498,7 @@ public function dismissUpdateNotice(): void
* after a manual version check.
*
* @since 1.1.4
* @return void
*/
public function showUpdateNotice(): void
{
Expand Down Expand Up @@ -556,6 +561,7 @@ public function showUpdateNotice(): void

/**
* Get plugin data from file
* @return array
*/
private function getPluginData(): array
{
Expand All @@ -569,6 +575,7 @@ private function getPluginData(): array
/**
* Get current version
*
* @return string
*/
public function getCurrentVersion(): string
{
Expand All @@ -578,6 +585,7 @@ public function getCurrentVersion(): string
/**
* Get GitHub repository
*
* @return string
*/
public function getGithubRepo(): string
{
Expand All @@ -587,6 +595,7 @@ public function getGithubRepo(): string
/**
* Check if update is available
*
* @return boolean
*/
public function isUpdateAvailable(): bool
{
Expand All @@ -602,7 +611,7 @@ public function isUpdateAvailable(): bool
* the need for consuming plugins to maintain their own JavaScript files.
* The script is loaded once and works for multiple plugins on the same page.
*
* @param array<string, string> $extraStrings Optional extra i18n string overrides
* @param array<string, string> $extraStrings Optional extra i18n string overrides.
* @return string Inline JS to echo (e.g. "wpGithubUpdaterCheckUpdates('myData'); return false;")
*
* @since 1.3.0
Expand Down Expand Up @@ -653,7 +662,7 @@ public function enqueueCheckUpdatesScript(array $extraStrings = []): string
* PHP's autoloader loads the class from the first registered vendor directory, but
* each plugin instance needs to load assets from its own vendor directory.
*
* @param string $assetPath Relative path to asset (e.g., 'assets/js/check-updates.js')
* @param string $assetPath Relative path to asset (e.g., 'assets/js/check-updates.js').
* @return string Full URL to the asset file
*
* @since 1.3.0
Expand Down Expand Up @@ -695,7 +704,7 @@ private function getPackageAssetUrl(string $assetPath): string
* Removes or replaces characters that are not valid in JavaScript identifiers.
* Used to generate unique global variable names for wp_localize_script.
*
* @param string $name Raw name to sanitize
* @param string $name Raw name to sanitize.
* @return string Valid JavaScript variable name
*
* @since 1.3.0
Expand All @@ -720,7 +729,7 @@ private function sanitizeJsVarName(string $name): string
* Converts basic Markdown syntax to HTML for better changelog display.
* Supports headers, bold text, italic text, inline code, lists, and links.
*
* @param string $markdown Markdown content to convert
* @param string $markdown Markdown content to convert.
* @return string HTML formatted content
*
* @since 1.0.1
Expand Down Expand Up @@ -778,10 +787,10 @@ private function parseMarkdownToHtml(string $markdown): string
* - string: Path to an already-downloaded file for WordPress to use
* - NEVER return true or any other type!
*
* @param boolean|WP_Error $result The result from previous filters
* @param string $package The package URL being downloaded
* @param object $upgrader The WP_Upgrader instance
* @param array $hook_extra Extra hook data
* @param boolean|WP_Error $result The result from previous filters.
* @param string $package The package URL being downloaded.
* @param object $upgrader The WP_Upgrader instance.
* @param array $hook_extra Extra hook data.
* @return string|WP_Error|false Path to downloaded file, WP_Error on failure, or false to continue
*
* @since 1.1.0
Expand Down Expand Up @@ -935,7 +944,7 @@ public function maybeFixDownload(
* Attempts different approaches to create a temporary file to avoid PCLZIP errors
* that can occur with restrictive /tmp directory permissions.
*
* @param string $package The package URL being downloaded
* @param string $package The package URL being downloaded.
* @return string|WP_Error Path to temporary file or WP_Error on failure
*
* @since 1.1.4
Expand Down
12 changes: 6 additions & 6 deletions src/UpdaterConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ class UpdaterConfig
* Initializes the updater configuration with plugin metadata and settings.
* Accepts text domain from the consuming plugin for proper i18n support.
*
* @param string $pluginFile Main plugin file path
* @param string $githubRepo GitHub repository (owner/repo)
* @param array $options Additional configuration options including text_domain
* @param string $pluginFile Main plugin file path.
* @param string $githubRepo GitHub repository (owner/repo).
* @param array $options Additional configuration options including text_domain.
*
* @since 1.0.0
*/
Expand Down Expand Up @@ -179,7 +179,7 @@ public function __construct(string $pluginFile, string $githubRepo, array $optio
* Retrieves plugin metadata from the plugin file header.
* Falls back to empty array when WordPress functions aren't available.
*
* @param string $pluginFile Path to the plugin file
* @param string $pluginFile Path to the plugin file.
* @return array Plugin data array
*
* @since 1.0.0
Expand All @@ -197,7 +197,7 @@ private function getPluginData(string $pluginFile): array
/**
* Translation wrapper for the package
*
* @param string $text Text to translate
* @param string $text Text to translate.
* @return string Translated text
*
* @since 1.1.0
Expand All @@ -210,7 +210,7 @@ public function __(string $text): string
/**
* Escaped translation wrapper for the package
*
* @param string $text Text to translate and escape
* @param string $text Text to translate and escape.
* @return string Translated and escaped text
*
* @since 1.1.0
Expand Down
8 changes: 8 additions & 0 deletions tests/Integration/DownloadFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class DownloadFilterTest extends TestCase

/**
* Set up test environment before each test
* @return void
*/
protected function setUp(): void
{
Expand All @@ -42,6 +43,7 @@ protected function setUp(): void

/**
* Clean up after each test
* @return void
*/
protected function tearDown(): void
{
Expand All @@ -54,6 +56,7 @@ protected function tearDown(): void

/**
* Test that temporary directory configuration is respected
* @return void
*/
public function testCustomTempDirectoryIsRespected(): void
{
Expand All @@ -68,6 +71,7 @@ public function testCustomTempDirectoryIsRespected(): void

/**
* Test that package URL validation works correctly
* @return void
*/
public function testPackageUrlValidation(): void
{
Expand All @@ -83,6 +87,7 @@ public function testPackageUrlValidation(): void

/**
* Test file size validation logic
* @return void
*/
public function testFileSizeValidation(): void
{
Expand All @@ -97,6 +102,7 @@ public function testFileSizeValidation(): void

/**
* Test that hook_extra validation logic works
* @return void
*/
public function testHookExtraValidation(): void
{
Expand All @@ -119,6 +125,7 @@ public function testHookExtraValidation(): void

/**
* Test version comparison logic
* @return void
*/
public function testVersionComparison(): void
{
Expand All @@ -133,6 +140,7 @@ public function testVersionComparison(): void

/**
* Test GitHub repository format validation
* @return void
*/
public function testGitHubRepoFormat(): void
{
Expand Down
Loading