From 32746c3069212612d075185a8ca6fb7509e96d83 Mon Sep 17 00:00:00 2001 From: BMTmohammedtaha Date: Fri, 6 Dec 2024 11:18:17 +0100 Subject: [PATCH] convert static methods to normal methods --- composer.json | 4 ---- src/ArrayToString.php | 12 ++++------- src/DateToString.php | 12 ++--------- src/TextToString.php | 48 ++++++++++--------------------------------- 4 files changed, 17 insertions(+), 59 deletions(-) diff --git a/composer.json b/composer.json index 9b89c56..5f7b55f 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,4 @@ }, "minimum-stability": "stable" -<<<<<<< HEAD } -======= -} ->>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364 diff --git a/src/ArrayToString.php b/src/ArrayToString.php index dc8bc08..ad7a1ab 100644 --- a/src/ArrayToString.php +++ b/src/ArrayToString.php @@ -12,7 +12,7 @@ class ArrayToString * @param array $array The input array. * @return string The string representation of the array. */ - public static function array(array $array): string + public function array(array $array): string { if (empty($array)) { return '[]'; @@ -34,7 +34,7 @@ public static function array(array $array): string * @param string $separator The separator used to join the array elements. * @return string The resulting string. */ - public static function arrayToText(array $data, string $separator = ','): string + public function arrayToText(array $data, string $separator = ','): string { return join($separator, $data); } @@ -45,13 +45,9 @@ public static function arrayToText(array $data, string $separator = ','): string * @param array $data The input array. * @return string The URL-friendly slug. */ -<<<<<<< HEAD - public static function arrayToSlug(array $data): string -======= public function arrayToSlug(array $data): string ->>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364 { - return static::arrayToText($data, '-'); + return $this->arrayToText($data, '-'); } /** @@ -60,7 +56,7 @@ public function arrayToSlug(array $data): string * @param array|string $data The input array or JSON string. * @return string The key-value pair string representation. */ - public static function arrayToTextKeyValue($data): string + public function arrayToTextKeyValue($data): string { if (is_string($data)) { $data = json_decode($data, true); diff --git a/src/DateToString.php b/src/DateToString.php index 6a86c48..a441bb7 100644 --- a/src/DateToString.php +++ b/src/DateToString.php @@ -12,11 +12,7 @@ class DateToString * @param int $time The time value in seconds. * @return string The formatted time string (HH:MM:SS). */ -<<<<<<< HEAD - public static function formatTime(int $time): string -======= public function formatTime(int $time): string ->>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364 { $hours = gmdate('H', $time); $minutes = gmdate('i', $time); @@ -31,12 +27,8 @@ public function formatTime(int $time): string * @param int $timestamp The timestamp value. * @return string The formatted date string (YYYY-MM-DD). */ -<<<<<<< HEAD - public static function formatDate(int $timestamp): string -======= - public function formatDate(int $timestamp): string ->>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364 + public static function formatDate(int $timestamp, string $format = 'Y-m-d'): string { - return date('Y-m-d', $timestamp); + return date($format, $timestamp); } } diff --git a/src/TextToString.php b/src/TextToString.php index bceeb14..6c80cf8 100644 --- a/src/TextToString.php +++ b/src/TextToString.php @@ -12,11 +12,7 @@ class TextToString * @param string $text The input string. * @return string The string converted to uppercase. */ -<<<<<<< HEAD - public static function toUppercase(string $text): string -======= public function toUppercase(string $text): string ->>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364 { return strtoupper($text); } @@ -27,11 +23,7 @@ public function toUppercase(string $text): string * @param string $text The input string. * @return string The string converted to lowercase. */ -<<<<<<< HEAD - public static function toLowercase(string $text): string -======= public function toLowercase(string $text): string ->>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364 { return strtolower($text); } @@ -42,11 +34,7 @@ public function toLowercase(string $text): string * @param string $text The input string. * @return string The string with tags stripped. */ -<<<<<<< HEAD - public static function strip(string $text): string -======= public function strip(string $text): string ->>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364 { return strip_tags($text); } @@ -57,11 +45,7 @@ public function strip(string $text): string * @param mixed $variable The variable to get the name from. * @return string The name of the variable. */ -<<<<<<< HEAD - public static function nameVar($variable): string -======= public function nameVar($variable): string ->>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364 { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $callerLine = $backtrace[1]['line']; @@ -79,27 +63,30 @@ public function nameVar($variable): string * Converts a string to a URL-friendly slug. * * @param string $text The input string. + * @param string $separator separator symbol. * @return string The URL-friendly slug. */ -<<<<<<< HEAD - public static function textToSlug($text): string -======= - public function textToSlug($text): string ->>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364 + public function textToSlug(string $text, string $separator): string { // Convert the text to lowercase $text = strtolower($text); // Replace spaces and special characters with dashes - $text = preg_replace('/[^a-z0-9]+/', '-', $text); + $text = preg_replace('/[^a-z0-9]+/', $separator, $text); // Remove leading and trailing dashes - $text = trim($text, '-'); + $text = trim($text, $separator); return $text; } -<<<<<<< HEAD + /** + * Converts a string to a camel case + * + * @param string $string + * @return string + */ + public static function snakeToCamel(string $string): string { $words = explode('_', $string); @@ -123,19 +110,13 @@ public static function camelToSnake(string $inputString): string return $outputString; } -======= ->>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364 /** * Converts a URL-friendly slug back to a readable text. * * @param string $slug The input slug. * @return string The readable text. */ -<<<<<<< HEAD - public static function slugToText($slug): string -======= public function slugToText($slug): string ->>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364 { // Replace dashes with spaces $text = str_replace('-', ' ', $slug); @@ -152,11 +133,7 @@ public function slugToText($slug): string * @param int $length The length of the random text. * @return string The generated random text. */ -<<<<<<< HEAD - public static function generateRandomText($length): string -======= public function generateRandomText($length): string ->>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364 { $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $randomText = ''; @@ -168,7 +145,6 @@ public function generateRandomText($length): string return $randomText; } -<<<<<<< HEAD /** * Converts a hyphen-separated text to camel case. @@ -198,6 +174,4 @@ function dashToCamelCase(string $text): string return $convertedText; } -======= ->>>>>>> 145a7cd92f06365c9f0ca190efdc6e1766c29364 }