Symfony rest endpoint for get a number products of one user
$productListUser = $this-&gt;em-&gt;getRepository(ProductAdmin::class)
                             -&gt;findProductsUser(...


Than

public function findProductsUser(UserInterface $user, int $number) :?array
    {

        $listProductUser = $this-&gt;em-&gt;getRepository(ProductAdmin::class)-&gt;findBy(...


seems to me that findProductsUser is method of whatever is returned by $em-&gt;getRepository(ProductAdmin::class) why is that method retrieving itself from entity manager? Shouldn't it be just $this-&gt;findBy(...?

Further, the responsibility of formatting the entity should not be done by the repository. You need to either wrap the repository with the formatter into another class, or do it in the controller. Also there is no reason why the formatter must be a trait. Make it a service and inject it to the entire controller through contructor if all methods of the controller need it, or have it injected in an action method, like you do with Security, BeamAPI, etc...