raul338/cakephp-phpstan-extensions 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

raul338/cakephp-phpstan-extensions

最新稳定版本:5.0.0

Composer 安装命令:

composer require --dev raul338/cakephp-phpstan-extensions

包简介

Services to aid phpstan analysis on CakePHP projects

README 文档

README

CI

Services to aid phpstan analysis on CakePHP projects

Version CakePHP Version phpstan version
5.x 5.x 2.0+
4.x 4.x 2.0+
3.x 4.x 1.10+
2.x 3.x 0.12
1.x 3.x 0.11

Install

composer require --dev raul338/cakephp-phpstan-extensions

This extensions load automatically if you install phpstan/extension-installer

composer require --dev phpstan/extension-installer

or if you don't use phpstan/extension-installer, include in your phpstan.neon

includes:
	- vendor/raul338/cakephp-phpstan-extensions/src/cakephp-extensions.neon

How does this help me

This extension includes rules to analyze the following snippets wihout using var annotations

Dynamic Finders

Link to the Book

$query = $this->Users->findAllByUsername('joebob');

Detect methods from behaviors

Link to the Book

This only works if the method name is not modified in implementedMethods. Otherwise the analysis may be wrong, or you'll have to decorate your code with dockblocks

/**
 * @mixin \Cake\ORM\Behavior\TimestampBehavior
 */
public class UsersTable extends Table
{
    public function initialize(array $config)
    {
        parent::initialize($config);
        $this->addBehavior('Timestamp');
    }
}
// somewhere else - phpstan will know its the Timestamp touch method
$this->Users->touch($user);

FriendsOfCake/crud Actions & Listeners

This is for use with FriendsOfCake/crud

public function add()
{
    // phpstan will know action() is a AddAction instead of BaseAction
    $this->Crud->action()->saveOptions([]);

    // phpstan will know it is a \Crud\Listener\RelatedModelsListener
    $this->Crud->listener('relatedModels')->relatedModels(true);
}

It will only work if you use one of the default action

  • add
  • delete
  • edit
  • index
  • view

And in spanish names:

  • agregar
  • editar
  • borrar
  • ver

If you use an action with crud you'll have to do something like this:

public function custom()
{
    $this->Crud->mapAction('custom', 'Crud.Index');
    /** @var \Crud\Action\IndexAction */
    $action = $this->Crud->action();
}

FriendsOfCake/crud Event Subject

Tell phpstan that if is an event inside a Controller, the subject will probably be a CrudSubject

Example:

$this->Crud->on('beforePaginate', function (Event $event) {
    $query = $event->getSubject()->query;
    $query->where([ /** ... */]);
});

License

MIT

统计信息

  • 总下载量: 59.91k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-23