rector/vendor/symplify/rule-doc-generator-contracts/src/ValueObject/AbstractCodeSample.php
Tomas Votruba 1e09b81ddb Updated Rector to commit e68c8d23cbbdb9dbfef66133af6bb4f1857015ad
e68c8d23cb Fix CallableTypeParameterNode and IdentifierTypeParameterNode crash (#3353)
2023-02-07 12:26:09 +00:00

46 lines
1.3 KiB
PHP

<?php
declare (strict_types=1);
namespace Symplify\RuleDocGenerator\ValueObject;
use Symplify\RuleDocGenerator\Contract\CodeSampleInterface;
use Symplify\RuleDocGenerator\Exception\ShouldNotHappenException;
abstract class AbstractCodeSample implements CodeSampleInterface
{
/**
* @var non-empty-string
* @readonly
*/
private $goodCode;
/**
* @var non-empty-string
* @readonly
*/
private $badCode;
public function __construct(string $badCode, string $goodCode)
{
$badCode = \trim($badCode);
$goodCode = \trim($goodCode);
if ($badCode === '') {
throw new ShouldNotHappenException('Bad sample good code cannot be empty');
}
if ($goodCode === '') {
throw new ShouldNotHappenException('Good sample good code cannot be empty');
}
if ($goodCode === $badCode) {
$errorMessage = \sprintf('Good and bad code cannot be identical: "%s"', $goodCode);
throw new ShouldNotHappenException($errorMessage);
}
$this->goodCode = $goodCode;
$this->badCode = $badCode;
}
public function getGoodCode() : string
{
return $this->goodCode;
}
public function getBadCode() : string
{
return $this->badCode;
}
}