mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 23:10:51 +00:00
1e09b81ddb
e68c8d23cb
Fix CallableTypeParameterNode and IdentifierTypeParameterNode crash (#3353)
46 lines
1.3 KiB
PHP
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;
|
|
}
|
|
}
|