Skip to content

Commit

Permalink
Cleanup of SmartFileSystem (#2854)
Browse files Browse the repository at this point in the history
* cleanup of filesystem

* use different class name than active service
  • Loading branch information
TomasVotruba committed Aug 29, 2022
1 parent 1a7e63b commit 6e2915c
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 35 deletions.
3 changes: 0 additions & 3 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@
$services->set(ParameterProvider::class)
->arg('$container', service('service_container'));

$services->set(SmartFileSystem::class);
$services->set(JsonFileSystem::class);

$services->set(InflectorFactory::class);
$services->set(Inflector::class)
->factory([service(InflectorFactory::class), 'build']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
use Rector\BetterPhpDocParser\Printer\PhpDocInfoPrinter;
use Rector\Testing\PHPUnit\AbstractTestCase;
use Symplify\EasyTesting\DataProvider\StaticFixtureFinder;
use Symplify\SmartFileSystem\SmartFileSystem;

abstract class AbstractPhpDocInfoPrinterTest extends AbstractTestCase
{
protected PhpDocInfoPrinter $phpDocInfoPrinter;

protected SmartFileSystem $smartFileSystem;

private PhpDocInfoFactory $phpDocInfoFactory;

protected function setUp(): void
Expand All @@ -28,7 +25,6 @@ protected function setUp(): void

$this->phpDocInfoFactory = $this->getService(PhpDocInfoFactory::class);
$this->phpDocInfoPrinter = $this->getService(PhpDocInfoPrinter::class);
$this->smartFileSystem = $this->getService(SmartFileSystem::class);
}

protected function createPhpDocInfoFromDocCommentAndNode(string $docComment, Node $node): PhpDocInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symplify\SmartFileSystem\SmartFileInfo;
use Symplify\SmartFileSystem\SmartFileSystem;

final class FileCacheStorageTest extends AbstractRectorTestCase
{
Expand All @@ -17,7 +17,7 @@ protected function setUp(): void
{
parent::setUp();

$this->fileCacheStorage = new FileCacheStorage(__DIR__ . '/Source', $this->getService(SmartFileSystem::class));
$this->fileCacheStorage = new FileCacheStorage(__DIR__ . '/Source', new Filesystem());
}

public function testClean(): void
Expand Down
1 change: 0 additions & 1 deletion packages/Caching/ValueObject/Storage/FileCacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Rector\Caching\ValueObject\CacheFilePaths;
use Rector\Caching\ValueObject\CacheItem;
use Rector\Core\Exception\Cache\CachingException;
use Symplify\SmartFileSystem\SmartFileSystem;

/**
* Inspired by https://github.com/phpstan/phpstan-src/blob/1e7ceae933f07e5a250b61ed94799e6c2ea8daa2/src/Cache/FileCacheStorage.php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ use Nette\Utils\FileSystem;

class SomeClass
{
public function __construct(private \Symplify\SmartFileSystem\SmartFileSystem $smartFileSystem)
public function __construct(private \Rector\Tests\Transform\Rector\StaticCall\StaticCallToMethodCallRector\Source\TargetFileSystem $targetFileSystem)
{
}
public function run()
{
return $this->smartFileSystem->dumpFile('file', 'content');
return $this->targetFileSystem->dumpFile('file', 'content');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use Nette\Utils\FileSystem;

class InConstructor
{
public function __construct(\Symplify\SmartFileSystem\SmartFileSystem $smartFileSystem)
public function __construct(\Rector\Tests\Transform\Rector\StaticCall\StaticCallToMethodCallRector\Source\TargetFileSystem $targetFileSystem)
{
return $smartFileSystem->dumpFile('file', 'content');
return $targetFileSystem->dumpFile('file', 'content');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class InstantMakeInStaticMethod
{
public static function run()
{
return (new \Symplify\SmartFileSystem\SmartFileSystem())->dumpFile('file', 'content');
return (new \Rector\Tests\Transform\Rector\StaticCall\StaticCallToMethodCallRector\Source\TargetFileSystem())->dumpFile('file', 'content');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

namespace Rector\Tests\Transform\Rector\StaticCall\StaticCallToMethodCallRector\Source;

use Symplify\SmartFileSystem\SmartFileSystem;

abstract class ClassWithFileSystem
{
/**
* @var SmartFileSystem
* @var TargetFileSystem
*/
public $smartFileSystemProperty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

namespace Rector\Tests\Transform\Rector\StaticCall\StaticCallToMethodCallRector\Source;

use Symplify\SmartFileSystem\SmartFileSystem;

abstract class ClassWithFileSystemMethod
{
public function getSmartFileSystem(): SmartFileSystem
public function getSmartFileSystem(): TargetFileSystem
{
return new SmartFileSystem();
return new TargetFileSystem();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);

namespace Rector\Tests\Transform\Rector\StaticCall\StaticCallToMethodCallRector\Source;

final class TargetFileSystem
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Tests\Transform\Rector\StaticCall\StaticCallToMethodCallRector\Source\TargetFileSystem;
use Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector;
use Rector\Transform\ValueObject\StaticCallToMethodCall;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig
->ruleWithConfiguration(StaticCallToMethodCallRector::class, [
new StaticCallToMethodCall(
'Nette\Utils\FileSystem',
'write',
'Symplify\SmartFileSystem\SmartFileSystem',
'dumpFile'
),
new StaticCallToMethodCall('Nette\Utils\FileSystem', 'write', TargetFileSystem::class, 'dumpFile'),
new StaticCallToMethodCall(
'Illuminate\Support\Facades\Response',
'*',
Expand Down
11 changes: 4 additions & 7 deletions rules/PSR4/Composer/PSR4AutoloadPathsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace Rector\PSR4\Composer;

use Nette\Utils\FileSystem;
use Nette\Utils\Json;
use Symplify\ComposerJsonManipulator\ValueObject\ComposerJsonSection;
use Symplify\SmartFileSystem\Json\JsonFileSystem;

final class PSR4AutoloadPathsProvider
{
Expand All @@ -14,11 +15,6 @@ final class PSR4AutoloadPathsProvider
*/
private array $cachedComposerJsonPSR4AutoloadPaths = [];

public function __construct(
private readonly JsonFileSystem $jsonFileSystem
) {
}

/**
* @return array<string, string|string[]>
*/
Expand All @@ -28,7 +24,8 @@ public function provide(): array
return $this->cachedComposerJsonPSR4AutoloadPaths;
}

$composerJson = $this->jsonFileSystem->loadFilePathToJson($this->getComposerJsonPath());
$fileContents = FileSystem::read($this->getComposerJsonPath());
$composerJson = Json::decode($fileContents, Json::FORCE_ARRAY);
$psr4Autoloads = array_merge(
$composerJson[ComposerJsonSection::AUTOLOAD]['psr-4'] ?? [],
$composerJson[ComposerJsonSection::AUTOLOAD_DEV]['psr-4'] ?? []
Expand Down

0 comments on commit 6e2915c

Please sign in to comment.