How do I read source code that eventually leads back to an interface?

Posted 4 months ago by ryanmortier

Whenever I'm trying to figure out how something works and it leads back to an interface, I get lost.

For example, I was trying to figure out how the Str::plural() method works and if it supported non-Americanized English.

Step 1: Look up the Illuminate\Support\Str class. Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Str.php

Step 2: Find the plural() method. Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Str.php#L278-L281

Step 3: See that it's using a Pluralizer class so find that. Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Pluralizer.php

Step 4: Find the plural() method on the Pluralizer class. Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Pluralizer.php#L65-L74

Step 5: See that it's using Doctrine's Inflector class so find that. Done: https://github.com/doctrine/inflector/blob/master/lib/Doctrine/Inflector/Inflector.php

Step 6: Find the pluralize() method on the Inflector class. Done: https://github.com/doctrine/inflector/blob/master/lib/Doctrine/Inflector/Inflector.php#L502-L505

Step 7: See that it's calling an inflect() method on a pluralizer object so try to find what the pluralizer object is. Done: It appears to be some type of instance of a WordInflector interface.

Now how do I go from here? I have no idea what the object is being passed that implements the WordInflector interface.

Please sign in or create an account to participate in this conversation.