diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 312b1c94..1b5084f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: - name: "Run friendsofphp/php-cs-fixer" - run: "vendor/bin/php-cs-fixer fix --dry-run --diff --verbose" + run: "vendor/bin/php-cs-fixer fix --dry-run --diff --verbose --allow-risky=yes" phpstan: name: "PHPStan (${{ matrix.php-version }})" @@ -87,6 +87,7 @@ jobs: php-version: - '7.3' - '7.4' + - '8.0' steps: - diff --git a/.gitignore b/.gitignore index 217f2292..e87ba04f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ /composer.lock /.php_cs.cache /stubs +/.vscode +.php_cs.cache \ No newline at end of file diff --git a/.php_cs.dist b/.php_cs.dist index a3d5fa36..2820b890 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -4,7 +4,7 @@ $finder = PhpCsFixer\Finder::create() ->in('lib') ->in('tests') ->exclude([ - 'tests/Workspace' + 'tests/Workspace', ]) ; @@ -13,6 +13,11 @@ return PhpCsFixer\Config::create() '@PSR2' => true, 'no_unused_imports' => true, 'array_syntax' => ['syntax' => 'short'], + 'void_return' => true, + 'ordered_class_elements' => true, + 'single_quote' => true, + 'heredoc_indentation' => true, + 'global_namespace_import' => true, ]) ->setFinder($finder) ; diff --git a/README.md b/README.md index 2095db24..f480f40c 100644 --- a/README.md +++ b/README.md @@ -40,3 +40,16 @@ Assert::assertTrue($workspace->exists('lib/Foo/ClassTwo.php')); echo $workspace->getContents('/lib/Foo/ClassTwo.php'); ``` + +Contributing +------------ + +This package is open source and welcomes contributions! Feel free to open a +pull request on this repository. + +Support +------- + +- Create an issue on the main [Phpactor](https://github.com/phpactor/phpactor) repository. +- Join the `#phpactor` channel on the Slack [Symfony Devs](https://symfony.com/slack-invite) channel. + diff --git a/composer.json b/composer.json index 928c9b35..de4aed13 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,8 @@ } ], "require": { - "php": "^7.3", - "webmozart/path-util": "^2.3" + "php": "^7.3 || ^8.0", + "symfony/filesystem": "^4.2 || ^5.0 || ^6.0 || ^7.0" }, "require-dev": { "dms/phpunit-arraysubset-asserts": "dev-master", @@ -43,5 +43,8 @@ "vendor/bin/phpstan analyse lib -c phpstan.neon", "vendor/bin/phpunit" ] + }, + "config": { + "allow-plugins": true } -} \ No newline at end of file +} diff --git a/lib/ExtractOffset.php b/lib/ExtractOffset.php index 792f18f8..c9acd5c1 100644 --- a/lib/ExtractOffset.php +++ b/lib/ExtractOffset.php @@ -9,21 +9,21 @@ class ExtractOffset { /** - * @return array + * @return array{string,int,int} */ public static function fromSource(string $source, string $marker = '<>'): array { list($source, $offsetStart) = self::extractOffset($source, $marker); list($source, $offsetEnd) = self::extractOffset($source, $marker); - return [$source, $offsetStart, $offsetEnd]; + return [$source, (int)$offsetStart, (int)$offsetEnd]; } /** * Extract the byte offset from the given marked source * and remove the <> mark. * - * @return array + * @return array{string,int} */ private static function extractOffset(string $source, string $marker): array { diff --git a/lib/Workspace.php b/lib/Workspace.php index a1dabdc9..5d0e6fe2 100644 --- a/lib/Workspace.php +++ b/lib/Workspace.php @@ -7,7 +7,7 @@ use RecursiveIteratorIterator; use RuntimeException; use SplFileInfo; -use Webmozart\PathUtil\Path; +use Symfony\Component\Filesystem\Path; class Workspace { @@ -18,7 +18,7 @@ class Workspace public function __construct(string $path) { - $this->path = $path; + $this->path = Path::canonicalize($path); } public static function create(string $path): self @@ -118,7 +118,7 @@ public function loadManifest(string $manifest): void */ private function parseManifest(string $manifest): array { - $lines = explode(PHP_EOL, $manifest); + $lines = explode("\n", $manifest); $buffer = []; $currentFile = null; @@ -143,7 +143,7 @@ private function parseManifest(string $manifest): array } return array_map(function (array $lines) { - return implode(PHP_EOL, $lines); + return implode("\n", $lines); }, $buffer); } diff --git a/tests/Integration/WorkspaceTest.php b/tests/Integration/WorkspaceTest.php index 818cc7eb..fda39efc 100644 --- a/tests/Integration/WorkspaceTest.php +++ b/tests/Integration/WorkspaceTest.php @@ -7,32 +7,37 @@ class WorkspaceTest extends IntegrationTestCase { + /** + * @var Workspace + */ + private $workspace; + protected function setUp(): void { $this->workspace = Workspace::create($this->workspaceDir()); $this->workspace->reset(); } - public function testBuild() + public function testBuild(): void { $manifest = <<<'EOT' -// File: Foobar.php -workspace->loadManifest($manifest); @@ -43,7 +48,7 @@ class Barfoo $this->assertEquals('Hello World', $this->workspace->getContents('Expected.php')); } - public function testGetContentsNotExist() + public function testGetContentsNotExist(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('File "barbarbarbar" does not exist'); @@ -51,7 +56,7 @@ public function testGetContentsNotExist() $this->workspace->getContents('barbarbarbar'); } - public function testReset() + public function testReset(): void { $this->workspace->reset(); touch($this->workspace->path('Foobar.php')); @@ -67,31 +72,31 @@ public function testReset() $this->assertFalse($this->workspace->exists('Barfoo/Bazboo.php')); } - public function testMkdir() + public function testMkdir(): void { $this->workspace->mkdir('foobar'); $this->assertTrue($this->workspace->exists('foobar')); $this->assertFalse($this->workspace->exists('barfoo')); } - public function testPutFileContents() + public function testPutFileContents(): void { $this->workspace->put('foobar', 'foobar contents'); $this->assertTrue($this->workspace->exists('foobar')); $this->assertStringContainsString('foobar contents', $this->workspace->getContents('foobar')); } - public function testGetPathWithNoArgs() + public function testGetPathWithNoArgs(): void { $this->assertEquals($this->workspaceDir(), $this->workspace->path()); } - public function testGetPath() + public function testGetPath(): void { $this->assertEquals($this->workspaceDir() . '/foo', $this->workspace->path('foo')); } - public function testGetPathConcat() + public function testGetPathConcat(): void { $workspace = Workspace::create($this->workspaceDir() . '/foobar/'); $this->assertEquals($this->workspaceDir() . '/foobar/foo', $workspace->path('foo'));