Skip to content

Commit

Permalink
Add rector [batch] (#122)
Browse files Browse the repository at this point in the history
* Add rector files yiisoft/yii-dev-tool#232

* Add rector/rector dependecy

* [rector] Apply fixes

* Apply fixes from StyleCI

* Use predefined rector action

* fix

* changelog

* fix config

* version

* fix

* 8.0

* Fix BC CI

Co-authored-by: rector-bot <rector@yiiframework.com>
Co-authored-by: StyleCI Bot <bot@styleci.io>
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
  • Loading branch information
4 people committed Jan 18, 2023
1 parent d24fc59 commit 8d7e227
Show file tree
Hide file tree
Showing 23 changed files with 119 additions and 133 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/bc.yml
Expand Up @@ -3,13 +3,12 @@ on:
- push

name: backwards compatibility

jobs:
roave_bc_check:
name: Roave BC Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: fetch tags
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Roave BC Check
uses: docker://nyholm/roave-bc-check-ga
uses: yiisoft/actions/.github/workflows/bc.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.0']
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['7.4', '8.0', '8.1']
['8.0', '8.1', '8.2']
21 changes: 21 additions & 0 deletions .github/workflows/rector.yml
@@ -0,0 +1,21 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: rector

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.0']
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Expand Up @@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['7.4', '8.0', '8.1']
['8.0', '8.1', '8.2']
9 changes: 5 additions & 4 deletions CHANGELOG.md
@@ -1,16 +1,17 @@
# Yii Config Change Log

## 1.1.2 under development
## 1.2.0 under development

- Enh #119: Improve performance of collecting data for `ReverseMerge` and `RecursiveMerge` (samdark)
- Enh #119: Improve performance of collecting data for `ReverseMerge` and `RecursiveMerge` (@samdark)
- Enh #122: Raise minimal PHP version to 8.0 (@vjik, @xepozz)

## 1.1.1 January 05, 2022

- Enh #110: Improve the error message by displaying a name of the group where the error occurred when merging (devanych)
- Enh #110: Improve the error message by displaying a name of the group where the error occurred when merging (@devanych)

## 1.1.0 December 31, 2021

- New #108: Add `Yiisoft\Config\ConfigInterface` to allow custom implementations of a config loader (devanych)
- New #108: Add `Yiisoft\Config\ConfigInterface` to allow custom implementations of a config loader (@devanych)

## 1.0.0 December 17, 2021

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -22,7 +22,7 @@ a plugin system. The package becomes a plugin holding both the code and its conf

## Requirements

- PHP 7.4 or higher.
- PHP 8.0 or higher.
- Composer 2.0 or higher.

## Installation
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Expand Up @@ -28,18 +28,19 @@
}
],
"require": {
"php": "^7.4|^8.0",
"php": "^8.0",
"composer-plugin-api": "^2.0",
"yiisoft/strings": "^2.0",
"yiisoft/var-dumper": "^1.1"
},
"require-dev": {
"ext-json": "*",
"composer/composer": "^2.0",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.15.7",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18",
"ext-json": "*"
"vimeo/psalm": "^4.18"
},
"config": {
"sort-packages": true,
Expand Down
29 changes: 29 additions & 0 deletions rector.php
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php70\Rector\FuncCall\NonVariableToVariableOnFunctionCallRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
]);

