Skip to content

Commit

Permalink
Only check classes in php7
Browse files Browse the repository at this point in the history
  • Loading branch information
mamazu committed Jan 12, 2022
1 parent 2b49942 commit 5a069b2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Validator/Php/PhpClassExistsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ final class PhpClassExistsValidator implements ValidatorInterface
/** @var PhpCodeEnsurerInterface */
private $codeEnsurer;

/** @var false|string */
private $phpVersion;

public function __construct(
callable $classExists,
?Parser $parser = null,
Expand All @@ -34,11 +37,19 @@ public function __construct(
$this->parser = $parser ?? (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$this->classExists = $classExists;
$this->codeEnsurer = $codeEnsurer ?? new PhpCodeEnsurer();

$phpversion = phpversion();
Assert::string($phpversion, 'Could not get php version.');
$this->phpVersion = $phpversion;
}

/** {@inheritDoc} */
public function validate(Block $block): array
{
if ($this->phpVersion === "8") {
return [];
}

$phpCode = $this->codeEnsurer->getPHPCode($block->getContent());
try {
$statements = $this->parser->parse($phpCode);
Expand Down

0 comments on commit 5a069b2

Please sign in to comment.