V
V
Vitaly Vitaly2015-01-24 14:13:38
Laravel
Vitaly Vitaly, 2015-01-24 14:13:38

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

6 answer(s)
S
Sergey, 2015-01-24
@V_Tjuryakin

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

J
JhaoDa, 2015-01-24
@JhaoDa

At a minimum:
- a mix of CamelCase and snake_case,
- a mix of compact() and View::make->with().

S
Sergey Gladkovskiy, 2015-01-24
@SMGladkovskiy

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. .. :)

O
OnYourLips, 2015-01-24
@OnYourLips

Saving LF characters is shitty code.

R
Rikcon, 2015-01-24
@Rikcon

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)

6
65536, 2015-01-24
@65536

other than that, use autoformat. take a config from a colleague, or wind up your own and always use it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question