PHPackages                             micaherne/phpstan-moodle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. micaherne/phpstan-moodle

ActivePhpstan-extension[Utility &amp; Helpers](/categories/utility)

micaherne/phpstan-moodle
========================

Rules and utilities for using PHPStan on Moodle code.

v1.0.3(1mo ago)41.0k↓26.3%3[2 issues](https://github.com/micaherne/phpstan-moodle/issues)GPL-3.0-or-laterPHPPHP ^8.2

Since Apr 12Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/micaherne/phpstan-moodle)[ Packagist](https://packagist.org/packages/micaherne/phpstan-moodle)[ RSS](/packages/micaherne-phpstan-moodle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (18)Versions (9)Used By (0)

phpstan-moodle
==============

[](#phpstan-moodle)

This is a plugin for PHPStan that enables analysis of Moodle code.

It currently only supports bootstrapping the classloader - there are no rules as yet.

Note that this will execute code in your Moodle codebase.

Installation
------------

[](#installation)

To use this plugin, install it with phpstan extension-installer:

Otherwise, require it in [Composer](https://getcomposer.org/):

```
composer require --dev micaherne/phpstan-moodle
```

Then create a `phpstan.neon` file in the root of your project with the following contents:

```
includes:
    - vendor/micaherne/phpstan-moodle/extension.neon
```

Usage
-----

[](#usage)

Add the following to your `phpstan.neon` file:

```
parameters:
    moodle:
        rootDirectory: /path/to/moodle
```

The rootDirectory parameter *must* be an absolute path. Also, `composer install` must have been run in the Moodle root directory to create the vendor directory.

Technical details
-----------------

[](#technical-details)

### Why this plugin exists

[](#why-this-plugin-exists)

PHPStan has excellent functionality for scanning code for classes and other symbols but this is not sufficient for use with Moodle. This is due to [PHPStan's handling of class aliases](https://phpstan.org/user-guide/discovering-symbols#class-aliases), which are heavily used by Moodle. For PHPStan to be aware of class aliases these must actually exist at runtime, which means that the aliased class must also be loadable. This plugin bootstraps the Moodle classloader and sets up (most of) the aliases in the codebase so that PHPStan can understand them.

The other reason for the plugin is to enable refactoring using Rector, which delegates its symbol discovery to PHPStan. Rector assumes that all classes can be correctly discovered (and in some cases will refactor wrongly if it is unaware of a base class) so this is necessary.

### How it works

[](#how-it-works)

Setting the moodle.rootDirectory parameter in your PHPStan config sets up a directory scan of the whole Moodle codebase. It also calls a bootstrap script which loads the Moodle classloader and includes most of the files in the codebase that contain explicit class alias calls. Aliasing of renamed classes in db/renamedclasses.php files is handled by the classloader itself.

It also:

- sets moodle\_exception as unchecked
- adds some ignores for the standard globals possibly not being defined (as we know they are)
- loads some type specifying extensions for functions like enrol\_get\_plugin() and get\_auth\_plugin() where the return type is dynamic based on the parameters in the call

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance70

Regular maintenance activity

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~140 days

Total

4

Last Release

50d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/11fff6d64aebe889955d1c8eb93fddff3cef0c02e3086a20678bfa94e8f76aef?d=identicon)[micaherne](/maintainers/micaherne)

---

Top Contributors

[![micaherne](https://avatars.githubusercontent.com/u/516366?v=4)](https://github.com/micaherne "micaherne (41 commits)")[![sharpchi](https://avatars.githubusercontent.com/u/3774280?v=4)](https://github.com/sharpchi "sharpchi (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisRector

### Embed Badge

![Health badge](/badges/micaherne-phpstan-moodle/health.svg)

```
[![Health](https://phpackages.com/badges/micaherne-phpstan-moodle/health.svg)](https://phpackages.com/packages/micaherne-phpstan-moodle)
```

###  Alternatives

[ticketswap/phpstan-error-formatter

A minimalistic error formatter for PHPStan

87578.8k35](/packages/ticketswap-phpstan-error-formatter)[slam/phpstan-extensions

Slam extension of phpstan

702.5M74](/packages/slam-phpstan-extensions)[ramsey/devtools

A Composer plugin to aid PHP library and application development.

7134.7k26](/packages/ramsey-devtools)[johnbillion/wp-compat

PHPStan extension to help verify that your PHP code is compatible with a given version of WordPress

24115.0k10](/packages/johnbillion-wp-compat)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
