Skip to content

Commit

Permalink
[DX] Remove only use case of exclusive file fixture, keep it simple (#…
Browse files Browse the repository at this point in the history
…2866)

* [DX] Remove only use case of exclusive file fixture, keep it simple

* bump to fixed symplify/phsptan-rules
  • Loading branch information
TomasVotruba committed Aug 31, 2022
1 parent 8ce5353 commit f91dba4
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 71 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"symplify/monorepo-builder": "^11.1",
"symplify/phpstan-extensions": "^11.1",
"symplify/phpstan-rules": "^11.1",
"symplify/rule-doc-generator": "dev-main",
"symplify/rule-doc-generator": "^11.1",
"symplify/vendor-patches": "^11.1"
},
"replace": {
Expand Down
65 changes: 0 additions & 65 deletions packages/Testing/Fixture/FixtureFileFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,69 +41,4 @@ private static function findFilesInDirectory(string $directory, string $suffix):
$fileInfos = iterator_to_array($finder);
return array_values($fileInfos);
}

/**
* @return Iterator<array<int, SmartFileInfo>>
*/
public static function yieldDirectoryExclusively(string $directory, string $suffix = '*.php.inc'): Iterator
{
$fileInfos = self::findFilesInDirectoryExclusively($directory, $suffix);

return self::yieldFileInfos($fileInfos);
}

private static function ensureNoOtherFileName(string $directory, string $suffix): void
{
$finder = Finder::create()->in($directory)
->files()
->notName($suffix);

/** @var SplFileInfo[] $fileInfos */
$fileInfos = iterator_to_array($finder->getIterator());

$relativeFilePaths = [];
foreach ($fileInfos as $fileInfo) {
$relativeFilePaths[] = Strings::substring($fileInfo->getRealPath(), strlen(getcwd()) + 1);
}

if ($relativeFilePaths === []) {
return;
}

throw new ShouldNotHappenException(sprintf(
'Files "%s" have invalid suffix, use "%s" suffix instead',
implode('", ', $relativeFilePaths),
$suffix
));
}

/**
* @return SplFileInfo[]
*/
private static function findFilesInDirectoryExclusively(string $directory, string $suffix): array
{
self::ensureNoOtherFileName($directory, $suffix);

$finder = Finder::create()->in($directory)
->files()
->name($suffix);

$fileInfos = iterator_to_array($finder->getIterator());
return array_values($fileInfos);
}

/**
* @param SplFileInfo[] $fileInfos
* @return Iterator<array<int, SmartFileInfo>>
*/
private static function yieldFileInfos(array $fileInfos): Iterator
{
foreach ($fileInfos as $fileInfo) {
try {
$smartFileInfo = new SmartFileInfo($fileInfo->getRealPath());
yield [$smartFileInfo];
} catch (FileNotFoundException) {
}
}
}
}
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -743,3 +743,6 @@ parameters:
-
message: '#Only booleans are allowed in a negated boolean, string\|false given#'
path: packages/Testing/Fixture/FixtureFileUpdater.php

# resolve later
- '#Content of method "(.*)" is duplicated\. Use unique content or service instead#'
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ public function testUsesFromProperty(SmartFileInfo $file): void
*/
public function provideData(): Iterator
{
return FixtureFileFinder::yieldDirectoryExclusively(__DIR__ . '/Fixture');
return FixtureFileFinder::yieldDirectory(__DIR__ . '/Fixture');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function refactor(Node $node): ?Node
}

$maximumAllowedParameterCount = $this->resolveMaximumAllowedParameterCount($functionLikeReflection);
//
//
if ($node->isFirstClassCallable()) {
return null;
}
Expand Down
1 change: 0 additions & 1 deletion rules/Php80/NodeFactory/MatchFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function createFromCondAndExprs(Expr $condExpr, array $condAndExprs, ?Stm

// is default value missing? maybe it can be found in next stmt
if (! $this->matchSwitchAnalyzer->hasCondsAndExprDefaultValue($condAndExprs)) {

// 1. is followed by throws stmts?
if ($nextStmt instanceof ThrowsStmt) {
$throw = new Throw_($nextStmt->expr);
Expand Down
1 change: 0 additions & 1 deletion rules/Renaming/NodeManipulator/ClassRenamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ private function refactorName(Name $name, array $oldToNewClasses): ?Name

// no need to preslash "use \SomeNamespace" of imported namespace
if ($parentNode instanceof UseUse && ($parentNode->type === Use_::TYPE_NORMAL || $parentNode->type === Use_::TYPE_UNKNOWN)) {

// no need to rename imports, they will be handled by autoimport and coding standard
// also they might cause some rename
return null;
Expand Down
2 changes: 1 addition & 1 deletion rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function narrowToFullyQualifiedOrAliasedObjectType(
ObjectType $objectType,
Scope|null $scope
): TypeWithClassName | NonExistingObjectType | UnionType | MixedType {
// $nameScope = $this->nameScopeFactory->createNameScopeFromNodeWithoutTemplateTypes($node);
// $nameScope = $this->nameScopeFactory->createNameScopeFromNodeWithoutTemplateTypes($node);
// @todo reuse name scope

if ($scope instanceof Scope) {
Expand Down

0 comments on commit f91dba4

Please sign in to comment.