Symfony2 Service and Trait Best Practices for Small Code Snippets

In Symfony2 (can also be applied to other frameworks), are there any factual best practices defined when putting a small piece of reusable code as a sign as opposed to a service (or even in a model)?

eg. scenario: I had a small piece of code that slightly changed the URL (a specific port was added based on the current environment and the machine). It was used by several controllers. I was told that this would be best, since the service would be redundant, because it was only a few lines of code, and only one parameter was passed to the function (url).

The Symfony2 Guide defines a service as:

"A generic term for any PHP object that performs a specific task.

There may be some subjective opinions, but the question prompts say:

Great subjective questions inspire answers explaining “why” and “how” and “Great subjective questions” insist that opinions be supported with facts and references

And this is what I am looking for. The actual reasons why or why not use the dash over the service for a small piece of code.

Update An excellent offer was: the characteristics are not easy to test, while the services

+3
source share

All Articles