Skip to content

Commit

Permalink
Converting Codestyle to PSR12
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackwar committed Jan 31, 2023
1 parent 0932b03 commit 8823ea4
Show file tree
Hide file tree
Showing 28 changed files with 3,239 additions and 3,358 deletions.
772 changes: 382 additions & 390 deletions Tests/InflectorTest.php

Large diffs are not rendered by default.

468 changes: 234 additions & 234 deletions Tests/NormaliseTest.php

Large diffs are not rendered by default.

1,816 changes: 904 additions & 912 deletions Tests/StringHelperTest.php

Large diffs are not rendered by default.

542 changes: 264 additions & 278 deletions src/Inflector.php

Large diffs are not rendered by default.

240 changes: 120 additions & 120 deletions src/Normalise.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,134 +15,134 @@
*/
abstract class Normalise
{
/**
* Method to convert a string from camel case.
*
* This method offers two modes. Grouped allows for splitting on groups of uppercase characters as follows:
*
* "FooBarABCDef" becomes array("Foo", "Bar", "ABC", "Def")
* "JFooBar" becomes array("J", "Foo", "Bar")
* "J001FooBar002" becomes array("J001", "Foo", "Bar002")
* "abcDef" becomes array("abc", "Def")
* "abc_defGhi_Jkl" becomes array("abc_def", "Ghi_Jkl")
* "ThisIsA_NASAAstronaut" becomes array("This", "Is", "A_NASA", "Astronaut"))
* "JohnFitzgerald_Kennedy" becomes array("John", "Fitzgerald_Kennedy"))
*
* Non-grouped will split strings at each uppercase character.
*
* @param string $input The string input (ASCII only).
* @param boolean $grouped Optionally allows splitting on groups of uppercase characters.
*
* @return array|string The space separated string, as an array if grouped.
*
* @since 1.0
*/
public static function fromCamelCase($input, $grouped = false)
{
return $grouped
? preg_split('/(?<=[^A-Z_])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][^A-Z_])/x', $input)
: trim(preg_replace('#([A-Z])#', ' $1', $input));
}
/**
* Method to convert a string from camel case.
*
* This method offers two modes. Grouped allows for splitting on groups of uppercase characters as follows:
*
* "FooBarABCDef" becomes array("Foo", "Bar", "ABC", "Def")
* "JFooBar" becomes array("J", "Foo", "Bar")
* "J001FooBar002" becomes array("J001", "Foo", "Bar002")
* "abcDef" becomes array("abc", "Def")
* "abc_defGhi_Jkl" becomes array("abc_def", "Ghi_Jkl")
* "ThisIsA_NASAAstronaut" becomes array("This", "Is", "A_NASA", "Astronaut"))
* "JohnFitzgerald_Kennedy" becomes array("John", "Fitzgerald_Kennedy"))
*
* Non-grouped will split strings at each uppercase character.
*
* @param string $input The string input (ASCII only).
* @param boolean $grouped Optionally allows splitting on groups of uppercase characters.
*
* @return array|string The space separated string, as an array if grouped.
*
* @since 1.0
*/
public static function fromCamelCase($input, $grouped = false)
{
return $grouped
? preg_split('/(?<=[^A-Z_])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][^A-Z_])/x', $input)
: trim(preg_replace('#([A-Z])#', ' $1', $input));
}

/**
* Method to convert a string into camel case.
*
* @param string $input The string input (ASCII only).
*
* @return string The camel case string.
*
* @since 1.0
*/
public static function toCamelCase($input)
{
// Convert words to uppercase and then remove spaces.
$input = static::toSpaceSeparated($input);
$input = ucwords($input);
$input = str_ireplace(' ', '', $input);
/**
* Method to convert a string into camel case.
*
* @param string $input The string input (ASCII only).
*
* @return string The camel case string.
*
* @since 1.0
*/
public static function toCamelCase($input)
{
// Convert words to uppercase and then remove spaces.
$input = static::toSpaceSeparated($input);
$input = ucwords($input);
$input = str_ireplace(' ', '', $input);

return $input;
}
return $input;
}

/**
* Method to convert a string into dash separated form.
*
* @param string $input The string input (ASCII only).
*
* @return string The dash separated string.
*
* @since 1.0
*/
public static function toDashSeparated($input)
{
// Convert spaces and underscores to dashes.
return preg_replace('#[ \-_]+#', '-', $input);
}
/**
* Method to convert a string into dash separated form.
*
* @param string $input The string input (ASCII only).
*
* @return string The dash separated string.
*
* @since 1.0
*/
public static function toDashSeparated($input)
{
// Convert spaces and underscores to dashes.
return preg_replace('#[ \-_]+#', '-', $input);
}

/**
* Method to convert a string into space separated form.
*
* @param string $input The string input (ASCII only).
*
* @return string The space separated string.
*
* @since 1.0
*/
public static function toSpaceSeparated($input)
{
// Convert underscores and dashes to spaces.
return preg_replace('#[ \-_]+#', ' ', $input);
}
/**
* Method to convert a string into space separated form.
*
* @param string $input The string input (ASCII only).
*
* @return string The space separated string.
*
* @since 1.0
*/
public static function toSpaceSeparated($input)
{
// Convert underscores and dashes to spaces.
return preg_replace('#[ \-_]+#', ' ', $input);
}

/**
* Method to convert a string into underscore separated form.
*
* @param string $input The string input (ASCII only).
*
* @return string The underscore separated string.
*
* @since 1.0
*/
public static function toUnderscoreSeparated($input)
{
// Convert spaces and dashes to underscores.
return preg_replace('#[ \-_]+#', '_', $input);
}
/**
* Method to convert a string into underscore separated form.
*
* @param string $input The string input (ASCII only).
*
* @return string The underscore separated string.
*
* @since 1.0
*/
public static function toUnderscoreSeparated($input)
{
// Convert spaces and dashes to underscores.
return preg_replace('#[ \-_]+#', '_', $input);
}

/**
* Method to convert a string into variable form.
*
* @param string $input The string input (ASCII only).
*
* @return string The variable string.
*
* @since 1.0
*/
public static function toVariable($input)
{
// Remove dashes and underscores, then convert to camel case.
$input = static::toCamelCase($input);
/**
* Method to convert a string into variable form.
*
* @param string $input The string input (ASCII only).
*
* @return string The variable string.
*
* @since 1.0
*/
public static function toVariable($input)
{
// Remove dashes and underscores, then convert to camel case.
$input = static::toCamelCase($input);

// Remove leading digits.
$input = preg_replace('#^[0-9]+#', '', $input);
// Remove leading digits.
$input = preg_replace('#^[0-9]+#', '', $input);

// Lowercase the first character.
$input = lcfirst($input);
// Lowercase the first character.
$input = lcfirst($input);

return $input;
}
return $input;
}

/**
* Method to convert a string into key form.
*
* @param string $input The string input (ASCII only).
*
* @return string The key string.
*
* @since 1.0
*/
public static function toKey($input)
{
// Remove spaces and dashes, then convert to lower case.
return strtolower(static::toUnderscoreSeparated($input));
}
/**
* Method to convert a string into key form.
*
* @param string $input The string input (ASCII only).
*
* @return string The key string.
*
* @since 1.0
*/
public static function toKey($input)
{
// Remove spaces and dashes, then convert to lower case.
return strtolower(static::toUnderscoreSeparated($input));
}
}
Loading

0 comments on commit 8823ea4

Please sign in to comment.