承接 micaherne/phpstan-moodle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

micaherne/phpstan-moodle

Composer 安装命令:

composer require micaherne/phpstan-moodle

包简介

Rules and utilities for using PHPStan on Moodle code.

README 文档

README

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

Require the plugin in Composer:

composer require --dev micaherne/phpstan-moodle

If you also have 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

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

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

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, 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

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

micaherne/phpstan-moodle 适用场景与选型建议

micaherne/phpstan-moodle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.71k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2024 年 03 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 micaherne/phpstan-moodle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 micaherne/phpstan-moodle 我们能提供哪些服务?
定制开发 / 二次开发

基于 micaherne/phpstan-moodle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.71k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 4
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2024-03-24