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

ambiguous EnglishInflector result may gives not expected adder/ remover method names #392

Open
PawelSuwinski opened this issue Sep 5, 2022 · 1 comment

Comments

@PawelSuwinski
Copy link
Contributor

Description
Singularized form of adder/remover method name for collections is hardcoded to the first item from the list returned by EnglishInflector:

return $inflector->singularize($string)[0];

If transformation is ambiguous inflector return list of proposition, and in some cases first one it not we want to, for example:

$ php -r 'require "vendor/autoload.php"; echo (new Symfony\Component\String\Inflector\EnglishInflector())->singularize("languages")[0].PHP_EOL;'
languag

How to reproduce

types:
  Book:
    properties:
      languages:
        cardinality: "(1..*)"
        range: Language

gives:

class Book
(...)
   function addLanguag(Language $languag)
   (...)

Possible Solution

  • ability to use alternate inflector class (in.e., decoration of EnglishInflector)
  • give singular form of given property in explicit by additional config paramater
@alanpoulain
Copy link
Member

The generator is using an interface:

public function __construct(InflectorInterface $inflector, PhpTypeConverterInterface $phpTypeConverter, CardinalitiesExtractor $cardinalitiesExtractor, GoodRelationsBridge $goodRelationsBridge)

You can already use an alternate inflector.

However having an additional config parameter could be a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants