Skip to content

Commit

Permalink
Update PHPUnit version and refactor code structure
Browse files Browse the repository at this point in the history
PHPUnit version has been updated in composer.json. Additionally, the SensitiveParameter attribute has been applied in the StringManipulation.php file. The 'nameFix' method now has this attribute for handling sensitive data. Single-line conditions have been applied in 'dateFix' and 'isValidTimePart' methods to enhance the code readability and efficiency.
  • Loading branch information
MarjovanLier committed Feb 4, 2024
1 parent 0a83970 commit 178a170
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"phpstan/extension-installer": "^1.3.1",
"phpstan/phpstan": "^1.10.57",
"phpstan/phpstan-strict-rules": "^1.5.2",
"phpunit/phpunit": "^10.5.9",
"phpunit/phpunit": "^10.5.10",
"psalm/plugin-phpunit": "^0.18.4",
"rector/rector": "^0.19.5",
"roave/no-floaters": "^1.11",
Expand Down
15 changes: 4 additions & 11 deletions src/StringManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MarjovanLier\StringManipulation;

use DateTime;
use SensitiveParameter;

/**
* String Manipulation class for various string operations.
Expand Down Expand Up @@ -78,7 +79,7 @@ public static function searchWords(?string $words): ?string
*
* @return null|string The fixed last name according to the standards, or null if the input was null.
*/
public static function nameFix(?string $lastName): ?string
public static function nameFix(#[SensitiveParameter] ?string $lastName): ?string
{
if ($lastName === null) {
return null;
Expand Down Expand Up @@ -228,11 +229,7 @@ public static function isValidDate(string $date, string $format = 'Y-m-d H:i:s')
{
$dateTime = DateTime::createFromFormat($format, $date);

if (!$dateTime instanceof DateTime) {
return false;
}

if ($dateTime->format($format) !== $date) {
if (!$dateTime instanceof DateTime || $dateTime->format($format) !== $date) {
return false;
}

Expand Down Expand Up @@ -275,11 +272,7 @@ public static function trim(string $string, string $characters = " \t\n\r\0\x0B"
*/
private static function isValidTimePart(array $dateParts): bool
{
if (!self::isValidHour($dateParts['hour'])) {
return false;
}

if (!self::isValidMinute($dateParts['minute'])) {
if (!self::isValidHour($dateParts['hour']) || !self::isValidMinute($dateParts['minute'])) {
return false;
}

Expand Down

0 comments on commit 178a170

Please sign in to comment.