diff --git a/libraries/vendor_jcb/VDM.Joomla/src/Utilities/String/ComponentCodeNameHelper.php b/libraries/vendor_jcb/VDM.Joomla/src/Utilities/String/ComponentCodeNameHelper.php index e0b87ac75..fd53586b9 100644 --- a/libraries/vendor_jcb/VDM.Joomla/src/Utilities/String/ComponentCodeNameHelper.php +++ b/libraries/vendor_jcb/VDM.Joomla/src/Utilities/String/ComponentCodeNameHelper.php @@ -1,48 +1,45 @@ - * @git Joomla Component Builder - * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ +/** + * @package Joomla.Component.Builder + * + * @created 4th September, 2020 + * @author Llewellyn van der Merwe + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ namespace VDM\Joomla\Utilities\String; /** - * Control the naming of a component code name - * + * Control the naming of a component code name + * * @since 3.2.1 */ abstract class ComponentCodeNameHelper { - /** - * Making component code name safe for namespacing. - * - * This function processes a given string to format it according to PHP namespace naming conventions. - * ensures no spaces or underscores are present. - * - * @param string $string The component code name string to make safe - * - * @return string A namespace-safe string on success - * @since 3.2.1 - */ - public static function safe(string $string): string - { - // Trim whitespace from both ends of the string - $string = trim($string); - - // Replace any sequence of non-alphanumeric characters or underscores with a single underscore - $string = preg_replace('/[^\p{L}\p{N}]+/u', '', $string); - - // Ensure the first character is uppercase (useful if the input string started with an invalid character) - $string = ucfirst($string); - - // Return the namespace-safe component code name - return $string; + /** + * Making component code name safe for namespacing. + * + * This function processes a given string to format it according to PHP namespace naming conventions. + * ensures no spaces or underscores are present. + * + * @param string $string The component code name string to make safe + * + * @return string A namespace-safe string on success + * @since 3.2.1 + */ + public static function safe(string $string): string + { + // Ensure there is no empty spaces anywhere in the string + $string = preg_replace('/\s+/', '', $string); + + // Replace any sequence of non-alphanumeric characters or underscores with a single underscore + $string = preg_replace('/[^\p{L}\p{N}]+/u', '', $string); + + // Return the namespace-safe component code name + return $string; } }