PHPackages                             micaherne/rector-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/rector-moodle

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

micaherne/rector-moodle
=======================

Rector config for upgrading Moodle plugins

1242[2 issues](https://github.com/micaherne/rector-moodle/issues)[1 PRs](https://github.com/micaherne/rector-moodle/pulls)PHPCI passing

Since Oct 7Pushed 2mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

Rector rules for Moodle
=======================

[](#rector-rules-for-moodle)

This package provides basic rule sets for upgrading Moodle plugins for compatibility with new versions, using [Rector](https://getrector.com/).

Note that this is a work in progress and does not provide a comprehensive migration. Manual checking is still necessary.

Install
-------

[](#install)

Rector is installed using Composer, and this package should be installed similarly. Add a development dependency:

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

```

Configuration
-------------

[](#configuration)

This library provides a configuration helper class that must be used to configure Rector correctly to understand Moodle classes. This is *essential* for many Rector rules as they can break your code if they are not aware of the Moodle class hierarchy.

Rule sets can be added to your rector.php config file. For example:

```
use RectorMoodle\Config\MoodleRectorConfig;
use RectorMoodle\Set\MoodleLevelSetList;

return MoodleRectorConfig::configure('/path/to/your/moodle/root')
    ->withSets([
        MoodleLevelSetList::UP_TO_MOODLE_45
    ])
    ->withImportNames();

```

The following rule sets are available:

- **MoodleSetList::MOODLE\_42** - Update features introduced in Moodle 4.2
- **MoodleSetList::MOODLE\_43** - Update features introduced in Moodle 4.3
- **MoodleSetList::MOODLE\_44** - Update features introduced in Moodle 4.4
- **MoodleSetList::MOODLE\_45** - Update features introduced in Moodle 4.5
- **MoodleSetList::RENAME\_CONTEXT\_CLASSES** - Rename context classes to the new namespaced names introduced in Moodle 4.2, and convert level constants like CONTEXT\_COURSE to the corresponding new LEVEL class constant. This is separate from the Moodle 4.2 set as the documentation strongly implies that there is no requirement to update from the old \\context\_\* class names, and that the class aliases for backward compatibility will be retained indefinitely.
- **MoodleLevelSetList::UP\_TO\_MOODLE\_43** - Apply both the Moodle 4.2 and 4.3 updates.
- **MoodleLevelSetList::UP\_TO\_MOODLE\_44** - Apply Moodle 4.2, 4.3 and 4.4 updates.
- **MoodleLevelSetList::UP\_TO\_MOODLE\_45** - Apply Moodle 4.2, 4.3, 4.4 and 4.5 updates.

A note on symbol discovery
--------------------------

[](#a-note-on-symbol-discovery)

Some rules in Rector require knowledge of the class hierarchy or other symbols (e.g. [CompleteDynamicPropertiesRector](https://github.com/rectorphp/rector/blob/main/rules/CodeQuality/Rector/Class_/CompleteDynamicPropertiesRector.php)).

For these rules to work correctly, the whole Moodle codebase must be scanned. This appears as if it should be possible by using the `autoloadPaths()` method on the RectorConfig object, but this does not seem to work as expected.

In addition to this, Rector must be aware of class aliases and the classes they point to. There is no way to do this in PHPStan (which Rector uses for symbol discovery) through configuration, so the aliased classes must be loaded and the aliases created. This means that the `MoodleRectorConfig` class *actually runs some of your Moodle code*, so please ensure that you are running this in a safe environment.

### Class aliases

[](#class-aliases)

Note that the above method of symbol discovery only deals with class aliases in the core Moodle codebase, and if you have any in your own codebase, you will need to ensure that they are available to Rector.

Coverage
--------

[](#coverage)

The rule sets mainly concentrate on updating class names where these are moved (e.g. as defined in the renamedclasses.php files), or where functions are moved to static methods on classes but retain the same signature.

There are various other changes between Moodle versions but some of these are not possible to implement an automated refactoring for, so this is not a replacement for following the guidance in the Moodle upgrade.txt files.

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### 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 (53 commits)")

### Embed Badge

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

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

PHPackages © 2026

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