$rectorConfig->skip([
RemoveExtraParametersRector::class,
NonVariableToVariableOnFunctionCallRector::class,
]);
};
14 changes: 5 additions & 9 deletions src/Composer/PackageFile.php
Expand Up @@ -9,15 +9,11 @@
*/
final class PackageFile
{
private string $filename;
private string $relativePath;
private string $absolutePath;

public function __construct(string $filename, string $relativePath, string $absolutePath)
{
$this->filename = $filename;
$this->relativePath = $relativePath;
$this->absolutePath = $absolutePath;
public function __construct(
private string $filename,
private string $relativePath,
private string $absolutePath,
) {
}

public function filename(): string
Expand Down
8 changes: 3 additions & 5 deletions src/Composer/PackagesListBuilder.php
Expand Up @@ -15,11 +15,9 @@
*/
final class PackagesListBuilder
{
private Composer $composer;

public function __construct(Composer $composer)
{
$this->composer = $composer;
public function __construct(
private Composer $composer,
) {
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Config.php
Expand Up @@ -21,7 +21,6 @@ final class Config implements ConfigInterface
{
private Merger $merger;
private FilesExtractor $filesExtractor;
private string $paramsGroup;
private bool $isBuildingParams = false;

/**
Expand All @@ -41,10 +40,9 @@ public function __construct(
ConfigPaths $paths,
string $environment = null,
array $modifiers = [],
string $paramsGroup = 'params'
private string $paramsGroup = 'params'
) {
$environment = empty($environment) ? Options::DEFAULT_ENVIRONMENT : $environment;
$this->paramsGroup = $paramsGroup;

/** @psalm-suppress UnresolvableInclude, MixedArgument */
$mergePlan = new MergePlan(require $paths->absolute(Options::MERGE_PLAN_FILENAME));
Expand Down Expand Up @@ -196,8 +194,6 @@ private function buildFile(string $filePath): array
}

/**
* @param string $message
*
* @throws ErrorException
*/
private function throwException(string $message): void
Expand Down
13 changes: 6 additions & 7 deletions src/ConfigPaths.php
Expand Up @@ -5,7 +5,6 @@
namespace Yiisoft\Config;

use function strlen;
use function strpos;
use function substr;
use function trim;

Expand All @@ -14,7 +13,6 @@
*/
final class ConfigPaths
{
private string $rootPath;
private string $configPath;
private string $vendorPath;

Expand All @@ -23,10 +21,11 @@ final class ConfigPaths
* @param string|null $configDirectory The relative path to the configuration storage location.
* @param string|null $vendorDirectory The relative path to the vendor directory.
*/
public function __construct(string $rootPath, string $configDirectory = null, string $vendorDirectory = null)
{
$this->rootPath = $rootPath;

public function __construct(
private string $rootPath,
string $configDirectory = null,
string $vendorDirectory = null,
) {
$configDirectory = trim($configDirectory ?? Options::DEFAULT_CONFIG_DIRECTORY, '/');
$this->configPath = $rootPath . ($configDirectory === '' ? '' : "/$configDirectory");

Expand Down Expand Up @@ -64,7 +63,7 @@ public function absolute(string $file, string $package = Options::ROOT_PACKAGE_N
*/
public function relative(string $file): string
{
return strpos($file, "$this->rootPath/") === 0
return str_starts_with($file, "$this->rootPath/")
? substr($file, strlen("$this->rootPath/"))
: $file;
}
Expand Down
20 changes: 7 additions & 13 deletions src/Context.php
Expand Up @@ -14,19 +14,13 @@ final class Context
public const APPLICATION = 3;
public const ENVIRONMENT = 4;

private string $group;
private string $package;
private int $layer;
private string $file;
private bool $isVariable;

public function __construct(string $group, string $package, int $layer, string $file, bool $isVariable)
{
$this->group = $group;
$this->package = $package;
$this->layer = $layer;
$this->file = $file;
$this->isVariable = $isVariable;
public function __construct(
private string $group,
private string $package,
private int $layer,
private string $file,
private bool $isVariable,
) {
}

public function group(): string
Expand Down
7 changes: 2 additions & 5 deletions src/DataModifiers.php
Expand Up @@ -33,12 +33,12 @@ final class DataModifiers
/**
* @psalm-var array<string, true>
*/
private array $removeFromVendorGroupsIndex;
private array $removeFromVendorGroupsIndex = [];

/**
* @psalm-var array<string, array<string, mixed>>
*/
private array $removeFromVendorKeysIndex;
private array $removeFromVendorKeysIndex = [];

/**
* @param object[] $modifiers Modifiers that affect merge process.
Expand All @@ -48,9 +48,6 @@ public function __construct(array $modifiers = [])
$reverseMergeGroups = [];
$recursiveMergeGroups = [];

$this->removeFromVendorGroupsIndex = [];
$this->removeFromVendorKeysIndex = [];

foreach ($modifiers as $modifier) {
if ($modifier instanceof ReverseMerge) {
array_unshift($reverseMergeGroups, $modifier->getGroups());
Expand Down
19 changes: 4 additions & 15 deletions src/FilesExtractor.php
Expand Up @@ -17,21 +17,12 @@
*/
final class FilesExtractor
{
private ConfigPaths $paths;
private MergePlan $mergePlan;
private DataModifiers $dataModifiers;
private string $environment;

public function __construct(
ConfigPaths $paths,
MergePlan $mergePlan,
DataModifiers $dataModifiers,
string $environment
private ConfigPaths $paths,
private MergePlan $mergePlan,
private DataModifiers $dataModifiers,
private string $environment,
) {
$this->paths = $paths;
$this->mergePlan = $mergePlan;
$this->dataModifiers = $dataModifiers;
$this->environment = $environment;
}

/**
Expand Down Expand Up @@ -171,8 +162,6 @@ private function prepareEnvironment(string $group): string
}

/**
* @param string $message
*
* @throws ErrorException
*/
private function throwException(string $message): void
Expand Down
11 changes: 3 additions & 8 deletions src/MergePlan.php
Expand Up @@ -9,17 +9,12 @@
*/
final class MergePlan
{
/**
* @psalm-var array<string, array<string, array<string, string[]>>>
*/
private array $mergePlan;

/**
* @psalm-param array<string, array<string, array<string, string[]>>> $mergePlan
*/
public function __construct(array $mergePlan = [])
{
$this->mergePlan = $mergePlan;
public function __construct(
private array $mergePlan = [],
) {
}

/**
Expand Down

0 comments on commit 8d7e227

Please sign in to comment.