michaelmeneses/moodle-stubs

PHP stubs for Moodle LMS — classes, functions, constants, and global variables for IDE and static analysis support

Maintainers

Package info

github.com/michaelmeneses/moodle-stubs

pkg:composer/michaelmeneses/moodle-stubs

Statistics

Installs: 239

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v5.2.0 2026-04-20 15:43 UTC

This package is auto-updated.

Last update: 2026-05-03 02:33:07 UTC


README

PHP stub files for the Moodle LMS codebase. Provides IDE autocompletion and static analysis support for Moodle's classes, functions, constants, and global variables — without requiring a full Moodle installation.

Ideal for Moodle plugin developers, theme developers, and anyone working with Moodle's PHP API outside of a full Moodle environment.

Installation

composer require --dev michaelmeneses/moodle-stubs

To pin to a specific Moodle version:

# Latest patch for Moodle 4.3.x
composer require --dev michaelmeneses/moodle-stubs:^4.3

# Latest patch for Moodle 5.0.x
composer require --dev michaelmeneses/moodle-stubs:^5.0

# Exact version
composer require --dev michaelmeneses/moodle-stubs:4.3.2

Usage

PHPStan

Add to your phpstan.neon:

parameters:
    scanDirectories:
        - vendor/michaelmeneses/moodle-stubs/stubs

Now PHPStan recognizes all Moodle classes, functions, and globals:

// PHPStan knows $DB is moodle_database, $CFG is stdClass, etc.
global $DB, $CFG;

$record = $DB->get_record('user', ['id' => 1]); // Fully typed
$wwwroot = $CFG->wwwroot; // No "undefined property" errors

Psalm

Add to your psalm.xml:

<psalm>
    <stubs>
        <dir name="vendor/michaelmeneses/moodle-stubs/stubs"/>
    </stubs>
</psalm>

Rector

Rector uses PHPStan internally. Add the PHPStan configuration above and Rector will pick it up automatically.

PhpStorm

Stubs are detected automatically via Composer. If autocompletion is not working, mark the vendor/michaelmeneses/moodle-stubs/stubs directory as a Sources Root (right-click > Mark Directory as > Sources Root).

VS Code (Intelephense)

Intelephense picks up stubs from Composer dependencies automatically. No extra configuration needed.

What's Included

  • Classes, interfaces, traits, and enums — full declarations with method signatures, type hints, and PHPDoc
  • Functions — all procedural functions from Moodle core libraries (lib/moodlelib.php, lib/weblib.php, lib/accesslib.php, etc.)
  • Constants — both define() and const declarations (MOODLE_INTERNAL, PARAM_INT, CONTEXT_*, etc.)
  • Global variables$DB, $CFG, $USER, $PAGE, $OUTPUT, $SESSION, $COURSE, $SITE with correct type annotations
  • Full coverage — all PHP files in the Moodle codebase, not just core libraries

All implementation bodies are stripped — only declarations and signatures are preserved.

Versions

Each Moodle release branch and version tag has a corresponding branch/tag in this repository:

This repository Moodle source Use case
Tag v4.3.2 Moodle release v4.3.2 Pin to a specific release (recommended for production)
Tag v5.0.0 Moodle release v5.0.0 Pin to a specific release
Branch MOODLE_403_STABLE Latest MOODLE_403_STABLE Track latest patches for 4.3.x
Branch MOODLE_500_STABLE Latest MOODLE_500_STABLE Track latest patches for 5.0.x
Branch master Latest Moodle master Bleeding edge development

Branches are updated weekly. Tags are immutable — once created, they never change.

How It Works

Stubs are auto-generated by bimoo, an AST-based stub generator built with nikic/php-parser. A GitHub Actions workflow runs weekly to:

  1. Detect new commits in Moodle's official repository
  2. Regenerate stubs only for branches that changed (SHA-based tracking)
  3. Create tags for new Moodle releases automatically

Sponsors

MIDDAG

Maintained by Michael Meneses and supported by MIDDAG — Moodle development and technical services.

Building Moodle plugins? Check out MIDDAG for Moodle — a plugin suite and development framework that brings modern developer experience to Moodle, inspired by tools like Symfony and Laravel.

Credits

Based on the original machitgarha/bimoo project by Mohammad Amin Chitgarha.

License

Licensed under GPL 3.0.