[Scoper] Remove Doctrine\Inflector\Inflector from exclude class#582
[Scoper] Remove Doctrine\Inflector\Inflector from exclude class#582TomasVotruba merged 2 commits intomainfrom
Conversation
|
/cc @soilSpoon this is to fix the doctrine inflector issue on rectorphp/rector#6607 beside the autoload definition that I send to your repo soilSpoon/example-app#2 |
|
All checks have passed 🎉 @TomasVotruba it is ready for review. |
|
I think this would make Inflector part of public API which is not our intention. Reproducible repository is needed in this case. |
|
@TomasVotruba the reproducible repository is on @soilSpoon's https://github.com/soilSpoon/example-app for @soilSpoon other solution is by manually add more require-dev : composer require --dev doctrine/inflectorafter use of custom bootstrap at PR soilSpoon/example-app#2 |
|
Thanks 👍 What is the command being run to see the error? This works for me: composer install
vendor/bin/rector p -n --clear-cache |
|
On PR soilSpoon/example-app#2 , I set the paths to - $parameters->set(Option::PATHS, [__DIR__ . '/app/Providers']);
+ $parameters->set(Option::PATHS, [__DIR__ . '/app']);it will got error: vendor/bin/rector p -n --clear-cache
19/19 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
1 file with changes
===================
1) app/Models/User.php
---------- begin diff ----------
@@ @@
-<?php
-
-namespace App\Models;
-
-use Illuminate\Contracts\Auth\MustVerifyEmail;
-use Illuminate\Database\Eloquent\Factories\HasFactory;
-use Illuminate\Database\Eloquent\Relations\HasMany;
-use Illuminate\Foundation\Auth\User as Authenticatable;
-use Illuminate\Notifications\Notifiable;
-
-class User extends Authenticatable
-{
- use HasFactory;
- use Notifiable;
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $fillable = [
- 'name',
- 'email',
- 'password',
- ];
-
- /**
- * The attributes that should be hidden for arrays.
- *
- * @var array
- */
- protected $hidden = [
- 'password',
- 'remember_token',
- ];
-
- /**
- * The attributes that should be cast to native types.
- *
- * @var array
- */
- protected $casts = [
- 'email_verified_at' => 'datetime',
- ];
-
- public function user(): HasMany
- {
- return $this->hasMany(Post::class);
- }
-
- public function getPosts()
- {
- return $this->name === 'foo' ? Post::all() : collect();
- }
-}
----------- end diff -----------
[ERROR] Could not process "app/Models/User.php" file, due to:
"RectorPrefix20210802\Doctrine\Inflector\Inflector::__construct(): Argument #1 ($singularizer) must be of type
RectorPrefix20210802\Doctrine\Inflector\WordInflector, Doctrine\Inflector\CachedWordInflector given, called in
vendor/laravel/framework/src/Illuminate/Support/Pluralizer.php:140". On line: 28 |
|
Adding: composer require --dev doctrine/inflectorseems still not the solution, it still got error: [ERROR] Could not process "app/Models/User.php" file, due to:
"RectorPrefix20210802\Doctrine\Inflector\Inflector::__construct(): Argument #1 ($singularizer) must be of type
RectorPrefix20210802\Doctrine\Inflector\WordInflector, Doctrine\Inflector\CachedWordInflector given, called in
vendor/laravel/framework/src/Illuminate/Support/Pluralizer.php:140". On line: 28 which looking for non-existent |
|
Good, this command breaks 👍 Thanks vendor/bin/rector p app/Models/User.php -n --clear-cache --debug |
|
is it merge-able then? or need to add : 'Doctrine\Inflector\WordInflector'to |
|
I'm looking at it an it seems the Laravel loads Doctrine/Inflector first in Then Rector gets the same class and crashes. Rector needs the prefixed version. I think it might help to add Could you verify? |
|
Add only ➜ example-app git:(bar) vendor/bin/rector p app/Models/User.php -n --clear-cache --debug
[parsing] app/Models/User.php
PHP Fatal error: Declaration of Doctrine\Inflector\CachedWordInflector::inflect(string $word): string must be compatible with RectorPrefix20210803\Doctrine\Inflector\WordInflector::inflect($word): string in /Users/samsonasik/www/example-app/vendor/doctrine/inflector/lib/Doctrine/Inflector/CachedWordInflector.php on line 20
Symfony\Component\ErrorHandler\Error\FatalError
Declaration of Doctrine\Inflector\CachedWordInflector::inflect(string $word): string must be compatible with RectorPrefix20210803\Doctrine\Inflector\WordInflector::inflect($word): string
at vendor/doctrine/inflector/lib/Doctrine/Inflector/CachedWordInflector.php:20
16▕ {
17▕ $this->wordInflector = $wordInflector;
18▕ }
19▕
➜ 20▕ public function inflect(string $word) : string
21▕ {
22▕ return $this->cache[$word] ?? $this->cache[$word] = $this->wordInflector->inflect($word);
23▕ }
24▕ }
Whoops\Exception\ErrorException
Declaration of Doctrine\Inflector\CachedWordInflector::inflect(string $word): string must be compatible with RectorPrefix20210803\Doctrine\Inflector\WordInflector::inflect($word): string
at vendor/doctrine/inflector/lib/Doctrine/Inflector/CachedWordInflector.php:20
16▕ {
17▕ $this->wordInflector = $wordInflector;
18▕ }
19▕
➜ 20▕ public function inflect(string $word) : string
21▕ {
22▕ return $this->cache[$word] ?? $this->cache[$word] = $this->wordInflector->inflect($word);
23▕ }
24▕ }
+1 vendor frames
2 [internal]:0
Whoops\Run::handleShutdown() |
|
Remove completely Step to reproduce:
|
|
All checks have passed 🎉 @TomasVotruba let's give it a try? |
|
Thank you! It makes sense, and the bug also. When we scope only some classes from one namespace, the rest can be autoloaded with priority by the project itself. Let's ship it 👍 |


Fixes rectorphp/rector#6607
to avoid error: