| Conditions | 1 |
| Paths | 1 |
| Total Lines | 25 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php namespace Tamtamchik\NameCase; |
||
| 30 | public static function nc($string, array $options = []) |
||
| 31 | { |
||
| 32 | //$options = array_merge(self::DEFAULT_OPTIONS, $options); |
||
| 33 | // |
||
| 34 | ////Skip if string is mixed case |
||
| 35 | //if ($options['lazy']) { |
||
| 36 | // $firstLetterLower = $string[0] == strtolower($string[0]); |
||
| 37 | // $allLowerOrUpper = (strtolower($string) == $string || strtoupper($string) == $string); |
||
| 38 | // |
||
| 39 | // if ( ! $firstLetterLower || ! $allLowerOrUpper) return $string; |
||
| 40 | //} |
||
| 41 | |||
| 42 | $local = strtolower($string); |
||
| 43 | |||
| 44 | // Capitalize |
||
| 45 | $local = preg_replace_callback('/\b\w/', function ($matches) { |
||
| 46 | return strtoupper($matches[0]); |
||
| 47 | }, $local); |
||
| 48 | |||
| 49 | $local = preg_replace_callback('/\'\w\b/', function ($matches) { |
||
| 50 | return strtolower($matches[0]); |
||
| 51 | }, $local); # Lowercase 's |
||
| 52 | |||
| 53 | return $local; |
||
| 54 | } |
||
| 55 | } |
||
| 56 |