When you first start using Symfony you will probably start with the code examples from the official documentation. This is fine and much recommended and I would encourage anyone to do so. These examples are amazing to get a good start in Symfony and provide quick feedback.
After a while though, you should consider to write cleaner and more separated code. Having well structured code will help you immensely to reuse code and write tests.