Skip to content

Commit fa95161

Browse files
author
ajibukunoluwa
committed
Improved documentation with better examples
1 parent 0a98f28 commit fa95161

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ var_dump(Duration::fiftyFourDays()); // returns 4665600;
6464
### Dynamic calls
6565
In addition to the methods provided above, the package uses `PHP` `__callStatic()` method to allow you make dynamic calls on the `Duration` trait.
6666

67-
For example, you want to get the number of seconds in 37 days, you can achieve this by calling a `studly-case` text of the number (`thirtySeven` in this case), plus the unit (`Days` in this case). That will leave us with something like this:
67+
For example, you want to get the number of seconds in 37 days, you can achieve this by calling a `camel-case` text of the number (`thirtySeven` in this case), plus the unit (`Days` in this case). That will leave us with something like this:
6868

6969
```php
70-
// The formula = studlyCaseOfTheNumberInWords + Unit
70+
// The formula = camelCaseOfTheNumberInWords + Unit
7171
Duration::thirtySevenDays(); // returns the number of seconds in 37 days
7272
```
7373

74-
> **Note:** The number in words **MUST** be in `studly-case`. Any other case will throw an `InvalidArgumentException`. Additionally, it must be followed by a `title-case` of the unit. The available units are `Seconds`, `Minutes`, `Hours`, and `Days`.
74+
> **Note:** The number in words **MUST** be in `camel-case`. Any other case will throw an `InvalidArgumentException`. Additionally, it must be followed by a `title-case` of the unit. The available units are `Seconds`, `Minutes`, `Hours`, and `Days`.
7575
7676

7777
## Usage

src/Helpers/Str.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ public static function simplePluralize(string $word): string
4040
*/
4141
public static function wordsToNumber($data): int
4242
{
43-
if (isset(static::$wordsToNumberCache[$data])) {
44-
return static::$wordsToNumberCache[$data];
43+
$key = $data;
44+
if (isset(static::$wordsToNumberCache[$key])) {
45+
return static::$wordsToNumberCache[$key];
4546
}
4647

4748
$wordsToValue = [
@@ -139,17 +140,17 @@ function ($val) {
139140
$last = $part;
140141
}
141142

142-
return static::$wordsToNumberCache[$data] = (int) ($sum + $stack->pop());
143+
return static::$wordsToNumberCache[$key] = (int) ($sum + $stack->pop());
143144
}
144145

145146
/**
146-
* Convert a studly case string to space separated words.
147+
* Convert a camel case string to space separated words.
147148
*
148149
* @param string $string
149150
*
150151
* @return string
151152
*/
152-
public static function studlyToSpaceSeparated(string $string): string
153+
public static function camelToSpaceSeparated(string $string): string
153154
{
154155
$words = array_map(function ($word) {
155156
return strtolower($word);

src/Traits/SupportsDynamicCalls.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private static function allowedSuffixes(): array
3030
*/
3131
public static function dynamicCall($methodName): int
3232
{
33-
$wordsInMethodName = explode(' ', Str::studlyToSpaceSeparated($methodName));
33+
$wordsInMethodName = explode(' ', Str::camelToSpaceSeparated($methodName));
3434
$suffix = end($wordsInMethodName);
3535

3636
if (! in_array($suffix, static::allowedSuffixes())) {

tests/Units/StrTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
}
3939
});
4040

41-
it('can correctly convert studly to space separated', function () {
42-
$studlyCaseToSpaceSeparated = [
41+
it('can correctly convert camel to space separated', function () {
42+
$camelCaseToSpaceSeparated = [
4343
'thisIsALongWord' => 'this is a long word',
4444
'thisIsALongWordWithNumbers' => 'this is a long word with numbers',
4545
'thisIsALongWordWithNumbersAndSymbols' => 'this is a long word with numbers and symbols',
4646
'iNeedAJob' => 'i need a job',
4747
];
4848

49-
foreach ($studlyCaseToSpaceSeparated as $studly => $space) {
50-
expect(Str::studlyToSpaceSeparated($studly))->toBe($space);
49+
foreach ($camelCaseToSpaceSeparated as $camel => $space) {
50+
expect(Str::camelToSpaceSeparated($camel))->toBe($space);
5151
}
5252
});

0 commit comments

Comments
 (0)