Moko Consulting

Open-source software for Joomla, Gitea, and web platforms. Home of MokoSuite, MokoGitea, and MokoCLI.

Tennessee
standards/coding-php.-

PHP Coding Standards

All PHP code in MokoConsulting projects follows PSR-12 as the base standard, extended with Joomla 5 conventions and modern PHP 8.1+ features.

Strict Types

Every PHP file must declare strict types:

<?php

declare(strict_types=1);

Namespaces

Joomla extensions use the MokoConsulting vendor namespace:

MokoConsulting\Component\MokoSuiteBackup\Administrator\Controller\BackupController
MokoConsulting\Component\MokoSuiteBackup\Administrator\Model\BackupsModel
MokoConsulting\Component\MokoSuiteBackup\Administrator\View\Backups\HtmlView
MokoConsulting\Component\MokoSuiteBackup\Administrator\Table\BackupTable
MokoConsulting\Component\MokoSuiteBackup\Administrator\Extension\MokoSuiteBackupComponent
MokoConsulting\Component\MokoSuiteBackup\Site\Controller\DisplayController

Plugin namespaces follow:

MokoConsulting\Plugin\System\MokoSuiteBackup\Extension\MokoSuiteBackup
MokoConsulting\Plugin\WebServices\MokoSuiteBackup\Extension\MokoSuiteBackupWebServices
MokoConsulting\Module\MokoSuiteHero\Site\Dispatcher\Dispatcher

DI Provider Pattern

Every component must register via services/provider.php:

<?php

declare(strict_types=1);

use Joomla\CMS\Dispatcher\ComponentDispatcherFactoryInterface;
use Joomla\CMS\Extension\ComponentInterface;
use Joomla\CMS\Extension\Service\Provider\ComponentDispatcherFactory;
use Joomla\CMS\Extension\Service\Provider\MVCFactory;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use MokoConsulting\Component\MokoSuiteBackup\Administrator\Extension\MokoSuiteBackupComponent;

return new class () implements ServiceProviderInterface {
    public function register(Container $container): void
    {
        $container->registerServiceProvider(new MVCFactory('\\MokoConsulting\\Component\\MokoSuiteBackup'));
        $container->registerServiceProvider(new ComponentDispatcherFactory('\\MokoConsulting\\Component\\MokoSuiteBackup'));

        $container->set(
            ComponentInterface::class,
            function (Container $container) {
                $component = new MokoSuiteBackupComponent($container->get(ComponentDispatcherFactoryInterface::class));
                $component->setMVCFactory($container->get(MVCFactoryInterface::class));
                return $component;
            }
        );
    }
};

PHP 8.1+ Features

Required

  • Type declarations on all method parameters and return types
  • Named arguments where they improve readability
  • match expressions instead of complex switch blocks
  • Readonly properties for value objects and immutable state
  • Enums for fixed sets of values (status, type, etc.)
  • Fibers only where Joomla's task system requires them
  • Union types and intersection types where appropriate
  • null safe operator (?->) for optional chaining

Examples

enum BackupType: string
{
    case Full = 'full';
    case Database = 'database';
    case Files = 'files';
}

final readonly class BackupResult
{
    public function __construct(
        public int $id,
        public BackupType $type,
        public string $archivePath,
        public int $sizeBytes,
        public \DateTimeImmutable $completedAt,
    ) {}
}

Formatting Rules

  • Indentation: 4 spaces (no tabs)
  • Line length: 120 characters soft limit
  • Braces: Allman style for classes/methods, K&R for control structures (per Joomla standard)
  • Trailing commas: Required in multi-line arrays and parameter lists
  • Blank lines: One blank line between methods, two between class sections
  • Imports: Grouped by type (PHP, Joomla, third-party, project), alphabetized within groups

Prohibited Patterns

  • eval(), exec(), system(), passthru() — never in production code
  • extract() — unpredictable variable creation
  • global keyword — use dependency injection
  • @ error suppression — handle errors explicitly
  • die() / exit() — use exceptions and proper error handling
  • Raw $_GET, $_POST, $_REQUEST — use Joomla's Input class
  • Direct SQL string concatenation — use prepared statements

Code Analysis

All projects must pass:

  • php -l (syntax check)
  • phpcs --standard=Joomla (Joomla Coding Standards)
  • phpstan --level=6 minimum (static analysis)

Run locally: make lint && make phpcs && make phpstan