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.1.0(3w ago)52.3k↓48.1%3[4 issues](https://github.com/micaherne/phpstan-moodle/issues)GPL-3.0-or-laterPHPPHP ^7.4|^8.0CI passing

Since Apr 12Pushed 3w 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 yesterday

READMEChangelog (5)Dependencies (22)Versions (11)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)

Require the plugin in [Composer](https://getcomposer.org/):

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

If you also have [phpstan/extension-installer](https://github.com/phpstan/extension-installer) installed, the extension will be registered with PHPStan automatically and no further configuration is needed:

```
composer require --dev phpstan/extension-installer
```

Otherwise, include the extension manually in the `phpstan.neon` file in the root of your project:

```
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 may be an absolute path, or a path relative to the config file it is written in (in the same way as PHPStan's own path parameters such as `paths` and `scanDirectories`). Also, `composer install` must have been run in the Moodle root directory to create the vendor directory.

### Common includes

[](#common-includes)

There is another parameter available - addCommonIncludes. This defaults to true and controls whether the plugin will add common includes, such as libraries like grade/lib.php and other non-autoloaded classes. These are not required for the coverage of the autoloadable classes and aliases that are this plugin's main focus, but they help to avoid missing classes that are often implicitly included when Moodle runs. If you would like not to load these, set addCommonIncludes to false:

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

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

46

—

FairBetter than 92% of packages

Maintenance79

Regular maintenance activity

Popularity29

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.5% 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 ~123 days

Total

5

Last Release

24d ago

PHP version history (2 changes)v1.0.0PHP ^8.2

v1.1.0PHP ^7.4|^8.0

### 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 (65 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

[deptrac/deptrac

Deptrac is a static code analysis tool that helps to enforce rules for dependencies between software layers.

3.0k8.8M118](/packages/deptrac-deptrac)[phpstan/phpstan-symfony

Symfony Framework extensions and rules for PHPStan

79475.7M2.2k](/packages/phpstan-phpstan-symfony)[ticketswap/phpstan-error-formatter

A minimalistic error formatter for PHPStan

87718.9k56](/packages/ticketswap-phpstan-error-formatter)[ec-europa/toolkit

Toolkit packaged for Drupal projects based on Robo.

40252.8k34](/packages/ec-europa-toolkit)[ergebnis/rector-rules

Provides rules for rector/rector.

10245.6k51](/packages/ergebnis-rector-rules)[shopsys/coding-standards

Coding standards definition compatible with PSR-2

20280.7k20](/packages/shopsys-coding-standards)

PHPackages © 2026

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