bmitch / Codor

Custom PHPCS sniffs to find Code Smells

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sniff to prevent conditionals in constructors

bmitch opened this issue · comments

Extracted from #71

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