-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DX] Skip vendor warning in case of downgrade (#5526)
* [DX] Skip vendor warning in case of downgrade * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <actions@github.com>
- Loading branch information
1 parent
0ff8cb0
commit a6b0d2c
Showing
2 changed files
with
54 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Configuration; | ||
|
||
use Rector\Configuration\Parameter\SimpleParameterProvider; | ||
use Rector\Skipper\FileSystem\PathNormalizer; | ||
|
||
final class VendorMissAnalyseGuard | ||
{ | ||
/** | ||
* @param string[] $filePaths | ||
*/ | ||
public function isVendorAnalyzed(array $filePaths): bool | ||
{ | ||
if ($this->hasDowngradeSets()) { | ||
return false; | ||
} | ||
|
||
return $this->containsVendorPath($filePaths); | ||
} | ||
|
||
private function hasDowngradeSets(): bool | ||
{ | ||
$registeredRectorSets = SimpleParameterProvider::provideArrayParameter(Option::REGISTERED_RECTOR_SETS); | ||
|
||
foreach ($registeredRectorSets as $registeredRectorSet) { | ||
if (str_contains((string) $registeredRectorSet, 'downgrade-')) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @param string[] $filePaths | ||
*/ | ||
private function containsVendorPath(array $filePaths): bool | ||
{ | ||
foreach ($filePaths as $filePath) { | ||
if (str_contains(PathNormalizer::normalize($filePath), '/vendor/')) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |