simensen/rector 问题修复 & 功能扩展

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

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

simensen/rector

最新稳定版本:v0.0.1

Composer 安装命令:

composer require simensen/rector

包简介

Simensen's Rules and Tools for Rector

README 文档

README

MIT License

Simensen's custom rules and tools for Rector - a PHP automated refactoring tool.

Installation

Install via Composer:

composer require simensen/rector

Rules

RemoveDefaultFromImplicitlyRequiredParamRector

This rector removes default values from function/method parameters when they are followed by required parameters, making the code more explicit and preventing potential runtime errors.

What it does:

  • Removes default values from parameters that are implicitly required (have required parameters after them)
  • Adds nullable types (?type or |null) to parameters that had null as their default value
  • Preserves default values only for trailing optional parameters

Example transformation:

// Before
class Example
{
    public function __construct(string $a = null, string $b)
    {
    }
}

// After  
class Example
{
    public function __construct(?string $a, string $b)
    {
    }
}

More complex example:

// Before
public function method(
    string $a = 'default',
    string $b,
    string $c = null,
    string $d,
    string $e = 'end'
)

// After
public function method(
    string $a,
    string $b, 
    ?string $c,
    string $d,
    string $e = 'end'
)

Usage

Add the rector to your rector.php configuration:

<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Simensen\Rector\Rules\Params\Rector\RemoveDefaultFromImplicitlyRequiredParamRector;

return RectorConfig::configure()
    ->withRules([
        RemoveDefaultFromImplicitlyRequiredParamRector::class,
    ]);

Then run Rector:

vendor/bin/rector process src/

Development

Requirements

  • PHP 8.1+
  • Composer

Setup

# Install dependencies
make vendor

# Install development tools
make tools

Testing

# Run tests
make test

# Run code style checks and fixes
make cs

Available Make Targets

  • make it - Default target, installs tools and dependencies
  • make vendor - Install Composer dependencies
  • make tools - Install development tools via PHIVE
  • make test - Run PHPUnit tests
  • make cs - Run code style checks and fixes
  • make clean - Remove vendor and tools directories
  • make realclean - Clean and also remove composer.lock
  • make help - Display available targets

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for any new functionality
  5. Ensure all tests pass: make test
  6. Ensure code style is correct: make cs
  7. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Beau Simensen - GitHub

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-28