Skip to content

Commit

Permalink
added five new generic remove filters (#1)
Browse files Browse the repository at this point in the history
* 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
davidmondok and wolfgangschaefer authored Feb 23, 2021
1 parent 0ec6a63 commit 3c2cbd3
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 24 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
7 changes: 0 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,11 @@
"Woda\\Test\\Unit\\String\\": "tests/unit"
}
},
"repositories": [
{
"type": "composer",
"url": "https://pack.eventjet.at/"
}
],
"minimum-stability": "stable",
"scripts": {
"check": [
"@check-deps",
"@cs-check",
"@psalm",
"@phpstan",
"@phpunit",
"@infection"
Expand Down
19 changes: 19 additions & 0 deletions src/StringFilter/RemoveDanglingColon.php
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 src/StringFilter/RemoveDoubleAngleBracketsStringFilter.php
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 src/StringFilter/RemoveDoubleCurlyBracketsStringFilter.php
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 src/StringFilter/RemoveDoubleRoundBracketsStringFilter.php
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 src/StringFilter/RemoveDoubleSquareBracketsStringFilter.php
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
);
}
}
18 changes: 18 additions & 0 deletions tests/unit/StringFilter/RemoveDanglingColonTest.php
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:'));
}
}
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>>'));
}
}
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}}'));
}
}
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))'));
}
}
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]]'));
}
}
1 change: 1 addition & 0 deletions tests/unit/StringGenerator/ListStringGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function testGenerateThrowsExceptionWhenListIsEmpty(): void

(new ListStringGenerator([]))->generate();
}

public function testGeneratesCodesFromList(): void
{
$generator = new ListStringGenerator(['foo', 'bar']);
Expand Down

0 comments on commit 3c2cbd3

Please sign in to comment.