diff --git a/packages/dev/src/App/Example.php b/packages/dev/src/App/Example.php index 48beec065..6d7d5c266 100644 --- a/packages/dev/src/App/Example.php +++ b/packages/dev/src/App/Example.php @@ -6,8 +6,8 @@ use Illuminate\Contracts\Foundation\Application; use LastDragon_ru\LaraASP\Core\Application\ApplicationResolver; use LastDragon_ru\LaraASP\Core\Utils\ConfigMerger; -use LastDragon_ru\LaraASP\Documentator\Preprocessor\Instructions\IncludeExample\Contracts\Runner; use LastDragon_ru\LaraASP\Documentator\Processor\FileSystem\File; +use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Instructions\IncludeExample\Contracts\Runner; use LogicException; use Override; use PhpParser\ErrorHandler\Collecting; diff --git a/packages/dev/src/App/Provider.php b/packages/dev/src/App/Provider.php index f699645f1..aac56f64a 100644 --- a/packages/dev/src/App/Provider.php +++ b/packages/dev/src/App/Provider.php @@ -3,7 +3,7 @@ namespace LastDragon_ru\LaraASP\Dev\App; use Illuminate\Support\ServiceProvider; -use LastDragon_ru\LaraASP\Documentator\Preprocessor\Instructions\IncludeExample\Contracts\Runner; +use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Instructions\IncludeExample\Contracts\Runner; use Override; class Provider extends ServiceProvider { diff --git a/packages/documentator/UPGRADE.md b/packages/documentator/UPGRADE.md index 690c02bb3..c66b54401 100644 --- a/packages/documentator/UPGRADE.md +++ b/packages/documentator/UPGRADE.md @@ -38,10 +38,10 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases) [//]: # (end: 470dd21d18d5886f1873b1247130ac8173ed99258e41418c6bd32162325d628b) * [ ] Migrate to the new contract: - * `\LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\Instruction` - * `\LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\Parameters`. + * `\LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Contracts\Instruction` + * `\LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Contracts\Parameters`. -* [ ] Instruction `include:example` not check/run `.run` file anymore. The `\LastDragon_ru\LaraASP\Documentator\Preprocessor\Instructions\IncludeExample\Contracts\Runner` should be used/provided instead. +* [ ] Instruction `include:example` not check/run `.run` file anymore. The `\LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Instructions\IncludeExample\Contracts\Runner` should be used/provided instead. * [ ] `LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Task::__invoke()` should yield a `LastDragon_ru\LaraASP\Documentator\Processor\Contracts\Dependency` instead of file. diff --git a/packages/documentator/src/Commands/Commands.php b/packages/documentator/src/Commands/Commands.php index 2cc22fac5..616739f8f 100644 --- a/packages/documentator/src/Commands/Commands.php +++ b/packages/documentator/src/Commands/Commands.php @@ -16,8 +16,6 @@ use function is_dir; -// @phpcs:disable Generic.Files.LineLength.TooLong - #[AsCommand( name : Commands::Name, description: 'Saves help for each command in the `namespace` into a separate file in the `target` directory.', diff --git a/packages/documentator/src/Commands/Preprocess.php b/packages/documentator/src/Commands/Preprocess.php index ba42bb9c3..441d49a45 100644 --- a/packages/documentator/src/Commands/Preprocess.php +++ b/packages/documentator/src/Commands/Preprocess.php @@ -6,11 +6,11 @@ use LastDragon_ru\LaraASP\Core\Utils\Cast; use LastDragon_ru\LaraASP\Core\Utils\Path; use LastDragon_ru\LaraASP\Documentator\Package; -use LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\Instruction; -use LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\Parameters; -use LastDragon_ru\LaraASP\Documentator\Preprocessor\Preprocessor; use LastDragon_ru\LaraASP\Documentator\Processor\Processor; use LastDragon_ru\LaraASP\Documentator\Processor\Result; +use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Contracts\Instruction; +use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Contracts\Parameters; +use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Task; use LastDragon_ru\LaraASP\Documentator\Utils\Markdown; use LastDragon_ru\LaraASP\Documentator\Utils\PhpDoc; use LastDragon_ru\LaraASP\Formatter\Formatter; @@ -39,7 +39,7 @@ use function var_export; /** - * @see Preprocessor + * @see Task */ #[AsCommand( name : Preprocess::Name, @@ -70,7 +70,7 @@ class Preprocess extends Command { HELP; public function __construct( - protected readonly Preprocessor $preprocessor, + protected readonly Task $preprocess, ) { parent::__construct(); } @@ -100,7 +100,7 @@ public function __invoke(Formatter $formatter): void { }; $duration = (new Processor()) - ->task($this->preprocessor) + ->task($this->preprocess) ->run($path, $exclude, $listener); $this->output->newLine(); @@ -116,11 +116,11 @@ public function getProcessedHelp(): string { } protected function getProcessedHelpDescription(): string { - return $this->getDocBlock(new ReflectionClass(Preprocessor::class)); + return $this->getDocBlock(new ReflectionClass(Task::class)); } protected function getProcessedHelpInstructions(): string { - $instructions = $this->preprocessor->getInstructions(); + $instructions = $this->preprocess->getInstructions(); $help = []; foreach ($instructions as $instruction) { diff --git a/packages/documentator/src/Commands/PreprocessTest.php b/packages/documentator/src/Commands/PreprocessTest.php index ef3043f1a..7e524d344 100644 --- a/packages/documentator/src/Commands/PreprocessTest.php +++ b/packages/documentator/src/Commands/PreprocessTest.php @@ -2,10 +2,10 @@ namespace LastDragon_ru\LaraASP\Documentator\Commands; -use LastDragon_ru\LaraASP\Documentator\Preprocessor\Context; -use LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\Instruction; -use LastDragon_ru\LaraASP\Documentator\Preprocessor\Contracts\Parameters; -use LastDragon_ru\LaraASP\Documentator\Preprocessor\Preprocessor; +use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Context; +use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Contracts\Instruction; +use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Contracts\Parameters; +use LastDragon_ru\LaraASP\Documentator\Processor\Tasks\Preprocess\Task; use LastDragon_ru\LaraASP\Documentator\Testing\Package\TestCase; use LastDragon_ru\LaraASP\Serializer\Contracts\Serializable; use Mockery; @@ -18,9 +18,9 @@ #[CoversClass(Preprocess::class)] final class PreprocessTest extends TestCase { public function testGetProcessedHelpInstructions(): void { - $preprocessor = Mockery::mock(Preprocessor::class); - $preprocessor->shouldAllowMockingProtectedMethods(); - $preprocessor + $preprocess = Mockery::mock(Task::class); + $preprocess->shouldAllowMockingProtectedMethods(); + $preprocess ->shouldReceive('getInstructions') ->once() ->andReturn([ @@ -29,7 +29,7 @@ public function testGetProcessedHelpInstructions(): void { PreprocessTest__InstructionNotSerializable::class, ]); - $command = new class($preprocessor) extends Preprocess { + $command = new class($preprocess) extends Preprocess { #[Override] public function getProcessedHelpInstructions(): string { return parent::getProcessedHelpInstructions(); @@ -79,8 +79,8 @@ public function getProcessedHelpInstructions(): string { } public function testGetProcessedHelpInstructionTarget(): void { - $preprocessor = Mockery::mock(Preprocessor::class); - $command = new class($preprocessor) extends Preprocess { + $preprocess = Mockery::mock(Task::class); + $command = new class($preprocess) extends Preprocess { #[Override] public function getProcessedHelpInstructionTarget( string $instruction, @@ -107,8 +107,8 @@ public function getProcessedHelpInstructionTarget( } public function testGetProcessedHelpInstructionParameters(): void { - $preprocessor = Mockery::mock(Preprocessor::class); - $command = new class($preprocessor) extends Preprocess { + $preprocess = Mockery::mock(Task::class); + $command = new class($preprocess) extends Preprocess { #[Override] public function getProcessedHelpInstructionParameters( string $instruction, @@ -138,8 +138,8 @@ public function getProcessedHelpInstructionParameters( } public function testGetProcessedHelpInstructionParametersNoParameters(): void { - $preprocessor = Mockery::mock(Preprocessor::class); - $command = new class($preprocessor) extends Preprocess { + $preprocess = Mockery::mock(Task::class); + $command = new class($preprocess) extends Preprocess { #[Override] public function getProcessedHelpInstructionParameters( string $instruction, @@ -160,8 +160,8 @@ public function getProcessedHelpInstructionParameters( } public function testGetProcessedHelpInstructionParametersNotSerializable(): void { - $preprocessor = Mockery::mock(Preprocessor::class); - $command = new class($preprocessor) extends Preprocess { + $preprocess = Mockery::mock(Task::class); + $command = new class($preprocess) extends Preprocess { #[Override] public function getProcessedHelpInstructionParameters( string $instruction, diff --git a/packages/documentator/src/Preprocessor/Exceptions/PreprocessorError.php b/packages/documentator/src/Preprocessor/Exceptions/PreprocessorError.php deleted file mode 100644 index 66566e9fc..000000000 --- a/packages/documentator/src/Preprocessor/Exceptions/PreprocessorError.php +++ /dev/null @@ -1,9 +0,0 @@ -target, - $context->file->getRelativePath($context->root), - ), - $previous, - ); - } -} diff --git a/packages/documentator/src/Preprocessor/Context.php b/packages/documentator/src/Processor/Tasks/Preprocess/Context.php similarity index 85% rename from packages/documentator/src/Preprocessor/Context.php rename to packages/documentator/src/Processor/Tasks/Preprocess/Context.php index da42cdf20..964455c12 100644 --- a/packages/documentator/src/Preprocessor/Context.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Context.php @@ -1,6 +1,6 @@ ` doesn't support. * * @todo Use https://github.com/thephpleague/commonmark? - * - * @see Preprocess */ -class Preprocessor implements Task { +class Task implements TaskContract { protected const Warning = 'Generated automatically. Do not edit.'; protected const Regexp = <<<'REGEXP' /^ @@ -163,10 +158,10 @@ public function __invoke(Directory $root, File $file): Generator { } $content = trim($content); - } catch (PreprocessorError $exception) { + } catch (ProcessorError $exception) { throw $exception; } catch (Exception $exception) { - throw new PreprocessingFailed($exception); + throw new PreprocessFailed($exception); } foreach ($token->matches as $match => $expression) { @@ -211,6 +206,10 @@ protected function parse(Directory $root, File $file): TokenList { $tokens = []; $matches = []; + if (!$this->instructions) { + return new TokenList($tokens); + } + if (!preg_match_all(static::Regexp, $file->getContent(), $matches, PREG_SET_ORDER | PREG_UNMATCHED_AS_NULL)) { return new TokenList($tokens); } diff --git a/packages/documentator/src/Preprocessor/PreprocessorTest.php b/packages/documentator/src/Processor/Tasks/Preprocess/TaskTest.php similarity index 83% rename from packages/documentator/src/Preprocessor/PreprocessorTest.php rename to packages/documentator/src/Processor/Tasks/Preprocess/TaskTest.php index bbb28add8..0a6665798 100644 --- a/packages/documentator/src/Preprocessor/PreprocessorTest.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/TaskTest.php @@ -1,12 +1,12 @@ shouldAllowMockingProtectedMethods(); - $preprocessor->makePartial(); - $preprocessor + $a = new TaskTest__EmptyInstruction(); + $b = new TaskTest__TestInstruction(); + $task = Mockery::mock(Task::class, MockProperties::class); + $task->shouldAllowMockingProtectedMethods(); + $task->makePartial(); + $task ->shouldUseProperty('container') ->value( $this->app()->make(ContainerResolver::class), ); - $preprocessor + $task ->shouldUseProperty('serializer') ->value( $this->app()->make(Serializer::class), ); - $preprocessor->addInstruction($a::class); - $preprocessor->addInstruction($b); + $task->addInstruction($a::class); + $task->addInstruction($b); $file = Mockery::mock(File::class); $file @@ -82,7 +82,7 @@ public function testParse(): void { ->andReturn(self::MARKDOWN); $root = Mockery::mock(Directory::class); - $tokens = $preprocessor->parse($root, $file); + $tokens = $task->parse($root, $file); self::assertEquals( new TokenList([ @@ -90,7 +90,7 @@ public function testParse(): void { $a, new Context($root, $file, '<./path/to/file "value">', null), './path/to/file "value"', - new PreprocessorTest__ParametersEmpty('./path/to/file "value"'), + new TaskTest__ParametersEmpty('./path/to/file "value"'), [ '[test:empty]: <./path/to/file "value">' => '[test:empty]: <./path/to/file "value">', ], @@ -99,7 +99,7 @@ public function testParse(): void { $b, new Context($root, $file, './path/to/file', null), './path/to/file', - new PreprocessorTest__Parameters('./path/to/file'), + new TaskTest__Parameters('./path/to/file'), [ // phpcs:disable Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned '[test:instruction]: ./path/to/file' => '[test:instruction]: ./path/to/file', @@ -129,7 +129,7 @@ public function testParse(): void { '{"a": "aa", "b": {"a": "a", "b": "b"}}', ), './path/to/file/parametrized', - new PreprocessorTest__Parameters( + new TaskTest__Parameters( './path/to/file/parametrized', 'aa', [ @@ -150,11 +150,11 @@ public function testParse(): void { } public function testInvoke(): void { - $preprocessor = $this->app()->make(Preprocessor::class) - ->addInstruction(new PreprocessorTest__EmptyInstruction()) - ->addInstruction(new PreprocessorTest__TestInstruction()); - $actual = null; - $file = Mockery::mock(File::class); + $task = $this->app()->make(Task::class) + ->addInstruction(new TaskTest__EmptyInstruction()) + ->addInstruction(new TaskTest__TestInstruction()); + $actual = null; + $file = Mockery::mock(File::class); $file ->shouldReceive('getContent') ->atLeast() @@ -172,7 +172,7 @@ static function (string $content) use ($file, &$actual): File { ); $root = Mockery::mock(Directory::class); - $result = ProcessorHelper::runTask($preprocessor, $root, $file); + $result = ProcessorHelper::runTask($task, $root, $file); self::assertTrue($result); self::assertEquals( @@ -247,9 +247,9 @@ static function (string $content) use ($file, &$actual): File { * @internal * @noinspection PhpMultipleClassesDeclarationsInOneFile * - * @implements Instruction + * @implements Instruction */ -class PreprocessorTest__EmptyInstruction implements Instruction { +class TaskTest__EmptyInstruction implements Instruction { #[Override] public static function getName(): string { return 'test:empty'; @@ -257,7 +257,7 @@ public static function getName(): string { #[Override] public static function getParameters(): string { - return PreprocessorTest__ParametersEmpty::class; + return TaskTest__ParametersEmpty::class; } #[Override] @@ -270,9 +270,9 @@ public function __invoke(Context $context, string $target, mixed $parameters): s * @internal * @noinspection PhpMultipleClassesDeclarationsInOneFile * - * @implements Instruction + * @implements Instruction */ -class PreprocessorTest__TestInstruction implements Instruction { +class TaskTest__TestInstruction implements Instruction { #[Override] public static function getName(): string { return 'test:instruction'; @@ -280,7 +280,7 @@ public static function getName(): string { #[Override] public static function getParameters(): string { - return PreprocessorTest__Parameters::class; + return TaskTest__Parameters::class; } #[Override] @@ -293,7 +293,7 @@ public function __invoke(Context $context, string $target, mixed $parameters): s * @internal * @noinspection PhpMultipleClassesDeclarationsInOneFile */ -class PreprocessorTest__Parameters implements Parameters, Serializable { +class TaskTest__Parameters implements Parameters, Serializable { /** * @param array $b */ @@ -310,7 +310,7 @@ public function __construct( * @internal * @noinspection PhpMultipleClassesDeclarationsInOneFile */ -class PreprocessorTest__ParametersEmpty implements Parameters, Serializable { +class TaskTest__ParametersEmpty implements Parameters, Serializable { public function __construct( public readonly string $target, ) { diff --git a/packages/documentator/src/Preprocessor/Token.php b/packages/documentator/src/Processor/Tasks/Preprocess/Token.php similarity index 69% rename from packages/documentator/src/Preprocessor/Token.php rename to packages/documentator/src/Processor/Tasks/Preprocess/Token.php index ac5ac136d..151c24678 100644 --- a/packages/documentator/src/Preprocessor/Token.php +++ b/packages/documentator/src/Processor/Tasks/Preprocess/Token.php @@ -1,9 +1,9 @@ |null $usedTypes diff --git a/packages/graphql/docs/Assertions/AssertGraphQLIntrospectionEquals.md b/packages/graphql/docs/Assertions/AssertGraphQLIntrospectionEquals.md index 4fb32d16c..b497fc8ef 100644 --- a/packages/graphql/docs/Assertions/AssertGraphQLIntrospectionEquals.md +++ b/packages/graphql/docs/Assertions/AssertGraphQLIntrospectionEquals.md @@ -27,8 +27,6 @@ use PHPUnit\Framework\Attributes\CoversNothing; use function array_merge; -// @phpcs:disable Generic.Files.LineLength.TooLong - /** * @internal */ diff --git a/packages/graphql/docs/Assertions/AssertGraphQLIntrospectionEqualsTest.php b/packages/graphql/docs/Assertions/AssertGraphQLIntrospectionEqualsTest.php index b2608e992..2589d6fbb 100644 --- a/packages/graphql/docs/Assertions/AssertGraphQLIntrospectionEqualsTest.php +++ b/packages/graphql/docs/Assertions/AssertGraphQLIntrospectionEqualsTest.php @@ -15,8 +15,6 @@ use function array_merge; -// @phpcs:disable Generic.Files.LineLength.TooLong - /** * @internal */ diff --git a/packages/graphql/src/Builder/BuilderInfoDetectorTest.php b/packages/graphql/src/Builder/BuilderInfoDetectorTest.php index e0c1d7928..abe8d4b39 100644 --- a/packages/graphql/src/Builder/BuilderInfoDetectorTest.php +++ b/packages/graphql/src/Builder/BuilderInfoDetectorTest.php @@ -39,8 +39,6 @@ use const JSON_THROW_ON_ERROR; -// @phpcs:disable Generic.Files.LineLength.TooLong - /** * @internal */ diff --git a/packages/graphql/src/Builder/Contracts/BuilderInfoProvider.php b/packages/graphql/src/Builder/Contracts/BuilderInfoProvider.php index 87388ef28..78e08b02a 100644 --- a/packages/graphql/src/Builder/Contracts/BuilderInfoProvider.php +++ b/packages/graphql/src/Builder/Contracts/BuilderInfoProvider.php @@ -5,8 +5,6 @@ use LastDragon_ru\LaraASP\GraphQL\Builder\BuilderInfo; use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\BuilderUnknown; -// @phpcs:disable Generic.Files.LineLength.TooLong - /** * Can be used with a directive to define the builder type in case when * auto-detection doesn't work. diff --git a/packages/graphql/src/Printer/PrinterTest.php b/packages/graphql/src/Printer/PrinterTest.php index 06f4e150a..d5f699095 100644 --- a/packages/graphql/src/Printer/PrinterTest.php +++ b/packages/graphql/src/Printer/PrinterTest.php @@ -38,8 +38,6 @@ use function in_array; use function str_starts_with; -// @phpcs:disable Generic.Files.LineLength.TooLong - /** * @internal */ diff --git a/packages/graphql/src/Testing/GraphQLAssertions.php b/packages/graphql/src/Testing/GraphQLAssertions.php index 8f45030b5..79c21b1e1 100644 --- a/packages/graphql/src/Testing/GraphQLAssertions.php +++ b/packages/graphql/src/Testing/GraphQLAssertions.php @@ -38,8 +38,6 @@ use function ksort; use function trim; -// @phpcs:disable Generic.Files.LineLength.TooLong - /** * @phpstan-import-type Change from BreakingChangesFinder * diff --git a/packages/graphql/src/Utils/AstManipulator.php b/packages/graphql/src/Utils/AstManipulator.php index e680726a1..71c451b6a 100644 --- a/packages/graphql/src/Utils/AstManipulator.php +++ b/packages/graphql/src/Utils/AstManipulator.php @@ -73,8 +73,6 @@ use const JSON_THROW_ON_ERROR; -// @phpcs:disable Generic.Files.LineLength.TooLong - class AstManipulator { public const Placeholder = '_'; diff --git a/packages/graphql/src/Utils/AstManipulatorTest.php b/packages/graphql/src/Utils/AstManipulatorTest.php index 6c7205455..3eb6add38 100644 --- a/packages/graphql/src/Utils/AstManipulatorTest.php +++ b/packages/graphql/src/Utils/AstManipulatorTest.php @@ -47,8 +47,6 @@ use function assert; use function is_string; -// @phpcs:disable Generic.Files.LineLength.TooLong - /** * @internal */ diff --git a/packages/testing/src/Assertions/DatabaseAssertions.php b/packages/testing/src/Assertions/DatabaseAssertions.php index 9e179c09e..36eab5204 100644 --- a/packages/testing/src/Assertions/DatabaseAssertions.php +++ b/packages/testing/src/Assertions/DatabaseAssertions.php @@ -9,8 +9,6 @@ use LastDragon_ru\LaraASP\Testing\Utils\Args; use PHPUnit\Framework\Assert; -// @phpcs:disable Generic.Files.LineLength.TooLong - /** * @mixin Assert */ diff --git a/packages/testing/src/Concerns/Override.php b/packages/testing/src/Concerns/Override.php index 1c1e8edaa..03a858b72 100644 --- a/packages/testing/src/Concerns/Override.php +++ b/packages/testing/src/Concerns/Override.php @@ -18,8 +18,6 @@ use function is_string; use function sprintf; -// @phpcs:disable Generic.Files.LineLength.TooLong - /** * Similar to {@see InteractsWithContainer} but will mark test as failed if * override was not used while test (that helps to find unused code). diff --git a/phpcs.xml b/phpcs.xml index 4d39b8292..1a270ae88 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -26,8 +26,11 @@ - + + + + diff --git a/phpstan-baseline-well-known.neon b/phpstan-baseline-well-known.neon index 063ca083f..6c273fdd9 100644 --- a/phpstan-baseline-well-known.neon +++ b/phpstan-baseline-well-known.neon @@ -34,7 +34,7 @@ parameters: - message: "#Calling putenv\\(\\) is forbidden, might overwrite existing variables\\.#" paths: - - packages/documentator/src/Preprocessor/Instructions/IncludeArtisan/Instruction.php + - packages/documentator/src/Processor/Tasks/Preprocess/Instructions/IncludeArtisan/Instruction.php # False positive # https://github.com/phpstan/phpstan/issues/5551