Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .molireali
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
authors
composer PetrKnap\\FilterCommand
composer PetrKnap\\ExternalFilter
dockerfile php 8.2-cli
docker-scripts petrknap/php-filter-command
docker-scripts petrknap/php-external-filter
donation
github-templates
github-workflow docker "composer ci-script"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ Its primary role is to **facilitate filtering operations within a pipeline**,
allowing for easy chaining and execution of executable filters.

```php
namespace PetrKnap\FilterCommand;
namespace PetrKnap\ExternalFilter;

# echo '<?php echo "Hello!";' | php
$data = (new FilterCommand('php'))->filter('<?php echo "Hello!";');
$data = (new Filter('php'))->filter('<?php echo "Hello!";');

echo $data;
```

---

Run `composer require petrknap/filter-command` to install it.
Run `composer require petrknap/external-filter` to install it.
You can [support this project via donation](https://petrknap.github.io/donate.html).
The project is licensed under [the terms of the `LGPL-3.0-or-later`](./COPYING.LESSER).
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"WARNING": "This file is updated automatically. All keys will be overwritten, except of 'conflict', 'keywords', 'require', 'require-dev', 'scripts' and 'suggest'.",
"autoload": {
"psr-4": {
"PetrKnap\\FilterCommand\\": "src"
"PetrKnap\\ExternalFilter\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"PetrKnap\\FilterCommand\\": "tests"
"PetrKnap\\ExternalFilter\\": "tests"
}
},
"config": {
Expand All @@ -21,17 +21,17 @@
"url": "https://petrknap.github.io/donate.html"
}
],
"homepage": "https://github.com/petrknap/php-filter-command",
"homepage": "https://github.com/petrknap/php-external-filter",
"keywords": [],
"license": "LGPL-3.0-or-later",
"name": "petrknap/filter-command",
"name": "petrknap/external-filter",
"require": {
"php": ">=8.1",
"petrknap/shorts": "^2.0|^3.0",
"symfony/process": "^4.0|^5.0|^6.0|^7.0"
},
"require-dev": {
"nunomaduro/phpinsights": "^2.11",
"petrknap/shorts": "^3.0",
"phpstan/phpstan": "^1.12",
"squizlabs/php_codesniffer": "^3.7",
"phpunit/phpunit": "^10.5"
Expand Down
14 changes: 0 additions & 14 deletions src/Exception/CouldNotFilterData.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Exception/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PetrKnap\FilterCommand\Exception;
namespace PetrKnap\ExternalFilter\Exception;

use Throwable;

Expand Down
9 changes: 9 additions & 0 deletions src/Exception/FilterException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace PetrKnap\ExternalFilter\Exception;

interface FilterException extends Exception
{
}
12 changes: 6 additions & 6 deletions src/FilterCommand.php → src/Filter.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

Check notice on line 1 in src/Filter.php

View workflow job for this annotation

GitHub Actions / run

* [Class definition] @@ -33,3 +33,3 @@ if (!$process->isSuccessful()) { - throw new class ($process) extends ProcessFailedException implements Exception\FilterException { + throw new class($process) extends ProcessFailedException implements Exception\FilterException { };

declare(strict_types=1);

namespace PetrKnap\FilterCommand;
namespace PetrKnap\ExternalFilter;

use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

final class FilterCommand
final class Filter
{
/**
* @param non-empty-string $command
Expand All @@ -20,18 +20,18 @@
}

/**
* @throws Exception\CouldNotFilterData
* @throws Exception\FilterException
*/
public function filter(string $data): string
public function filter(string $input): string
{
$process = new Process([
$this->command,
...$this->options,
]);
$process->setInput($data);
$process->setInput($input);
$process->run();
if (!$process->isSuccessful()) {

Check notice on line 33 in src/Filter.php

View workflow job for this annotation

GitHub Actions / run

* [Space after not] Expected 1 space(s) after NOT operator; 0 found
throw new class (__METHOD__, $data, new ProcessFailedException($process)) extends Exception\CouldNotFilterData {
throw new class ($process) extends ProcessFailedException implements Exception\FilterException {

Check notice on line 34 in src/Filter.php

View workflow job for this annotation

GitHub Actions / run

* [Line length] Line exceeds maximum limit of 100 characters; contains 108 characters
};
}
return $process->getOutput();
Expand Down
12 changes: 6 additions & 6 deletions tests/FilterCommandTest.php → tests/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

declare(strict_types=1);

namespace PetrKnap\FilterCommand;
namespace PetrKnap\ExternalFilter;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class FilterCommandTest extends TestCase
final class FilterTest extends TestCase
{
public function testFiltersInputByCommand(): void
public function testFilters(): void
{
self::assertSame(
'test',
(new FilterCommand('php'))->filter('<?php echo "test";'),
(new Filter('php'))->filter('<?php echo "test";'),
);
}

#[DataProvider('dataThrows')]
public function testThrows(string $command, array $options, string $data): void

Check notice on line 21 in tests/FilterTest.php

View workflow job for this annotation

GitHub Actions / run

* [Parameter type hint] Method \PetrKnap\ExternalFilter\FilterTest::testThrows() does not have @param annotation for its traversable parameter $options. * [Line length] Line exceeds 80 characters; contains 83 characters
{
self::expectException(Exception\CouldNotFilterData::class);
self::expectException(Exception\FilterException::class);

(new FilterCommand($command, $options))->filter($data);
(new Filter($command, $options))->filter($data);
}

public static function dataThrows(): array

Check notice on line 28 in tests/FilterTest.php

View workflow job for this annotation

GitHub Actions / run

* [Return type hint] Method \PetrKnap\ExternalFilter\FilterTest::dataThrows() does not have @return annotation for its traversable return value.
{
return [
'unknown command' => ['unknown', [], ''],
Expand Down
2 changes: 1 addition & 1 deletion tests/ReadmeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PetrKnap\FilterCommand;
namespace PetrKnap\ExternalFilter;

use PetrKnap\Shorts\PhpUnit\MarkdownFileTestInterface;
use PetrKnap\Shorts\PhpUnit\MarkdownFileTestTrait;
Expand All @@ -17,7 +17,7 @@
return __DIR__ . '/../README.md';
}

public static function getExpectedOutputsOfPhpExamples(): iterable

Check notice on line 20 in tests/ReadmeTest.php

View workflow job for this annotation

GitHub Actions / run

* [Return type hint] Method \PetrKnap\ExternalFilter\ReadmeTest::getExpectedOutputsOfPhpExamples() does not have @return annotation for its traversable return value.
{
return [
'example' => 'Hello!',
Expand Down
Loading