Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated inflector to conserve internal caps #16

Closed
wants to merge 3 commits into from

Conversation

calcinai
Copy link
Contributor

@calcinai calcinai commented Dec 14, 2016

Also added a test case for this

Fixes #15

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 90.184% when pulling 305880d on calcinai:master into 4f876f1 on ICanBoogie:master.

@@ -238,7 +238,7 @@ public function camelize($term, $downcase_first_letter = self::UPCASE_FIRST_LETT

$m = $matches[0];

return !empty($acronyms[$m]) ? $acronyms[$m] : capitalize($m);
return !empty($acronyms[$m]) ? $acronyms[$m] : ucfirst($m);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ucfirst() won't do because it doesn't work with UTF-8. Maybe add a private method:

static private function ucfirst($str)
{
    return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, good spotting. Should there be tests for this (all current tests pass)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't actually seen that helpers file until now - would that be a more appropriate place to add it? e.g.

if (!function_exists(__NAMESPACE__ . '\mb_ucfirst'))
{
	function mb_ucfirst($str)
	{
		return upcase(mb_substr($str, 0, 1)) . mb_substr($str, 1);
	}
}

Is that naming ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather use a private method, or define mb_ucfirst() without namespace, that's because mb_ functions are defined in the global namespace, contrary to the helpers in that file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plan a done.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 90.244% when pulling 6013fb1 on calcinai:master into 4f876f1 on ICanBoogie:master.

* @param $str
* @return string
*/
private static function ucfirst($str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing, please define the static method at the top of the class, after static public function get($locale = self::DEFAULT_LOCALE), and use static private rather than private static. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok cool, except it's not going to work because of the closure context

/**
* Multi-byte safe ucfirst
*
* @param $str
Copy link
Member

@olvlvl olvlvl Dec 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be @param string $str.

@calcinai
Copy link
Contributor Author

Obviously not ideal having the function out there, but it seems like the cleanest way to retain PHP 5.3 compatibility.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 90.244% when pulling 1567653 on calcinai:master into 4f876f1 on ICanBoogie:master.

@olvlvl
Copy link
Member

olvlvl commented Dec 14, 2016

@calcinai, please have a look at this PR: #17

@calcinai calcinai closed this Dec 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants