-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added five new generic remove filters (#1)
* Added five new generic remove filters * Added tests * Remove psalm (false positives psalm errors) * Update github workflow * Update github workflow Co-authored-by: Wolfgang Schaefer <[email protected]>
- Loading branch information
1 parent
0ec6a63
commit 3c2cbd3
Showing
13 changed files
with
223 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,42 +6,42 @@ jobs: | |
build: | ||
|
||
runs-on: ubuntu-latest | ||
container: | ||
image: eventjet/checks-7.4:latest | ||
|
||
strategy: | ||
matrix: | ||
php: [ '7.4' ] | ||
|
||
name: PHP ${{ matrix.php }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: SSH agent | ||
uses: webfactory/[email protected] | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
php-version: ${{ matrix.php }} | ||
|
||
- name: Prepare environment | ||
run: | | ||
composer config http-basic.pack.eventjet.at ${{ secrets.SATIS_USER }} ${{ secrets.SATIS_PASSWORD }} | ||
mkdir -p /root/.ssh | ||
ssh-keyscan -t rsa github.com >> /root/.ssh/known_hosts | ||
- name: Get Composer cache directory | ||
id: composer-cache | ||
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
|
||
- name: Composer Cache | ||
- name: Cache Composer dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: $(composer config cache-files-dir) | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-composer- | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
|
||
- name: Install dependencies | ||
run: | | ||
composer install --no-progress --no-suggest --no-interaction > /dev/null | ||
composer install --prefer-dist --no-progress --no-suggest --no-interaction > /dev/null | ||
- name: Static analysis | ||
run: | | ||
composer check-deps | ||
composer cs-check | ||
composer phpstan -- --no-progress | ||
composer psalm | ||
- name: Tests | ||
run: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Woda\String\StringFilter; | ||
|
||
use function Safe\preg_replace; | ||
|
||
final class RemoveDanglingColon implements StringFilterInterface | ||
{ | ||
public function __invoke(string $string): string | ||
{ | ||
return preg_replace( | ||
'/:$/', | ||
'', | ||
$string | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/StringFilter/RemoveDoubleAngleBracketsStringFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Woda\String\StringFilter; | ||
|
||
use function Safe\preg_replace; | ||
|
||
final class RemoveDoubleAngleBracketsStringFilter implements StringFilterInterface | ||
{ | ||
public function __invoke(string $string): string | ||
{ | ||
return preg_replace( | ||
'/[<]{2}([^>]*)[>]{2}/', | ||
'$1', | ||
$string | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/StringFilter/RemoveDoubleCurlyBracketsStringFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Woda\String\StringFilter; | ||
|
||
use function Safe\preg_replace; | ||
|
||
final class RemoveDoubleCurlyBracketsStringFilter implements StringFilterInterface | ||
{ | ||
public function __invoke(string $string): string | ||
{ | ||
return preg_replace( | ||
'/[{]{2}([^}]*)[}]{2}/', | ||
'$1', | ||
$string | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/StringFilter/RemoveDoubleRoundBracketsStringFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Woda\String\StringFilter; | ||
|
||
use function Safe\preg_replace; | ||
|
||
final class RemoveDoubleRoundBracketsStringFilter implements StringFilterInterface | ||
{ | ||
public function __invoke(string $string): string | ||
{ | ||
return preg_replace( | ||
'/[(]{2}([^}]*)[)]{2}/', | ||
'$1', | ||
$string | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/StringFilter/RemoveDoubleSquareBracketsStringFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Woda\String\StringFilter; | ||
|
||
use function Safe\preg_replace; | ||
|
||
final class RemoveDoubleSquareBracketsStringFilter implements StringFilterInterface | ||
{ | ||
public function __invoke(string $string): string | ||
{ | ||
return preg_replace( | ||
'/[\[]{2}([^]]*)[\]]{2}/', | ||
'$1', | ||
$string | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Woda\Test\Unit\String\StringFilter; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Woda\String\StringFilter\RemoveDanglingColon; | ||
|
||
final class RemoveDanglingColonTest extends TestCase | ||
{ | ||
public function testName(): void | ||
{ | ||
$filter = new RemoveDanglingColon(); | ||
|
||
self::assertSame('foo', ($filter)('foo:')); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/unit/StringFilter/RemoveDoubleAngleBracketsStringFilterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Woda\Test\Unit\String\StringFilter; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Woda\String\StringFilter\RemoveDoubleAngleBracketsStringFilter; | ||
|
||
final class RemoveDoubleAngleBracketsStringFilterTest extends TestCase | ||
{ | ||
public function testName(): void | ||
{ | ||
$filter = new RemoveDoubleAngleBracketsStringFilter(); | ||
|
||
self::assertSame('<foo>', ($filter)('<foo>')); | ||
self::assertSame('foo', ($filter)('<<foo>>')); | ||
self::assertSame('<<foo', ($filter)('<<foo')); | ||
self::assertSame('foo>>', ($filter)('foo>>')); | ||
self::assertSame('<<foo>', ($filter)('<<foo>')); | ||
self::assertSame('<foo>>', ($filter)('<foo>>')); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/unit/StringFilter/RemoveDoubleCurlyBracketsStringFilterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Woda\Test\Unit\String\StringFilter; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Woda\String\StringFilter\RemoveDoubleCurlyBracketsStringFilter; | ||
|
||
final class RemoveDoubleCurlyBracketsStringFilterTest extends TestCase | ||
{ | ||
public function testName(): void | ||
{ | ||
$filter = new RemoveDoubleCurlyBracketsStringFilter(); | ||
|
||
self::assertSame('{foo}', ($filter)('{foo}')); | ||
self::assertSame('foo', ($filter)('{{foo}}')); | ||
self::assertSame('{{foo', ($filter)('{{foo')); | ||
self::assertSame('foo}}', ($filter)('foo}}')); | ||
self::assertSame('{{foo}', ($filter)('{{foo}')); | ||
self::assertSame('{foo}}', ($filter)('{foo}}')); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/unit/StringFilter/RemoveDoubleRoundBracketsStringFilterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Woda\Test\Unit\String\StringFilter; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Woda\String\StringFilter\RemoveDoubleRoundBracketsStringFilter; | ||
|
||
final class RemoveDoubleRoundBracketsStringFilterTest extends TestCase | ||
{ | ||
public function testName(): void | ||
{ | ||
$filter = new RemoveDoubleRoundBracketsStringFilter(); | ||
|
||
self::assertSame('(foo)', ($filter)('(foo)')); | ||
self::assertSame('foo', ($filter)('((foo))')); | ||
self::assertSame('((foo', ($filter)('((foo')); | ||
self::assertSame('foo))', ($filter)('foo))')); | ||
self::assertSame('((foo)', ($filter)('((foo)')); | ||
self::assertSame('(foo))', ($filter)('(foo))')); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/unit/StringFilter/RemoveDoubleSquareBracketsStringFilterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Woda\Test\Unit\String\StringFilter; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Woda\String\StringFilter\RemoveDoubleSquareBracketsStringFilter; | ||
|
||
final class RemoveDoubleSquareBracketsStringFilterTest extends TestCase | ||
{ | ||
public function testName(): void | ||
{ | ||
$filter = new RemoveDoubleSquareBracketsStringFilter(); | ||
|
||
self::assertSame('[foo]', ($filter)('[foo]')); | ||
self::assertSame('foo', ($filter)('[[foo]]')); | ||
self::assertSame('[[foo', ($filter)('[[foo')); | ||
self::assertSame('foo]]', ($filter)('foo]]')); | ||
self::assertSame('[[foo]', ($filter)('[[foo]')); | ||
self::assertSame('[foo]]', ($filter)('[foo]]')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters