Skip to content

Commit 7d0cde6

Browse files
ArshidArshid
authored andcommitted
MbStrContainsRector
1 parent ecb4204 commit 7d0cde6

File tree

7,727 files changed

+292008
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

7,727 files changed

+292008
-0
lines changed

CODE_OF_CONDUCT.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at tomas.vot@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [https://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: https://contributor-covenant.org
46+
[version]: https://contributor-covenant.org/version/1/4/

CONTRIBUTING.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# How to Contribute
2+
3+
Contributions here are more than welcomed! You can contribute to [rector-src](https://github.com/rectorphp/rector-src) repository or one of [extension packages](https://github.com/rectorphp/).
4+
5+
## Preparing Local Environment
6+
7+
1. Fork the [rector/rector-src](https://github.com/rectorphp/rector-src) repository and clone it
8+
9+
```bash
10+
git clone git@github.com:<your-name>/rector-src.git
11+
cd rector-src
12+
```
13+
14+
2. We use PHP 8.2 and composer
15+
16+
Install dependencies and verify your local environment:
17+
18+
```bash
19+
composer update
20+
composer check-platform-reqs
21+
```
22+
23+
*Note: using Docker for contributing is strongly discouraged, as it requires [extra knowledge of composer internals](https://github.com/composer/composer/issues/9368#issuecomment-718112361).*
24+
25+
Then you can start working with the code :+1:
26+
27+
<br>
28+
29+
Do you want to **contribute a failing test**? [This tutorial will show you how](https://getrector.com/documentation/reporting-issue-with-rector)
30+
31+
## Preparing Pull Request
32+
33+
3 steps will make your pull-request easy to merge:
34+
35+
- **1 feature per pull-request**
36+
- **new features need tests**
37+
- CI must pass... you can mimic it locally by running
38+
39+
```bash
40+
composer complete-check
41+
```
42+
43+
- Do you need to fix coding standards?
44+
45+
```bash
46+
composer fix-cs
47+
```
48+
49+
We would be happy to accept PRs that follow these guidelines.
50+
51+
### Using Docker
52+
53+
A `docker-compose.yml` file is provided to make it easier to run the CI checks locally.
54+
To use it, you need to have Docker installed on your machine, then you can build the image and execute the
55+
above commands in a docker container:
56+
57+
```bash
58+
# Build the docker image
59+
docker compose build --pull
60+
61+
# Install dependencies
62+
docker compose run --rm php composer install
63+
64+
# Run the entire CI suite
65+
docker compose run --rm php composer complete-check
66+
67+
# Fix the coding standards
68+
docker compose run --rm php composer fix-cs
69+
```
70+
71+
## TroubleShooting
72+
If you are on macOS, and got hang on applying patch, you may need to install gpatch, you can install with:
73+
74+
`brew install gpatch`
75+
76+
## Repository layout
77+
Documentation goes into `build/target-repository/docs`.

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM php:8.2-cli-alpine
2+
3+
WORKDIR /etc/rector
4+
5+
# required for composer patches
6+
RUN apk add --no-cache patch git
7+
8+
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
9+
10+
RUN mkdir -p /etc/rector
11+
RUN git config --global --add safe.directory /etc/rector

LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
The MIT License
2+
---------------
3+
4+
Copyright (c) 2017-present Tomas Votruba (https://tomasvotruba.com)
5+
6+
Permission is hereby granted, free of charge, to any person
7+
obtaining a copy of this software and associated documentation
8+
files (the "Software"), to deal in the Software without
9+
restriction, including without limitation the rights to use,
10+
copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following
13+
conditions:
14+
15+
The above copyright notice and this permission notice shall be
16+
included in all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25+
OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Rector - Instant Upgrades and Automated Refactoring
2+
3+
[![Downloads](https://img.shields.io/packagist/dt/rector/rector.svg?style=flat-square)](https://packagist.org/packages/rector/rector)
4+
5+
<br>
6+
7+
This repository (`rectorphp/rector-src`) is for development Rector only.
8+
Head to [`rectorphp/rector`](http://github.com/rectorphp/rector) for documentation, install or [creating an issue](https://github.com/rectorphp/rector/issues/new).
9+
10+
<br>
11+
12+
## Building `rectorphp/rector`
13+
14+
Code of this repository requires PHP 8. For `rector/rector` package the build downgrades code to PHP 7.4+.
15+
16+
<br>
17+
18+
## How to Contribute
19+
20+
Please read [contributing guideline](/CONTRIBUTING.md) for how to contribute to rector.
21+
22+
<br>
23+
24+
## Debug Tests
25+
26+
Do you need to measure speed of particular test? Or just check which test fixture is failing? Make use of pretty print:
27+
28+
```bash
29+
vendor/bin/phpunit -d --enable-pretty-print
30+
```
31+
32+
<br>
33+
34+
## Code of Conduct
35+
36+
This project adheres to a [Contributor Code of Conduct](/CODE_OF_CONDUCT.md) By participating in this project and its community, you are expected to uphold this code.
37+
38+
<br>
39+
40+
## Rector Packages CI Status
41+
42+
**Symfony** - https://github.com/rectorphp/rector-symfony
43+
44+
* ![](https://github.com/rectorphp/rector-symfony/actions/workflows/tests.yaml/badge.svg)
45+
![](https://github.com/rectorphp/rector-symfony/actions/workflows/code_analysis.yaml/badge.svg)
46+
47+
**PHPUnit** - https://github.com/rectorphp/rector-phpunit
48+
49+
* ![](https://github.com/rectorphp/rector-phpunit/actions/workflows/tests.yaml/badge.svg)
50+
![](https://github.com/rectorphp/rector-phpunit/actions/workflows/code_analysis.yaml/badge.svg)
51+
52+
**Doctrine** - https://github.com/rectorphp/rector-doctrine
53+
54+
* ![](https://github.com/rectorphp/rector-doctrine/actions/workflows/tests.yaml/badge.svg)
55+
![](https://github.com/rectorphp/rector-doctrine/actions/workflows/code_analysis.yaml/badge.svg)
56+
57+
**Downgrade PHP** - https://github.com/rectorphp/rector-downgrade-php
58+
59+
* ![](https://github.com/rectorphp/rector-downgrade-php/actions/workflows/tests.yaml/badge.svg)
60+
![](https://github.com/rectorphp/rector-downgrade-php/actions/workflows/code_analysis.yaml/badge.svg)

UPGRADING.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Upgrading from Rector 1.x to 2.0
2+
3+
## PHP version requirements
4+
5+
Rector now uses PHP 7.4 or newer to run.
6+
7+
<br>
8+
9+
## Rector now uses PHP-Parser 5
10+
11+
See [upgrading guide](https://github.com/nikic/PHP-Parser/blob/master/UPGRADE-5.0.md) for PHP-Parser.
12+
13+
<br>
14+
15+
## Rector now uses PHPStan 2
16+
17+
See [upgrading guide](https://github.com/phpstan/phpstan-src/blob/2.0.x/UPGRADING.md) for PHPStan.
18+
19+
<br>
20+
21+
## Upgrade for custom Rules writers
22+
23+
### 1. `AbstractScopeAwareRector` is removed, use `AbstractRector` instead
24+
25+
The `Rector\Rector\AbstractScopeAwareRector` was too granular to fetch single helper object. It made creating new custom rules ambiguous, one layer more complex and confusing. This class has been removed in favor of standard `AbstractRector`. The `Scope` object can be fetched via `ScopeFetcher`.
26+
27+
**Before**
28+
29+
```php
30+
use Rector\Rector\AbstractScopeAwareRector;
31+
32+
final class SimpleRector extends AbstractScopeAwareRector
33+
{
34+
public function refactorWithScope(Node $node, Scope $scope): ?Node
35+
{
36+
// ...
37+
}
38+
}
39+
```
40+
41+
**After**
42+
43+
```php
44+
use Rector\Rector\AbstractRector;
45+
use Rector\PHPStan\ScopeFetcher;
46+
47+
final class SimpleRector extends AbstractRector
48+
{
49+
public function refactor(Node $node): ?Node
50+
{
51+
if (...) {
52+
// this allow to fetch scope only when needed
53+
$scope = ScopeFetcher::fetch($node);
54+
}
55+
56+
// ...
57+
}
58+
}
59+
```
60+
61+
62+
### 2. `AbstractRector` get focused on code, the `getRuleDefinition()` is no longer required
63+
64+
Core rules need documentation, so people can read their feature and [search through](https://getrector.com/find-rule) them. Yet for writing custom rules and local rules, its not necessary. People often filled it empty, just to make Rector happy.
65+
66+
This is no longer needed. Now The `getRuleDefinition()` method has been removed:
67+
68+
```diff
69+
use Rector\Rector\AbstractRector;
70+
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
71+
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
72+
73+
final class SimpleRector extends AbstractRector
74+
{
75+
- public function getRuleDefinition(): RuleDefinition
76+
- {
77+
- return new RuleDefinition('// @todo fill the description', [
78+
- new CodeSample(
79+
- <<<'CODE_SAMPLE'
80+
-// @todo fill code before
81+
-CODE_SAMPLE
82+
- ,
83+
- <<<'CODE_SAMPLE'
84+
-// @todo fill code after
85+
-CODE_SAMPLE
86+
- ),
87+
- ]);
88+
- }
89+
90+
// valuable code here
91+
}
92+
```
93+
94+
If you need description yourself to understand rule after many months, use the common place for documentation - docblock above class.
95+
96+
97+
### 3. `SetListInterface` was removed
98+
99+
The deprecated `SetListInterface` was removed, if you created your own list just remove the Interface from it:
100+
101+
```diff
102+
-use Rector\Set\Contract\SetListInterface;
103+
104+
-final class YourSetList implements SetListInterface
105+
+final class YourSetList
106+
```

bin/add-phpstan-self-replace.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
// this is part of downgrade build
4+
5+
declare(strict_types=1);
6+
7+
use Nette\Utils\FileSystem;
8+
use Nette\Utils\Json;
9+
use PackageVersions\Versions;
10+
11+
require __DIR__ . '/../vendor/autoload.php';
12+
13+
$composerJsonFileContents = FileSystem::read(__DIR__ . '/../composer.json');
14+
15+
$composerJson = Json::decode($composerJsonFileContents, forceArrays: true);
16+
// result output is like: // 1.0.0@0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
17+
[$phpstanVersion] = explode('@', Versions::getVersion('phpstan/phpstan'));
18+
$composerJson['replace']['phpstan/phpstan'] = $phpstanVersion;
19+
20+
$modifiedComposerJsonFileContents = Json::encode($composerJson, pretty: true);
21+
FileSystem::write(__DIR__ . '/../composer.json', $modifiedComposerJsonFileContents, null);
22+
23+
echo 'Done!' . PHP_EOL;

0 commit comments

Comments
 (0)