diff --git a/src/Laravel/ValidationServiceProvider.php b/src/Laravel/ValidationServiceProvider.php index 01ca9f5..fb86d9c 100644 --- a/src/Laravel/ValidationServiceProvider.php +++ b/src/Laravel/ValidationServiceProvider.php @@ -24,14 +24,14 @@ public function boot() ); // add rules to laravel validator - foreach ($this->getRuleShortnames() as $rulename) { + foreach ($this->ruleShortnames() as $rulename) { $this->app['validator']->extend( $rulename, function ($attribute, $value, $parameters, $validator) use ($rulename) { - return $this->getInterventionRule($rulename, $parameters) + return $this->interventionRule($rulename, $parameters) ->isValid($value); }, - $this->getErrorMessage($rulename) + $this->errorMessage($rulename) ); } } @@ -44,7 +44,7 @@ function ($attribute, $value, $parameters, $validator) use ($rulename) { * @return Rule * @throws NotExistingRuleException */ - private function getInterventionRule(string $rulename, array $parameters): Rule + private function interventionRule(string $rulename, array $parameters): Rule { $classname = sprintf("Intervention\Validation\Rules\%s", ucfirst($rulename)); @@ -56,11 +56,11 @@ private function getInterventionRule(string $rulename, array $parameters): Rule } /** - * List all shortnames of new rule objects + * List all shortnames of Intervention validation rule objects * * @return array */ - private function getRuleShortnames(): array + private function ruleShortnames(): array { return array_map(function ($filename) { return mb_strtolower(substr($filename, 0, -4)); @@ -73,13 +73,13 @@ private function getRuleShortnames(): array * @param string $rulename * @return string */ - protected function getErrorMessage(string $rulename): string + protected function errorMessage(string $rulename): string { return $this->app['translator']->get('validation::validation.' . $rulename); } /** - * Get the services provided by the provider. + * Return the services provided by the provider. * * @return array */ diff --git a/src/Rules/Domainname.php b/src/Rules/Domainname.php index 7cb4890..7d1d737 100644 --- a/src/Rules/Domainname.php +++ b/src/Rules/Domainname.php @@ -15,7 +15,7 @@ class Domainname extends AbstractRule */ public function isValid(mixed $value): bool { - $labels = $this->getLabels($value); // get labels of domainname + $labels = $this->labels($value); // get labels of domainname $tld = end($labels); // most right label of domainname is tld // domain must have 2 labels minimum @@ -43,7 +43,7 @@ public function isValid(mixed $value): bool * * @return array */ - private function getLabels(mixed $value): array + private function labels(mixed $value): array { return explode('.', $this->idnToAscii($value)); } diff --git a/src/Rules/Iban.php b/src/Rules/Iban.php index 1c2c32c..05512c7 100644 --- a/src/Rules/Iban.php +++ b/src/Rules/Iban.php @@ -132,7 +132,7 @@ public function isValid(mixed $value): bool $value = str_replace(' ', '', strtoupper(strval($value))); // check iban length and checksum - return $this->hasValidLength($value) && $this->getChecksum($value) === 1; + return $this->hasValidLength($value) && $this->checksum($value) === 1; } /** @@ -141,12 +141,12 @@ public function isValid(mixed $value): bool * @param string $iban * @return int */ - private function getChecksum(string $iban): int + private function checksum(string $iban): int { $iban = substr($iban, 4) . substr($iban, 0, 4); $iban = str_replace( - $this->getReplacementsChars(), - $this->getReplacementsValues(), + $this->replacementsChars(), + $this->replacementsValues(), $iban ); @@ -167,7 +167,7 @@ private function getChecksum(string $iban): int * @param string $iban * @return int|false */ - private function getDesignatedIbanLength(string $iban): int|false + private function designatedIbanLength(string $iban): int|false { $countrycode = substr($iban, 0, 2); @@ -182,7 +182,7 @@ private function getDesignatedIbanLength(string $iban): int|false */ private function hasValidLength(string $iban): bool { - return $this->getDesignatedIbanLength($iban) == strlen($iban); + return $this->designatedIbanLength($iban) == strlen($iban); } /** @@ -190,7 +190,7 @@ private function hasValidLength(string $iban): bool * * @return array */ - private function getReplacementsChars(): array + private function replacementsChars(): array { return range('A', 'Z'); } @@ -200,7 +200,7 @@ private function getReplacementsChars(): array * * @return array */ - private function getReplacementsValues(): array + private function replacementsValues(): array { $values = []; foreach (range(10, 35) as $value) { diff --git a/src/Rules/Isbn.php b/src/Rules/Isbn.php index dba82a2..5091ed5 100644 --- a/src/Rules/Isbn.php +++ b/src/Rules/Isbn.php @@ -48,7 +48,7 @@ public function isValid(mixed $value): bool */ private function shortChecksumMatches(string $value): bool { - return $this->getShortChecksum($value) % 11 === 0; + return $this->shortChecksum($value) % 11 === 0; } /** @@ -57,7 +57,7 @@ private function shortChecksumMatches(string $value): bool * @param string $value * @return int */ - private function getShortChecksum(string $value): int + private function shortChecksum(string $value): int { $checksum = 0; $multiplier = 10; diff --git a/src/Rules/Isin.php b/src/Rules/Isin.php index 6ab771a..d271db8 100644 --- a/src/Rules/Isin.php +++ b/src/Rules/Isin.php @@ -58,7 +58,7 @@ public function isValid(mixed $value): bool */ public function normalize(string $value): string { - return $this->replaceChars($this->getValueWithoutLastDigit($value)) . $this->getLastDigit($value); + return $this->replaceChars($this->valueWithoutLastDigit($value)) . $this->lastDigit($value); } /** @@ -78,7 +78,7 @@ private function replaceChars(string $value): string * @param string $value * @return string */ - private function getValueWithoutLastDigit(string $value): string + private function valueWithoutLastDigit(string $value): string { return substr($value, 0, -1); } @@ -89,7 +89,7 @@ private function getValueWithoutLastDigit(string $value): string * @param string $value * @return string */ - private function getLastDigit(string $value): string + private function lastDigit(string $value): string { return substr($value, -1); } diff --git a/src/Rules/Lowercase.php b/src/Rules/Lowercase.php index 24329bd..dc59310 100644 --- a/src/Rules/Lowercase.php +++ b/src/Rules/Lowercase.php @@ -15,17 +15,8 @@ class Lowercase extends AbstractRule */ public function isValid(mixed $value): bool { - return $value === $this->getLowerCaseValue($value); - } + $lowerCaseValue = mb_strtolower(strval($value), mb_detect_encoding($value)); - /** - * Return value as lowercase - * - * @param mixed $value - * @return string - */ - private function getLowerCaseValue(mixed $value): string - { - return mb_strtolower(strval($value), mb_detect_encoding($value)); + return $value === $lowerCaseValue; } } diff --git a/src/Rules/Luhn.php b/src/Rules/Luhn.php index a4dbe77..541e4a9 100644 --- a/src/Rules/Luhn.php +++ b/src/Rules/Luhn.php @@ -15,7 +15,7 @@ class Luhn extends AbstractRule */ public function isValid(mixed $value): bool { - return $this->checksumIsValid($this->getChecksum($value)); + return $this->checksumIsValid($this->checksum($value)); } /** @@ -35,7 +35,7 @@ private function checksumIsValid($checksum): bool * @param mixed $value * @return int */ - private function getChecksum($value): int + private function checksum($value): int { $checksum = 0; $reverse = strrev(strval($value)); diff --git a/src/Rules/Postalcode.php b/src/Rules/Postalcode.php index baca8cd..4a4e9b6 100644 --- a/src/Rules/Postalcode.php +++ b/src/Rules/Postalcode.php @@ -78,7 +78,7 @@ public static function countrycode(array $countrycodes): self */ public function isValid(mixed $value): bool { - foreach ($this->getPatterns() as $pattern) { + foreach ($this->patterns() as $pattern) { if (preg_match($pattern, $value)) { return true; } @@ -92,11 +92,11 @@ public function isValid(mixed $value): bool * * @return array */ - private function getPatterns(): array + private function patterns(): array { $patterns = array_map(function ($countrycode) { - return $this->getPattern($countrycode); - }, $this->getCountryCodes()); + return $this->pattern($countrycode); + }, $this->countryCodes()); return array_filter($patterns, function ($pattern) { return !is_null($pattern); @@ -108,7 +108,7 @@ private function getPatterns(): array * * @return array */ - private function getCountryCodes(): array + private function countryCodes(): array { if (count($this->countrycodes) == 0) { // return country code by reference @@ -125,7 +125,7 @@ private function getCountryCodes(): array * * @return ?string */ - private function getPattern(string $countrycode): ?string + private function pattern(string $countrycode): ?string { return match (strtolower($countrycode)) { 'dz', 'as', 'ad', 'de', 'ba', 'ic', 'mp', 'hr', 'cu', 'ee', 'fi', 'fr', 'gf', 'gp', 'gu', 'id', 'it', 'kr', diff --git a/src/Rules/Titlecase.php b/src/Rules/Titlecase.php index 7e578ca..dd14ab7 100644 --- a/src/Rules/Titlecase.php +++ b/src/Rules/Titlecase.php @@ -15,7 +15,7 @@ class Titlecase extends AbstractRule */ public function isValid(mixed $value): bool { - foreach ($this->getWords($value) as $word) { + foreach ($this->words($value) as $word) { if (!$this->isValidWord($word)) { return false; } @@ -30,7 +30,7 @@ public function isValid(mixed $value): bool * @param mixed $value * @return array */ - private function getWords(mixed $value): array + private function words(mixed $value): array { return explode(" ", $value); } diff --git a/src/Rules/Uppercase.php b/src/Rules/Uppercase.php index 4fb0152..7617811 100644 --- a/src/Rules/Uppercase.php +++ b/src/Rules/Uppercase.php @@ -15,16 +15,8 @@ class Uppercase extends AbstractRule */ public function isValid(mixed $value): bool { - return $value === $this->getUpperCaseValue($value); - } + $upperCaseValue = mb_strtoupper(strval($value), mb_detect_encoding($value)); - /** - * Return value as uppercase - * - * @return string - */ - private function getUpperCaseValue(mixed $value): string - { - return mb_strtoupper(strval($value), mb_detect_encoding($value)); + return $value === $upperCaseValue; } }