for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace PhpSpellCheck;
use PhpSpellCheck\Exception\InvalidArgumentException;
use PhpSpellCheck\Utils\TextEncoding;
class Text implements TextInterface
{
/**
* @var string
*/
private $content;
private $encoding;
* @var array
private $context;
public function __construct(string $content, string $encoding, array $context = [])
$this->content = $content;
$this->encoding = $encoding;
$this->context = $context;
}
public function getContent(): string
return $this->content;
public function getEncoding(): string
return $this->encoding;
public function getContext(): array
return $this->context;
public function replaceContent(string $newContent): TextInterface
return new self($newContent, $this->encoding, $this->context);
public function mergeContext(array $context, bool $override = true): TextInterface
if (empty($context)) {
throw new InvalidArgumentException('Context trying to be merged is empty');
return new self(
$this->getContent(),
$this->getEncoding(),
$override ? array_merge($this->getContext(), $context) : array_merge($context, $this->getContext())
);
public static function utf8(string $text, array $context = [])
return new self($text, TextEncoding::UTF8, $context);
public function __toString()
return $this->getContent();