Codor icon indicating copy to clipboard operation
Codor copied to clipboard

Sniff to prevent conditionals in constructors

Open bmitch opened this issue 8 years ago • 1 comments

Extracted from #71

bmitch avatar May 30 '17 23:05 bmitch

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;
    }
}

Exadra37 avatar Aug 05 '17 11:08 Exadra37