Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
REBELinBLUE committed Mar 14, 2021
1 parent 0c6bfc6 commit b243862
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
1 change: 0 additions & 1 deletion resources/lang/de/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
'top_100' => 'Das Passwort ist in den Top 100 der häufigsten Passwörter.',
'digits' => 'Durch das Hinzufügen einer Reihe von Ziffern wird die Sicherheit nicht verbessert.',
'reused' => 'Die Wiederverwendung von Informationen wie Name, Benutzername oder E-Mail-Adresse im Kennwort ist nicht sicher.',

];
4 changes: 0 additions & 4 deletions src/ZxcvbnServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class ZxcvbnServiceProvider extends ServiceProvider

/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Expand All @@ -27,8 +25,6 @@ public function boot()

/**
* Register the application services.
*
* @return void
*/
public function register()
{
Expand Down
47 changes: 23 additions & 24 deletions src/ZxcvbnValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Illuminate\Translation\Translator;
use Illuminate\Validation\Validator;
use InvalidArgumentException;
use stdClass;
use ZxcvbnPhp\Matchers\BaseMatch;
use ZxcvbnPhp\Zxcvbn;

/**
Expand All @@ -28,15 +30,14 @@ public function __construct(Translator $translator)
$this->translator = $translator;
}

public function validate(...$args)
public function validate(...$args): bool
{
/** @var string $value */
$value = trim($args[1]);

/** @var array $parameters */
$parameters = $args[2] ? $args[2] : [];

/** @var \Illuminate\Validation\Validator $validator */
/** @var Validator $validator */
$validator = $args[3];

$desiredScore = $this->getDesiredScore($parameters);
Expand All @@ -59,7 +60,7 @@ public function validate(...$args)
return false;
}

private function getDesiredScore(array $parameters = [])
private function getDesiredScore(array $parameters = []): int
{
$desiredScore = isset($parameters[0]) ? $parameters[0] : self::DEFAULT_MINIMUM_STRENGTH;

Expand All @@ -70,7 +71,7 @@ private function getDesiredScore(array $parameters = [])
return $desiredScore;
}

private function getAdditionalInput(Validator $validator, array $parameters = [])
private function getAdditionalInput(Validator $validator, array $parameters = []): array
{
$input = $validator->getData();
$otherInput = [];
Expand All @@ -87,7 +88,7 @@ private function getFeedbackTranslation()
{
$isOnlyMatch = count($this->result['sequence']) === 1;

$longestMatch = new \stdClass();
$longestMatch = new stdClass();
$longestMatch->token = '';

foreach ($this->result['sequence'] as $match) {
Expand All @@ -99,7 +100,7 @@ private function getFeedbackTranslation()
return $this->getMatchFeedback($longestMatch, $isOnlyMatch);
}

private function getMatchFeedback($match, $isOnlyMatch)
private function getMatchFeedback(BaseMatch $match, $isOnlyMatch)
{
$pattern = mb_strtolower($match->pattern);
$strategy = 'get' . ucfirst($pattern) . 'Warning';
Expand All @@ -113,31 +114,28 @@ private function getMatchFeedback($match, $isOnlyMatch)

/**
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
* @param $match
* @param $isOnlyMatch
* @return string
*/
private function getDictionaryWarning($match, $isOnlyMatch)
private function getDictionaryWarning(BaseMatch $match, bool $isOnlyMatch): string
{
$warning = 'common'; // $match->dictionaryName == 'english'
if ($match->dictionaryName === 'passwords') {
$warning = $this->getPasswordWarning($match, $isOnlyMatch);
} elseif (in_array($match->dictionaryName, ['surnames', 'male_names', 'female_names'], true)) {
$warning = 'names';
} elseif ($match->dictionaryName === 'user_inputs') {
$warning = 'reused';
return $this->getPasswordWarning($match, $isOnlyMatch);
}

return $warning;
if (in_array($match->dictionaryName, ['surnames', 'male_names', 'female_names'], true)) {
return 'names';
}

if ($match->dictionaryName === 'user_inputs') {
return 'reused';
}

return 'common';
}

/**
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
* @noinspection PhpMissingReturnTypeInspection
* @param $match
* @return string
*/
private function getRegexWarning($match)
private function getRegexWarning(BaseMatch $match): string
{
$warning = 'year';

Expand All @@ -148,11 +146,12 @@ private function getRegexWarning($match)
return $warning;
}

private function getPasswordWarning($match, $isOnlyMatch)
private function getPasswordWarning(BaseMatch $match, bool $isOnlyMatch): string
{
if (!$isOnlyMatch) {
return 'suggestion';
}

if ($match->l33t) {
return 'predictable';
}
Expand All @@ -175,7 +174,7 @@ private function getPasswordWarning($match, $isOnlyMatch)
/**
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
*/
private function getSpatialWarning($match)
private function getSpatialWarning(BaseMatch $match): string
{
if ($match->turns === 1) {
return 'straight_spatial';
Expand Down

0 comments on commit b243862

Please sign in to comment.