Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: helper::Text::superTrim #130

Merged
merged 2 commits into from
Nov 25, 2022
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
11 changes: 11 additions & 0 deletions EMS/helpers/src/Standard/Text.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace EMS\Helpers\Standard;

class Text
{
public static function superTrim(string $content): string
{
return \trim(\preg_replace('!\s+!', ' ', $content) ?? '');
}
}
21 changes: 21 additions & 0 deletions EMS/helpers/tests/Unit/Standard/TextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace EMS\Helpers\Tests\Unit\Standard;

use EMS\Helpers\Standard\Text;
use PHPUnit\Framework\TestCase;

class TextTest extends TestCase
{
public function testFoobar()
{
self::assertEquals('foo bar', Text::superTrim("\n\r
foo \t\t

bar

"));
}
}
3 changes: 2 additions & 1 deletion elasticms-cli/src/Helper/AsyncResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Helper;

use EMS\Helpers\Standard\Json;
use EMS\Helpers\Standard\Text;
use GuzzleHttp\Promise\PromiseInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
Expand All @@ -21,7 +22,7 @@ public function __construct(PromiseInterface $promise, bool $trimWhiteSpaces = t

public function getContent(): string
{
return $this->trimWhiteSpaces ? TextHelper::trim($this->getResponse()->getBody()->getContents()) : $this->getResponse()->getBody()->getContents();
return $this->trimWhiteSpaces ? Text::superTrim($this->getResponse()->getBody()->getContents()) : $this->getResponse()->getBody()->getContents();
}

public function getStream(): StreamInterface
Expand Down
5 changes: 5 additions & 0 deletions elasticms-cli/src/Helper/TextHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

class TextHelper
{
/**
* @deprecated TextHelper::trim is now deprecated, use EMS\Helpers\Standard\Text::superTrim
*/
public static function trim(string $content): string
{
\trigger_error('TextHelper::trim is now deprecated, use EMS\Helpers\Standard\Text::superTrim', E_USER_DEPRECATED);

return \trim(\preg_replace('!\s+!', ' ', $content) ?? '');
}
}
3 changes: 2 additions & 1 deletion elasticms-cli/src/Helper/TikaWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Helper;

use EMS\Helpers\Standard\Text;
use Psr\Http\Message\StreamInterface;

class TikaWrapper extends ProcessWrapper
Expand Down Expand Up @@ -56,7 +57,7 @@ public static function getDocumentType(StreamInterface $stream, string $cacheFol
public function getOutput(): string
{
if ($this->trimWhiteSpaces) {
return TextHelper::trim(parent::getOutput());
return Text::superTrim(parent::getOutput());
}

return parent::getOutput();
Expand Down