【问题标题】:Is there any code standards for PHP using multiple calls and arguments?是否有使用多个调用和参数的 PHP 代码标准?
【发布时间】:2016-07-26 12:11:06
【问题描述】:

我正在使用 Doctrine,并且在 PHP 中有这一行:

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

我想知道是否有任何代码标准用于设置具有多个调用的行。我浏览了 Symphony 和其他一些 PSR,但找不到任何具体的东西。

【问题讨论】:

    标签: php code-standards


    【解决方案1】:

    PSR 目前没有指定它们。我通常在链接方法时采用 jQuery 方法,例如,每个链接都在自己的行上缩进。所以,以你的代码为例,我会做这样的事情:

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

    但话说回来,有些人会觉得它丑陋,有些人不会:)它是 PHP,毕竟没有其他语言会产生如此多的混合意见 :)

    【讨论】:

    • 我同意.. 但话又说回来,在一个有这么多不同人编码的环境中工作,有一些事情可以跟进会很好。遇到这样的问题,它只有 2 条线并且正在逃逸我的 22 英寸显示器。顺便说一句,没有一个能指定这么多?
    猜你喜欢
    • 1970-01-01
    • 2011-11-26
    • 1970-01-01
    • 1970-01-01
    • 2016-06-23
    • 2022-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多