Answer the question
In order to leave comments, you need to log in
What can be the * ovnocode here?
Hello, when a colleague saw the method in the controller, he said that it was one solid code, it was the code itself, explain to me, maybe I'm not from our world? As far as I'm concerned, everything is fine.
public function getIndex()
{
$title = 'Мои компании';
$where = array('uid' => Sentry::getUser()->id);
if (Input::has('status')) $where['status'] = (Input::get('status') ? 1 : 2);
$company_list = new CompanyList();
$company = $company_list->get($where)->paginate(1);
return View::make('dashboard.account', compact('title'))->with(array(
'company' => $company
));
}
Answer the question
In order to leave comments, you need to log in
1) Code formatting is terrible. Let's start with this.
2) what does the title do in the controller?
3) what are 1 and 2, what do they mean? It is worth replacing with constants at least.
4) for a couple of years you can use shorthand array syntax
5) You have IoC, why are you calling new CompanyList()? What does this even refer to? What's happening?
In short ... horror ... the controller is the place where it should be clear what is happening there. Something like this:
class CompanyListController {
/**
* @var CompanyRepositoryInterface
*/
private $companyRepository;
function __construct(CompanyRepositoryInterface $companyRepository)
{
$this->companyRepository = $companyRepository;
}
public function getIndex()
{
$companies = $this
->companyRepository
->getCompanyByUser(Sentry::getUser()->id, Input::get('status', false))
;
return View::make('dashboard.account')->with(compact('companies'));
}
At a minimum:
- a mix of CamelCase and snake_case,
- a mix of compact() and View::make->with().
It all depends on many factors, including the preferences of your colleague and the rules of coding established in your company. Find out the details first from your colleague, and then you will probably have a bunch of questions of an existential nature regarding code design issues, after finding the answers to which, you will develop your own style that you can justify to anyone and are unlikely to seek to ask such questions here. .. :)
if (Input::has('status')) $where['status'] = (Input::get('status') ? 1 : 2);
This piece is strangely formatted somehow, I only caught up with what was happening here after 2 minutes)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question