Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Filter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check notice on line 1 in src/Filter.php

View workflow job for this annotation

GitHub Actions / run

* [Having `classes` with more than 5 cyclomatic complexity is prohibited - Consider refactoring] 10 cyclomatic complexity * [Class definition] @@ -99,3 +99,3 @@ if (!$finishedProcess->isSuccessful()) { - throw new class ($finishedProcess) extends ProcessFailedException implements Exception\FilterException { + throw new class($finishedProcess) extends ProcessFailedException implements Exception\FilterException { };

declare(strict_types=1);

Expand All @@ -8,7 +8,7 @@
use Symfony\Component\Process\Process;

/**
* @todo make it abstract and remove extends

Check notice on line 11 in src/Filter.php

View workflow job for this annotation

GitHub Actions / run

* [Todo] Comment refers to a TODO task
*/
final class Filter extends PipelinableFilter
{
Expand All @@ -28,15 +28,15 @@
* @param non-empty-string $command
* @param array<non-empty-string>|null $options
*/
public static function new(string $command, array|null $options = null): PipelinableFilter

Check notice on line 31 in src/Filter.php

View workflow job for this annotation

GitHub Actions / run

* [Line length] Line exceeds 80 characters; contains 94 characters
{
return new Filter($command, $options);
}

/**
* @todo move it to {@see ExternalFilter}

Check notice on line 37 in src/Filter.php

View workflow job for this annotation

GitHub Actions / run

* [Todo] Comment refers to a TODO task
*/
public function filter(mixed $input, mixed $output = null, mixed $error = null): string|null

Check notice on line 39 in src/Filter.php

View workflow job for this annotation

GitHub Actions / run

* [Function length] Your function is too long. Currently using 23 lines. Can be up to 20 lines. * [Line length] Line exceeds 80 characters; contains 96 characters
{
self::checkFilterArguments(
input: $input,
Expand Down Expand Up @@ -67,7 +67,7 @@
}

/**
* @todo move it to {@see ExternalFilter}

Check notice on line 70 in src/Filter.php

View workflow job for this annotation

GitHub Actions / run

* [Todo] Comment refers to a TODO task
*/
protected function clone(): static
{
Expand All @@ -75,12 +75,12 @@
}

/**
* @todo move it to {@see ExternalFilter}

Check notice on line 78 in src/Filter.php

View workflow job for this annotation

GitHub Actions / run

* [Todo] Comment refers to a TODO task
*
* @param resource|null $output
* @param resource|null $error
*/
private static function buildProcessCallback(mixed $output, mixed $error): callable

Check notice on line 83 in src/Filter.php

View workflow job for this annotation

GitHub Actions / run

* [Line length] Line exceeds 80 characters; contains 87 characters
{
return static function (string $type, string $data) use ($output, $error): void {
/** @var Process::OUT|Process::ERR $type */
Expand All @@ -92,7 +92,7 @@
}

/**
* @todo move it to {@see ExternalFilter}

Check notice on line 95 in src/Filter.php

View workflow job for this annotation

GitHub Actions / run

* [Todo] Comment refers to a TODO task
*/
private static function checkFinishedProcess(Process $finishedProcess): void
{
Expand All @@ -103,7 +103,7 @@
}

/**
* @todo move it to {@see ExternalFilter}

Check notice on line 106 in src/Filter.php

View workflow job for this annotation

GitHub Actions / run

* [Todo] Comment refers to a TODO task
*
* @param non-empty-array<PipelinableFilter> $pipeline
*
Expand All @@ -112,16 +112,20 @@
private static function transformPipeline(array $pipeline): array
{
$transformedPipeline = [];
$shellCommandLine = null;
foreach ($pipeline as $filter) {
if ($filter instanceof self) {
$transformedPipeline[] = new Process([
$shellCommandLine = ($shellCommandLine === null ? '' : "{$shellCommandLine} | ") . (new Process([
$filter->command,
...($filter->options ?? []),
]);
]))->getCommandLine();
} else {
throw new \BadMethodCallException('$pipeline contains unsupported filter');
}
}
if ($shellCommandLine !== null) {
$transformedPipeline[] = Process::fromShellCommandline($shellCommandLine);
}
return $transformedPipeline;
}
}
Loading