Reputation: 685
What kind of name do you use for classes? For Example an user service located in the folder User/Service with the namespace User\Service:
First i prevered using the first option because of the directory, its clear that it is a service. But then i saw the following using my service in for example a controller.
namespace User\Controller;
use User\Service\User;
class UserController {
public function __construct(User $userService) {
...
}
}
At first glance you think you have to inject an user entity to the constructor. Or should i change the use statement to use User\Service\User as UserService? Are there any conventions?
Upvotes: 1
Views: 83
Reputation: 33148
This is subjective, but I normally use User\Service\UserService
for the reasons you describe. With namespaces, you rarely use the full class name, and if you have multiple 'User' classes, it gets a bit confusing, and you end up having to alias everything anyway.
I've seen UserService
used more than the other way, but it's just down to personal preference really.
Upvotes: 2