Skip to content

Commit 4cb4adf

Browse files
committed
Added Trim strategy.
1 parent a006681 commit 4cb4adf

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
notifications:
22
email: false
33

4-
sudo: false
5-
64
language: php
75

86
php:

src/Strategy/Delegate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public function __invoke($data, $context = null)
2626

2727
protected function delegate($strategy, $data, $context, $key = null)
2828
{
29-
return $this->mapper->map($data, $strategy, $context, $key !== null ? $key : $this->key);
29+
return $this->mapper->map($data, $strategy, $context, $key ?? $this->key);
3030
}
3131
}

src/Strategy/Trim.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ScriptFUSION\Mapper\Strategy;
5+
6+
class Trim extends Delegate
7+
{
8+
public function __invoke($data, $context = null)
9+
{
10+
return trim(parent::__invoke($data, $context));
11+
}
12+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ScriptFUSIONTest\Integration\Mapper\Strategy;
5+
6+
use ScriptFUSION\Mapper\Mapper;
7+
use ScriptFUSION\Mapper\Strategy\Trim;
8+
use PHPUnit\Framework\TestCase;
9+
10+
/**
11+
* @see Trim
12+
*/
13+
final class TrimTest extends TestCase
14+
{
15+
public function test(): void
16+
{
17+
$trim = (new Trim(' foo '))->setMapper(new Mapper());
18+
19+
self::assertSame('foo', $trim([]));
20+
}
21+
}

0 commit comments

Comments
 (0)