From e2fd8093b455827a789fe471e60607c1902df182 Mon Sep 17 00:00:00 2001 From: Daniel Wilkowski Date: Sat, 24 Feb 2024 00:08:46 +0100 Subject: [PATCH] Deprecate Group methods --- ChangeLog.md | 12 ++++ .../Match/Details/Group/MatchedGroup.php | 57 ++++++++++++++++++- .../Match/Details/Group/NotMatchedGroup.php | 55 ++++++++++++++++++ src/CleanRegex/Match/Element.php | 3 + src/CleanRegex/Match/Group.php | 22 +++++++ src/CleanRegex/Match/Structure.php | 3 + 6 files changed, 151 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 603fd084e..af59ddd9d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -52,6 +52,18 @@ Incoming * Deprecate `Detail.toInt()` * Deprecate `Detail.isInt()` * Deprecate `Intable` + * Deprecate `Group` methods unqualified for release candidate. + * Deprecate `Group`, use `Detail` methods instead + * Deprecate `Group.matched()`, to be refactored to `Detail.groupMatched()` + * Deprecate `Group.equals()` + * Deprecate `Group.or()`, to be refactored `Detail.groupOrNull()` + * Deprecate `Group.index()`, use `Pattern.groupNames()` to calculate index based on name + * Deprecate `Group.name()`, use `Pattern.groupNames()` to calculate index based on name + * Deprecate `Group.usedIdentifier()` + * Deprecate `Group.all()` + * Deprecate `Group.subject()` + * Deprecate `Element` interface + * Deprecate `Structure` interface Added in 0.41.5 --------------- diff --git a/src/CleanRegex/Internal/Match/Details/Group/MatchedGroup.php b/src/CleanRegex/Internal/Match/Details/Group/MatchedGroup.php index 33395fd13..852fc728c 100644 --- a/src/CleanRegex/Internal/Match/Details/Group/MatchedGroup.php +++ b/src/CleanRegex/Internal/Match/Details/Group/MatchedGroup.php @@ -10,6 +10,9 @@ use TRegx\CleanRegex\Internal\Subject; use TRegx\CleanRegex\Match\Group; +/** + * @deprecated + */ class MatchedGroup implements Group { /** @var Subject */ @@ -26,48 +29,72 @@ public function __construct(Subject $subject, GroupDetails $details, GroupEntry $this->groupEntry = $entry; } + /** + * @deprecated + */ public function text(): string { return $this->groupEntry->text(); } + /** + * @deprecated + */ public function toInt(int $base = 10): int { $integerBase = new IntegerBase(new Base($base), new GroupExceptions($this->details->group())); return $integerBase->integer($this->groupEntry->text()); } + /** + * @deprecated + */ public function isInt(int $base = 10): bool { $number = new StringNumeral($this->groupEntry->text()); try { $number->asInt(new Base($base)); - } catch (NumeralFormatException | NumeralOverflowException $exception) { + } catch (NumeralFormatException|NumeralOverflowException $exception) { return false; } return true; } + /** + * @deprecated + */ public function matched(): bool { return true; } + /** + * @deprecated + */ public function equals(string $expected): bool { return $this->groupEntry->text() === $expected; } + /** + * @deprecated + */ public function or(string $substitute): string { return $this->text(); } + /** + * @deprecated + */ public function name(): ?string { return $this->details->name(); } + /** + * @deprecated + */ public function index(): int { return $this->details->index(); @@ -75,52 +102,80 @@ public function index(): int /** * @return int|string + * @deprecated */ public function usedIdentifier() { return $this->details->nameOrIndex(); } + /** + * @deprecated + */ public function offset(): int { return $this->groupEntry->offset(); } + /** + * @deprecated + */ public function tail(): int { return $this->groupEntry->tail(); } + /** + * @deprecated + */ public function length(): int { return \mb_strLen($this->groupEntry->text(), 'UTF-8'); } + /** + * @deprecated + */ public function byteOffset(): int { return $this->groupEntry->byteOffset(); } + /** + * @deprecated + */ public function byteTail(): int { return $this->groupEntry->byteTail(); } + /** + * @deprecated + */ public function byteLength(): int { return \strLen($this->groupEntry->text()); } + /** + * @deprecated + */ public function subject(): string { return $this->subject; } + /** + * @deprecated + */ public function all(): array { return $this->details->all(); } + /** + * @deprecated + */ public function __toString(): string { return $this->text(); diff --git a/src/CleanRegex/Internal/Match/Details/Group/NotMatchedGroup.php b/src/CleanRegex/Internal/Match/Details/Group/NotMatchedGroup.php index 552b0c4c6..2734a7ee7 100644 --- a/src/CleanRegex/Internal/Match/Details/Group/NotMatchedGroup.php +++ b/src/CleanRegex/Internal/Match/Details/Group/NotMatchedGroup.php @@ -6,6 +6,9 @@ use TRegx\CleanRegex\Internal\Subject; use TRegx\CleanRegex\Match\Group; +/** + * @deprecated + */ class NotMatchedGroup implements Group { /** @var Subject */ @@ -13,49 +16,76 @@ class NotMatchedGroup implements Group /** @var GroupDetails */ private $details; + /** + * @deprecated + */ public function __construct(Subject $subject, GroupDetails $details) { $this->subject = $subject; $this->details = $details; } + /** + * @deprecated + */ public function text(): string { throw $this->groupNotMatched('text'); } + /** + * @deprecated + */ public function toInt(int $base = 10): int { new Base($base); throw $this->groupNotMatched('toInt'); } + /** + * @deprecated + */ public function isInt(int $base = 10): bool { new Base($base); throw $this->groupNotMatched('isInt'); } + /** + * @deprecated + */ public function matched(): bool { return false; } + /** + * @deprecated + */ public function equals(string $expected): bool { return false; } + /** + * @deprecated + */ public function or(string $substitute): string { return $substitute; } + /** + * @deprecated + */ public function name(): ?string { return $this->details->name(); } + /** + * @deprecated + */ public function index(): int { return $this->details->index(); @@ -63,37 +93,56 @@ public function index(): int /** * @return int|string + * @deprecated */ public function usedIdentifier() { return $this->details->nameOrIndex(); } + /** + * @deprecated + */ public function offset(): int { throw $this->groupNotMatched('offset'); } + /** + * @deprecated + */ public function tail(): int { throw $this->groupNotMatched('tail'); } + /** + * @deprecated + */ public function length(): int { throw $this->groupNotMatched('length'); } + /** + * @deprecated + */ public function byteOffset(): int { throw $this->groupNotMatched('byteOffset'); } + /** + * @deprecated + */ public function byteTail(): int { throw $this->groupNotMatched('byteTail'); } + /** + * @deprecated + */ public function byteLength(): int { throw $this->groupNotMatched('byteLength'); @@ -104,11 +153,17 @@ protected function groupNotMatched(string $method): GroupNotMatchedException return new GroupNotMatchedException("Expected to call $method() for group {$this->details->group()}, but the group was not matched"); } + /** + * @deprecated + */ public function subject(): string { return $this->subject; } + /** + * @deprecated + */ public function all(): array { return $this->details->all(); diff --git a/src/CleanRegex/Match/Element.php b/src/CleanRegex/Match/Element.php index 944460f7c..c32805d68 100644 --- a/src/CleanRegex/Match/Element.php +++ b/src/CleanRegex/Match/Element.php @@ -3,6 +3,9 @@ use TRegx\CleanRegex\Internal\Match\Intable; +/** + * @deprecated + */ interface Element extends Intable { public function text(): string; diff --git a/src/CleanRegex/Match/Group.php b/src/CleanRegex/Match/Group.php index 3f3ba3918..54403b1f3 100644 --- a/src/CleanRegex/Match/Group.php +++ b/src/CleanRegex/Match/Group.php @@ -1,22 +1,44 @@