Sniff to prevent conditionals in constructors
bmitch opened this issue · comments
Bill Mitchell commented
Extracted from #71
Paulo Renato commented
With the exception for Immutable Values Objects constructors should only accept objects and their body we should only see them assigned to private properties.
So calls to collaborators methods, self methods or any other kind of logic MUST NOT be presented in the body of a constructor.
<?php
class UserHandler
{
private $userRepo;
public function __construct(UserRepositoryContract $userRepo)
{
$this->userRepo = $userRepo;
}
}