Skip to content

Commit

Permalink
Make underscore and dasherize consistent
Browse files Browse the repository at this point in the history
Also Rename normalize to delimit, it isn't normalizing (take
inconsistent and make consistent).
  • Loading branch information
AD7six committed Feb 9, 2015
1 parent f79325f commit 11c03e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/Utility/Inflector.php
Expand Up @@ -606,7 +606,7 @@ public static function camelize($string, $replacement = '_')
*/
public static function underscore($string)
{
return static::normalize($string, '_');
return static::delimit(str_replace('-', '_', $string), '_');
}

/**
Expand All @@ -617,7 +617,7 @@ public static function underscore($string)
*/
public static function dasherize($string)
{
return static::normalize($string, '-');
return static::delimit(str_replace('_', '-', $string), '-');
}

/**
Expand All @@ -644,13 +644,13 @@ public static function humanize($string, $replacement = '_')
}

/**
* Takes the input string, and based on the replacement character converts to a normalized string
* Takes the input string, and based on the replacement character converts to a delimited string
*
* @param string $string String to normalize
* @param string $string String to delimit
* @param string $replacement the character to use as a delimiter
* @return string normalized string
* @return string delimited string
*/
public static function normalize($string, $replacement = '_')
public static function delimit($string, $replacement = '_')
{
$cacheKey = __FUNCTION__ . $replacement;

Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/Utility/InflectorTest.php
Expand Up @@ -377,6 +377,7 @@ public function testInflectorUnderscore()
$this->assertSame('test_thing', Inflector::underscore('testThing'));
$this->assertSame('test_thing_extra', Inflector::underscore('TestThingExtra'));
$this->assertSame('test_thing_extra', Inflector::underscore('testThingExtra'));
$this->assertSame('test_this_thing', Inflector::underscore('test-this-thing'));

// Identical checks test the cache code path.
$this->assertSame('test_thing', Inflector::underscore('TestThing'));
Expand All @@ -401,7 +402,7 @@ public function testDasherized()
$this->assertSame('test-thing', Inflector::dasherize('testThing'));
$this->assertSame('test-thing-extra', Inflector::dasherize('TestThingExtra'));
$this->assertSame('test-thing-extra', Inflector::dasherize('testThingExtra'));
$this->assertSame('test_this_thing', Inflector::dasherize('test_this_thing'), 'Should be unchanged');
$this->assertSame('test-this-thing', Inflector::dasherize('test_this_thing'));

// Test stupid values
$this->assertSame('', Inflector::dasherize(null));
Expand Down

0 comments on commit 11c03e0

Please sign in to comment.