Skip to content

Commit 978a6b1

Browse files
authored
Merge pull request #3 from petrknap/refactored
`FilterCommand` refactored to (external) `Filter`
2 parents 5e2784d + 1511776 commit 978a6b1

File tree

9 files changed

+33
-38
lines changed

9 files changed

+33
-38
lines changed

.molireali

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
authors
2-
composer PetrKnap\\FilterCommand
2+
composer PetrKnap\\ExternalFilter
33
dockerfile php 8.2-cli
4-
docker-scripts petrknap/php-filter-command
4+
docker-scripts petrknap/php-external-filter
55
donation
66
github-templates
77
github-workflow docker "composer ci-script"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ Its primary role is to **facilitate filtering operations within a pipeline**,
55
allowing for easy chaining and execution of executable filters.
66

77
```php
8-
namespace PetrKnap\FilterCommand;
8+
namespace PetrKnap\ExternalFilter;
99

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

1313
echo $data;
1414
```
1515

1616
---
1717

18-
Run `composer require petrknap/filter-command` to install it.
18+
Run `composer require petrknap/external-filter` to install it.
1919
You can [support this project via donation](https://petrknap.github.io/donate.html).
2020
The project is licensed under [the terms of the `LGPL-3.0-or-later`](./COPYING.LESSER).

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"WARNING": "This file is updated automatically. All keys will be overwritten, except of 'conflict', 'keywords', 'require', 'require-dev', 'scripts' and 'suggest'.",
33
"autoload": {
44
"psr-4": {
5-
"PetrKnap\\FilterCommand\\": "src"
5+
"PetrKnap\\ExternalFilter\\": "src"
66
}
77
},
88
"autoload-dev": {
99
"psr-4": {
10-
"PetrKnap\\FilterCommand\\": "tests"
10+
"PetrKnap\\ExternalFilter\\": "tests"
1111
}
1212
},
1313
"config": {
@@ -21,17 +21,17 @@
2121
"url": "https://petrknap.github.io/donate.html"
2222
}
2323
],
24-
"homepage": "https://github.com/petrknap/php-filter-command",
24+
"homepage": "https://github.com/petrknap/php-external-filter",
2525
"keywords": [],
2626
"license": "LGPL-3.0-or-later",
27-
"name": "petrknap/filter-command",
27+
"name": "petrknap/external-filter",
2828
"require": {
2929
"php": ">=8.1",
30-
"petrknap/shorts": "^2.0|^3.0",
3130
"symfony/process": "^4.0|^5.0|^6.0|^7.0"
3231
},
3332
"require-dev": {
3433
"nunomaduro/phpinsights": "^2.11",
34+
"petrknap/shorts": "^3.0",
3535
"phpstan/phpstan": "^1.12",
3636
"squizlabs/php_codesniffer": "^3.7",
3737
"phpunit/phpunit": "^10.5"

src/Exception/CouldNotFilterData.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Exception/Exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace PetrKnap\FilterCommand\Exception;
5+
namespace PetrKnap\ExternalFilter\Exception;
66

77
use Throwable;
88

src/Exception/FilterException.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PetrKnap\ExternalFilter\Exception;
6+
7+
interface FilterException extends Exception
8+
{
9+
}

src/FilterCommand.php renamed to src/Filter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace PetrKnap\FilterCommand;
5+
namespace PetrKnap\ExternalFilter;
66

77
use Symfony\Component\Process\Exception\ProcessFailedException;
88
use Symfony\Component\Process\Process;
99

10-
final class FilterCommand
10+
final class Filter
1111
{
1212
/**
1313
* @param non-empty-string $command
@@ -20,18 +20,18 @@ public function __construct(
2020
}
2121

2222
/**
23-
* @throws Exception\CouldNotFilterData
23+
* @throws Exception\FilterException
2424
*/
25-
public function filter(string $data): string
25+
public function filter(string $input): string
2626
{
2727
$process = new Process([
2828
$this->command,
2929
...$this->options,
3030
]);
31-
$process->setInput($data);
31+
$process->setInput($input);
3232
$process->run();
3333
if (!$process->isSuccessful()) {
34-
throw new class (__METHOD__, $data, new ProcessFailedException($process)) extends Exception\CouldNotFilterData {
34+
throw new class ($process) extends ProcessFailedException implements Exception\FilterException {
3535
};
3636
}
3737
return $process->getOutput();

tests/FilterCommandTest.php renamed to tests/FilterTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
declare(strict_types=1);
44

5-
namespace PetrKnap\FilterCommand;
5+
namespace PetrKnap\ExternalFilter;
66

77
use PHPUnit\Framework\Attributes\DataProvider;
88
use PHPUnit\Framework\TestCase;
99

10-
final class FilterCommandTest extends TestCase
10+
final class FilterTest extends TestCase
1111
{
12-
public function testFiltersInputByCommand(): void
12+
public function testFilters(): void
1313
{
1414
self::assertSame(
1515
'test',
16-
(new FilterCommand('php'))->filter('<?php echo "test";'),
16+
(new Filter('php'))->filter('<?php echo "test";'),
1717
);
1818
}
1919

2020
#[DataProvider('dataThrows')]
2121
public function testThrows(string $command, array $options, string $data): void
2222
{
23-
self::expectException(Exception\CouldNotFilterData::class);
23+
self::expectException(Exception\FilterException::class);
2424

25-
(new FilterCommand($command, $options))->filter($data);
25+
(new Filter($command, $options))->filter($data);
2626
}
2727

2828
public static function dataThrows(): array

tests/ReadmeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace PetrKnap\FilterCommand;
5+
namespace PetrKnap\ExternalFilter;
66

77
use PetrKnap\Shorts\PhpUnit\MarkdownFileTestInterface;
88
use PetrKnap\Shorts\PhpUnit\MarkdownFileTestTrait;

0 commit comments

Comments
 (0)