Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9717676

Browse files
committed
feat: Rector rules to help migrating away from proxy (#941)
* feat(rector): MethodCallToFuncCallWIthObjectAsFirstParameterRector * feat(rector): RemoveMethodCallRector * feat(rector): RemoveWithoutAutorefreshCallRector * feat(rector): RemoveFunctionCallRector * chore(rector): add a workflow to test Rector rules * chore(rector): ChangeFactoryBaseClassRector * chore(rector): RemovePhpDocProxyTypeHintRector * feat(rector): delete full expressions in RemoveMethodCallRector * feat(rector): prevent false positive in RemovePhpDocProxyTypeHintRector * feat(rector): add RemoveUnproxifyArrayMapRector * feat(rector): don't change parent of child factory in ChangeFactoryBaseClassRector * feat(rector): remove _set() from MethodCallToFuncCallWIthObjectASFirstParameter * feat(rector): change Zenstruck\Foundry\set in order to return current object * fix(rector): ChangeFactoryBaseClassRector should handle generic classes * feat(rector): add rector ChangeProxyReturnTypesRector * feat(rector): handle @method in RemovePhpDocProxyTypeHintRector * feat(rector): add rector ChangeProxyParamTypesRector * fix(rector): remove usage of Webmozart\Assert * fix(rector): misc fixes on MethodCallToFuncCallWithObjectAsFirstParameterRector bot: fix cs [skip ci]
1 parent 35e8da6 commit 9717676

88 files changed

Lines changed: 3771 additions & 7 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
paths:
6+
- 'utils/rector/**'
7+
pull_request:
8+
paths:
9+
- 'utils/rector/**'
10+
schedule:
11+
- cron: '0 0 1,16 * *'
12+
13+
jobs:
14+
test-rector-rules:
15+
name: Test rector rules
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v3
20+
21+
- name: Setup PHP
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: 8.4
25+
coverage: none
26+
27+
- name: Install dependencies
28+
uses: ramsey/composer-install@v2
29+
with:
30+
composer-options: --prefer-dist
31+
32+
- name: Install Rector & PHPStan
33+
run: |
34+
composer update phpunit/phpunit:^11 brianium/paratest -W
35+
36+
composer bin phpstan install
37+
composer bin rector install
38+
39+
- name: Test
40+
run: vendor/bin/phpunit -c phpunit-rector.xml.dist
41+
shell: bash
42+
43+
- name: Static analysis
44+
run: bin/tools/rector/vendor/phpstan/phpstan/phpstan analyse -c utils/rector/phpstan.neon
45+
shell: bash

bin/tools/rector/composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"require": {
3+
"rector/rector": "^2.0",
4+
"phpstan/phpstan-doctrine": "^2.0"
5+
}
6+
}

bin/tools/rector/composer.lock

Lines changed: 208 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@
4949
"symfony/translation-contracts": "^3.4",
5050
"symfony/uid": "^6.4|^7.0|^8.0",
5151
"symfony/var-dumper": "^6.4|^7.0|^8.0",
52-
"symfony/yaml": "^6.4|^7.0|^8.0"
52+
"symfony/yaml": "^6.4|^7.0|^8.0",
53+
"webmozart/assert": "^1.11"
5354
},
5455
"autoload": {
5556
"psr-4": {
5657
"Zenstruck\\Foundry\\": "src/",
57-
"Zenstruck\\Foundry\\Psalm\\": "utils/psalm"
58+
"Zenstruck\\Foundry\\Psalm\\": "utils/psalm",
59+
"Zenstruck\\Foundry\\Utils\\Rector\\": "utils/rector/src/"
5860
},
5961
"files": [
6062
"src/functions.php",
@@ -66,9 +68,10 @@
6668
"psr-4": {
6769
"Zenstruck\\Foundry\\Tests\\": ["tests/"],
6870
"App\\": "tests/Fixture/Maker/tmp/src",
69-
"App\\Tests\\": "tests/Fixture/Maker/tmp/tests"
71+
"App\\Tests\\": "tests/Fixture/Maker/tmp/tests",
72+
"Zenstruck\\Foundry\\Utils\\Rector\\Tests\\": "utils/rector/tests/"
7073
},
71-
"exclude-from-classmap": ["tests/Fixture/Maker/expected"]
74+
"exclude-from-classmap": ["tests/Fixture/Maker/expected", "utils/rector/tests/**/Fixtures/"]
7275
},
7376
"config": {
7477
"preferred-install": "dist",

phpunit-rector.xml.dist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- https://phpunit.readthedocs.io/en/9.5/configuration.html -->
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
colors="true"
6+
bootstrap="utils/rector/tests/bootstrap.php"
7+
failOnRisky="true"
8+
failOnWarning="true">
9+
10+
<php>
11+
<ini name="error_reporting" value="-1"/>
12+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0&amp;max[direct]=0&amp;quiet[]=indirect&amp;quiet[]=other"/>
13+
<env name="SHELL_VERBOSITY" value="0"/>
14+
</php>
15+
16+
<testsuites>
17+
<testsuite name="Rector">
18+
<directory>./utils/rector/tests/</directory>
19+
</testsuite>
20+
</testsuites>
21+
</phpunit>

src/Persistence/functions.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,26 @@ function enable_persisting(): void
201201
Configuration::instance()->persistence()->enablePersisting();
202202
}
203203

204-
function assert_persisted(object $object, string $message = '{entity} is not persisted.'): void
204+
function assert_persisted(object $object, string $message = '{entity} is not persisted.'): object
205205
{
206206
Configuration::instance()->assertPersistenceEnabled();
207207

208208
Assert::that(
209209
Configuration::instance()->persistence()->isPersisted($object)
210210
)->isTrue($message, ['entity' => $object::class]);
211+
212+
return $object;
211213
}
212214

213-
function assert_not_persisted(object $object, string $message = '{entity} is persisted.'): void
215+
function assert_not_persisted(object $object, string $message = '{entity} is persisted.'): object
214216
{
215217
Configuration::instance()->assertPersistenceEnabled();
216218

217219
Assert::that(
218220
Configuration::instance()->persistence()->isPersisted($object)
219221
)->isFalse($message, ['entity' => $object::class]);
222+
223+
return $object;
220224
}
221225

222226
/**

src/functions.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,17 @@ function object(string $class, array|callable $attributes = []): object
5151

5252
/**
5353
* "Force set" (using reflection) an object property.
54+
*
55+
* @template T of object
56+
* @param T $object
57+
*
58+
* @return T
5459
*/
55-
function set(object $object, string $property, mixed $value): void
60+
function set(object $object, string $property, mixed $value): object
5661
{
5762
Hydrator::set($object, $property, $value);
63+
64+
return $object;
5865
}
5966

6067
/**

0 commit comments

Comments
 (0)