Search code examples
phpcode-standards

Is there any code standards for PHP using multiple calls and arguments?


I am using Doctrine and have this line in PHP:

    $result = $entityManager->getRepository('Example\Entity\Users')->findOneBy(array(
        'address' => $address->getId(),
        'email' => $email->getEmail(),
        'type' => $type->getId(),
    ));

I would like to know if there is any code standards for setting lines with multiple calls. I looked through the Symphony and some of the others PSRs but couldn't find anything this specific.


Solution

  • PSR currently doesn't specify them. I usually take jQuery approach when chaining methods, e.g., each chain link is on its own line indented. So, using your code as an example, I'd do something like this:

    $result = $entityManager
                ->getRepository('Example\Entity\Users')
                ->findOneBy(
                    array(
                        'address' => $address->getId(),
                        'email'   => $email->getEmail(),
                        'type'    => $type->getId(),
                    )
                );
    

    But then again, some people will find it ugly, some will not :) It's PHP, afterall, no other language generates so many mixed opinions :)