diff --git a/src/Zxcvbn/Classes/FeedbackUtilities.php b/src/Zxcvbn/Classes/FeedbackUtilities.php new file mode 100644 index 0000000..c8fcc7a --- /dev/null +++ b/src/Zxcvbn/Classes/FeedbackUtilities.php @@ -0,0 +1,48 @@ + 2) + { + return new Feedback(); + } + + // tie feedback to the longest match for longer sequences + $longestMatch = $sequence[0]; + foreach (array_slice($sequence, 1) as $match) + { + if (mb_strlen($match->token) > mb_strlen($longestMatch->token)) + { + $longestMatch = $match; + } + } + + /** @var Feedback $feedback */ + $feedback = $longestMatch->getFeedback(count($sequence) === 1); + $extraFeedback = 'Add another word or two. Uncommon words are better.'; + array_unshift($feedback->Suggestions, $extraFeedback); + return $feedback; + } + } diff --git a/src/Zxcvbn/Classes/Matchers/DateMatch.php b/src/Zxcvbn/Classes/Matchers/DateMatch.php new file mode 100644 index 0000000..04360d6 --- /dev/null +++ b/src/Zxcvbn/Classes/Matchers/DateMatch.php @@ -0,0 +1,8 @@ +Warning = $warning; + $this->Suggestions = $Suggestions; + } + + /** + * @return array + * @noinspection PhpUnused + */ + public function toArray(): array + { + return [ + 'warning' => $this->Warning, + 'suggestions' => $this->Suggestions + ]; + } + + /** + * @param array $data + * @return Feedback + * @noinspection PhpUnused + */ + public static function fromArray(array $data): Feedback + { + $FeedbackObject = new Feedback(); + + if(isset($data['warning'])) + $FeedbackObject->Warning = $data['warning']; + + if(isset($data['suggestions'])) + $FeedbackObject->Suggestions = $data['suggestions']; + + return $FeedbackObject; + } + } \ No newline at end of file