PSR-12 coding standards compliance

Add phpcs/phpcbf tooling (composer require-dev, scripts, .phpcs.xml).
Auto-fix tabs to spaces across all PHP files (phpcbf).
Add missing doc comments for classes and constructors.
Add missing @param tags on public/private methods.
This commit is contained in:
Laurent Dinclaux
2026-02-10 22:52:30 +11:00
parent 05a7a2967f
commit b9e16f186d
8 changed files with 2679 additions and 2433 deletions

47
.phpcs.xml Normal file
View File

@@ -0,0 +1,47 @@
<?xml version="1.0"?>
<ruleset name="NextBridge">
<description>PSR-12 coding standard for NextBridge RoundCube plugin</description>
<!-- Use PSR-12 as base with RoundCube-specific exclusions -->
<rule ref="PSR12">
<!-- Allow longer lines for readability -->
<exclude name="Generic.Files.LineLength"/>
<!-- RoundCube plugins don't use namespaces -->
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
<!-- RoundCube plugins use lowercase class names by convention -->
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps"/>
<!-- RoundCube plugins can have side effects (require_once) -->
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/>
<!-- RoundCube hooks use snake_case method names by convention -->
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>
</rule>
<!-- Allow @url/@link in class doc comments -->
<rule ref="Squiz.Commenting.ClassComment">
<exclude name="Squiz.Commenting.ClassComment.TagNotAllowed"/>
</rule>
<rule ref="Squiz.Commenting.FunctionComment">
<exclude name="Squiz.Commenting.FunctionComment.MissingReturn"/>
</rule>
<!-- Line length: warn at 120, no hard limit -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
<!-- Require class documentation -->
<rule ref="Squiz.Commenting.ClassComment"/>
<!-- Require function documentation with @param and @return -->
<rule ref="Squiz.Commenting.FunctionComment"/>
<!-- Files to check -->
<file>ident_switch.php</file>
<file>lib/</file>
<!-- Exclude vendor directories -->
<exclude-pattern>*/vendor/*</exclude-pattern>
</ruleset>

View File

@@ -38,6 +38,9 @@
"roundcube/plugin-installer": ">=0.3.0",
"ext-ctype": "*"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.0"
},
"conflict": {
"boressoft/ident_switch": "*",
"elm/identity_smtp": "*",
@@ -51,5 +54,14 @@
"min-version": "1.6",
"sql-dir": "SQL"
}
},
"scripts": {
"phpcs": "phpcs",
"phpcbf": "phpcbf"
},
"config": {
"allow-plugins": {
"roundcube/plugin-installer": true
}
}
}

158
composer.lock generated Normal file
View File

@@ -0,0 +1,158 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "46b2d3558cb304fde0539d1b85971382",
"packages": [
{
"name": "roundcube/plugin-installer",
"version": "0.3.2",
"source": {
"type": "git",
"url": "https://github.com/roundcube/plugin-installer.git",
"reference": "c4335e20b86cfe3a184ccf24d675c6a0338a372a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/roundcube/plugin-installer/zipball/c4335e20b86cfe3a184ccf24d675c6a0338a372a",
"reference": "c4335e20b86cfe3a184ccf24d675c6a0338a372a",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.0 || ^2.0"
},
"require-dev": {
"composer/composer": "*"
},
"type": "composer-plugin",
"extra": {
"class": [
"Roundcube\\Composer\\RoundcubeInstaller"
]
},
"autoload": {
"psr-0": {
"Roundcube\\Composer": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-3.0+"
],
"authors": [
{
"name": "Thomas Bruederli",
"email": "thomas@roundcube.net"
},
{
"name": "Till Klampaeckel",
"email": "till@php.net"
},
{
"name": "Philip Weir",
"email": "roundcube@tehinterweb.co.uk"
}
],
"description": "A composer-installer for Roundcube plugins and skins.",
"support": {
"issues": "https://github.com/roundcube/plugin-installer/issues",
"source": "https://github.com/roundcube/plugin-installer/tree/0.3.2"
},
"time": "2022-06-24T09:08:18+00:00"
}
],
"packages-dev": [
{
"name": "squizlabs/php_codesniffer",
"version": "3.13.5",
"source": {
"type": "git",
"url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git",
"reference": "0ca86845ce43291e8f5692c7356fccf3bcf02bf4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/0ca86845ce43291e8f5692c7356fccf3bcf02bf4",
"reference": "0ca86845ce43291e8f5692c7356fccf3bcf02bf4",
"shasum": ""
},
"require": {
"ext-simplexml": "*",
"ext-tokenizer": "*",
"ext-xmlwriter": "*",
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4"
},
"bin": [
"bin/phpcbf",
"bin/phpcs"
],
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Greg Sherwood",
"role": "Former lead"
},
{
"name": "Juliette Reinders Folmer",
"role": "Current lead"
},
{
"name": "Contributors",
"homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors"
}
],
"description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
"homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer",
"keywords": [
"phpcs",
"standards",
"static analysis"
],
"support": {
"issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues",
"security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy",
"source": "https://github.com/PHPCSStandards/PHP_CodeSniffer",
"wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki"
},
"funding": [
{
"url": "https://github.com/PHPCSStandards",
"type": "github"
},
{
"url": "https://github.com/jrfnl",
"type": "github"
},
{
"url": "https://opencollective.com/php_codesniffer",
"type": "open_collective"
},
{
"url": "https://thanks.dev/u/gh/phpcsstandards",
"type": "thanks_dev"
}
],
"time": "2025-11-04T16:30:35+00:00"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=8.2",
"ext-ctype": "*"
},
"platform-dev": {},
"plugin-api-version": "2.6.0"
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* ident_switch - Roundcube plugin for fast switching between accounts.
*
@@ -19,6 +20,14 @@ require_once __DIR__ . '/lib/IdentSwitchForm.php';
require_once __DIR__ . '/lib/IdentSwitchSwitcher.php';
require_once __DIR__ . '/lib/IdentSwitchChecker.php';
/**
* Roundcube plugin for fast switching between multiple IMAP accounts.
*
* Allows users to configure and switch between multiple mail accounts
* (including remote) within a single Roundcube session, with alias support.
*
* @url https://github.com/Gecka-apps/ident_switch
*/
class ident_switch extends rcube_plugin
{
/** @var string Task regex: active on all tasks except login/logout. */
@@ -479,7 +488,7 @@ class ident_switch extends rcube_plugin
/**
* Resolve username for an identity: use stored username or fall back to email.
*
* @param int $iid Identity ID.
* @param integer $iid Identity ID.
* @param string|null $username Stored username (may be empty).
* @return string Resolved username.
*/

View File

@@ -1,4 +1,5 @@
<?php
/**
* ident_switch - Background mail checker.
*
@@ -104,8 +105,8 @@ class IdentSwitchChecker
*
* @param rcmail $rc Roundcube instance.
* @param array $identity Identity DB record.
* @param int $previousCount Previous unseen count (returned on error).
* @return int Unseen message count.
* @param integer $previousCount Previous unseen count (returned on error).
* @return integer Unseen message count.
*/
private function check_unseen(rcmail $rc, array $identity, int $previousCount): int
{
@@ -241,7 +242,7 @@ class IdentSwitchChecker
*
* @param rcmail $rc Roundcube instance.
* @param array $identity Identity record.
* @param int $count New unseen count.
* @param integer $count New unseen count.
*/
private function send_notification(rcmail $rc, array $identity, int $count): void
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* ident_switch - Identity form handling.
*
@@ -21,6 +22,11 @@ class IdentSwitchForm
private ident_switch $plugin;
/**
* Constructor.
*
* @param ident_switch $plugin Parent plugin instance.
*/
public function __construct(ident_switch $plugin)
{
$this->plugin = $plugin;
@@ -30,6 +36,8 @@ class IdentSwitchForm
* Build the common form fields for identity settings.
*
* @param array $record Identity record data used for placeholders.
* @param boolean $domainAllowed Whether the identity domain has a matching preconfig.
* @param string $warningHtml HTML warning message when domain is not allowed.
* @return array Form field definitions for mode select, label, and readonly.
*/
public function get_common_fields(array &$record, bool $domainAllowed = true, string $warningHtml = ''): array
@@ -74,7 +82,7 @@ class IdentSwitchForm
* Get all separate accounts available as alias targets.
*
* @param rcmail $rc Roundcube instance.
* @param int|null $excludeIid Identity ID to exclude (the identity being edited).
* @param integer|null $excludeIid Identity ID to exclude (the identity being edited).
* @return array List of account records with id, label, username, email.
*/
private function get_available_accounts(rcmail $rc, ?int $excludeIid): array
@@ -301,7 +309,7 @@ class IdentSwitchForm
* a matching preconfig entry are allowed.
*
* @param string $email Email address to check.
* @return bool True if allowed, false if blocked by preconfig_only.
* @return boolean True if allowed, false if blocked by preconfig_only.
*/
private function is_domain_allowed(string $email): bool
{
@@ -365,6 +373,8 @@ class IdentSwitchForm
/**
* Delegate to ident_switch::parse_host_scheme().
*
* @param string $host Hostname possibly prefixed with ssl:// or tls://.
*/
private static function parse_host_scheme(string $host): array
{
@@ -968,7 +978,7 @@ class IdentSwitchForm
* Otherwise return the raw password as-is.
*
* @param rcmail $rc Roundcube instance.
* @param int $iid Identity ID.
* @param integer $iid Identity ID.
* @param string|null $pass Raw password from POST.
* @return string Decrypted or raw password for testing.
*/
@@ -1146,8 +1156,8 @@ class IdentSwitchForm
*
* @param string $section Form section name (common, imap, smtp).
* @param string $field Field name within the section.
* @param bool $trim Whether to trim and nullify empty values.
* @param bool $html Whether to allow HTML in the value.
* @param boolean $trim Whether to trim and nullify empty values.
* @param boolean $html Whether to allow HTML in the value.
* @return string|null The field value, or null if empty and trimmed.
*/
public static function get_field_value(string $section, string $field, bool $trim = true, bool $html = false): ?string
@@ -1172,7 +1182,7 @@ class IdentSwitchForm
*
* @param rcmail $rc Roundcube instance for DB access and encryption.
* @param array $data Validated field data including 'id' (identity_id).
* @return bool True if a query was executed, false otherwise.
* @return boolean True if a query was executed, false otherwise.
*/
public function save(rcmail $rc, array $data): bool
{
@@ -1261,8 +1271,8 @@ class IdentSwitchForm
* Creates or updates an ident_switch record with parent_id set and
* all server fields cleared (alias uses parent's config).
*
* @param int $iid Identity ID of the alias.
* @param int $parentId ident_switch.id of the parent account.
* @param integer $iid Identity ID of the alias.
* @param integer $parentId Ident_switch.id of the parent account.
*/
private function save_alias(int $iid, int $parentId): void
{
@@ -1306,7 +1316,7 @@ class IdentSwitchForm
/**
* Disable the ident_switch flag for a given identity.
*
* @param int $iid Identity ID to disable.
* @param integer $iid Identity ID to disable.
*/
public function disable(int $iid): void
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* ident_switch - Preconfiguration handler.
*
@@ -17,6 +18,11 @@ class IdentSwitchPreconfig
{
private ident_switch $plugin;
/**
* Constructor.
*
* @param ident_switch $plugin Parent plugin instance.
*/
public function __construct(ident_switch $plugin)
{
$this->plugin = $plugin;
@@ -55,7 +61,7 @@ class IdentSwitchPreconfig
* and port, then sets the username and delimiter based on config values.
*
* @param array $record Identity record to modify (passed by reference).
* @return bool True if the preconfig is readonly, false otherwise.
* @return boolean True if the preconfig is readonly, false otherwise.
*/
public function apply(array &$record): bool
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* ident_switch - Account switching handler.
*
@@ -281,7 +282,8 @@ class IdentSwitchSwitcher
{
$rc = rcmail::get_instance();
if ($args['section'] === 'folders'
if (
$args['section'] === 'folders'
&& strcasecmp($rc->user->data['username'], $_SESSION['username']) !== 0
) {
$no_override = array_flip((array)$rc->config->get('dont_override'));
@@ -328,7 +330,8 @@ class IdentSwitchSwitcher
{
$rc = rcmail::get_instance();
if ($args['section'] === 'folders'
if (
$args['section'] === 'folders'
&& strcasecmp($rc->user->data['username'], $_SESSION['username']) !== 0
) {
$sql = 'SELECT id FROM ' . $rc->db->table_name(ident_switch::TABLE) . ' WHERE iid = ? AND user_id = ?';
@@ -382,7 +385,7 @@ class IdentSwitchSwitcher
* For primary account (identId=-1), iid is 0.
* For secondary accounts, look up iid from the ident_switch table.
*
* @param int|null $iid Known iid (0 for primary), or null to look up.
* @param integer|null $iid Known iid (0 for primary), or null to look up.
* @param rcmail $rc Roundcube instance.
* @param mixed $identId The ident_switch.id value for secondary accounts.
*/