Skip to content

Commit

Permalink
singularize all words not just last one (#6)
Browse files Browse the repository at this point in the history
* singularize all words not just last one
  • Loading branch information
dakorpar authored Mar 6, 2019
1 parent f4dc65d commit 96c1f9b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function getClassName(string $table): string
if (isset($this->config->replacements[$table])) {
return $this->config->replacements[$table];
}
return $this->config->prefix . Inflector::singularize(Inflector::classify($table)) . $this->config->suffix;
return $this->config->prefix . Helper::camelize($table) . $this->config->suffix;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/Generator/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace DodoIt\EntityGenerator\Generator;

use Doctrine\Common\Inflector\Inflector;

class Helper
{

Expand All @@ -20,4 +22,14 @@ public static function multiArrayFlip(array $array): array
return $result;
}

public static function camelize(string $input, string $separator = '_'): string
{
$words = explode($separator, $input);
$result = '';
foreach ($words as $word) {
$result .= Inflector::singularize(ucfirst($word));
}
return $result;
}

}
6 changes: 6 additions & 0 deletions tests/Generator/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ public function testMultiArrayFlip(): void
]);
}

public function testCamelize()
{
$this->assertEquals('User', Helper::camelize('users'));
$this->assertEquals('UserLogin', Helper::camelize('users_logins'));
}

}

0 comments on commit 96c1f9b

Please sign in to comment.