Skip to content

Commit

Permalink
Remove ilario-pierbattista/reverse-regex
Browse files Browse the repository at this point in the history
  • Loading branch information
pdureau committed Oct 8, 2023
1 parent 7058995 commit 7957ebb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"license": "GPL-2.0-or-later",
"type": "drupal-module",
"require": {
"drupal/token": "^1.0",
"ilario-pierbattista/reverse-regex": "0.3.*"
"drupal/token": "^1.0"
}
}
28 changes: 10 additions & 18 deletions src/Utils/SchemaCompatibilityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

namespace Drupal\ui_patterns\Utils;

use ReverseRegex\Generator\Scope;
use ReverseRegex\Lexer;
use ReverseRegex\Parser;
use ReverseRegex\Random\SimpleRandom;

/**
* Checks whether two schemas are compatible.
*
Expand Down Expand Up @@ -177,11 +172,6 @@ protected function isNumericCompatible(array $checked_schema, array $reference_s
*/
protected function isStringCompatible(array $checked_schema, array $reference_schema): bool {
// FALSE if at least one of those tests is FALSE.
if (array_key_exists("pattern", $reference_schema)) {
if (!$this->isStringPatternCompatible($checked_schema, $reference_schema)) {
return FALSE;
}
}
if (array_key_exists("format", $reference_schema)) {
if (!$this->isStringFormatCompatible($checked_schema, $reference_schema)) {
return FALSE;
Expand All @@ -202,6 +192,11 @@ protected function isStringCompatible(array $checked_schema, array $reference_sc
return FALSE;
}
}
if (array_key_exists("pattern", $reference_schema)) {
if (!$this->isStringPatternCompatible($checked_schema, $reference_schema)) {
return FALSE;
}
}
return TRUE;
}

Expand All @@ -212,24 +207,21 @@ protected function isStringPatternCompatible(array $checked_schema, array $refer
if (!array_key_exists("pattern", $checked_schema)) {
return FALSE;
}
return FALSE;
// Is checked schema pattern and sub pattern of reference schema?
$example = $this->generateExampleFromPattern($checked_schema["pattern"]);
$result = preg_match("/" . $reference_schema["pattern"] . "/", $example);
if ($result !== 1) {
return FALSE;
if ($result === 1) {
return TRUE;
}
return TRUE;
return FALSE;
}

/**
*
*/
protected function generateExampleFromPattern(string $pattern): string {
$lexer = new Lexer($pattern);
$gen = new SimpleRandom(10007);
$result = '';
$parser = new Parser($lexer, new Scope(), new Scope());
$parser->parse()->getResult()->generate($result, $gen);
// ilario-pierbattista/reverse-regex.
return $result;
}

Expand Down

0 comments on commit 7957ebb

Please sign in to comment.