emacs-php / php-mode

A powerful and flexible Emacs major mode for editing PHP scripts
GNU General Public License v3.0
580 stars 118 forks source link

PEAR method chaining wrong indentation #745

Closed cweiske closed 6 months ago

cweiske commented 1 year ago

The PEAR coding standard says in https://pear.php.net/manual/en/standards.funcalls.php

Using fluent application programming interfaces often leads to many concatenated function calls. Those calls may be split onto several lines. When doing this, all subsequent lines are indented by 4 spaces and begin with the "->" arrow.

<?php
$someObject->someFunction("some", "parameter")
->someOtherFunc(23, 42)
->andAThirdFunction();
?> 

On my emacs 27.1 with php-mode 20230423.1446 the second method call arrow is directly below the previous arrow (wrong):

        $pages = $dbOld->createQueryBuilder()
                       ->select('*')

Setting php-mode-lineup-cascaded-calls to nil aligns the -> with the = (wrong):

        $pages = $dbOld->createQueryBuilder()
               ->select('*')

When enabling the pear coding style, it should be indented 4 spaces:

        $pages = $dbOld->createQueryBuilder()
            ->select('*')

(Related to #237, which was the same problem with PSR2)

cweiske commented 1 year ago

It seems that php-mode-lineup-cascaded-calls = nil not working was a problem in my configuration.

So the only thing left is that pear style should set that automatically.


--- PHP-MODE DEBUG BEGIN ---
versions: GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu)
 of 2022-01-24, modified by Debian; PHP Mode v0.1.0-46-g0808b37; Cc Mode 5.34.1)
package-version: nil
major-mode: php-mode
minor-modes: (helm-mode helm-minibuffer-history-mode shell-dirtrack-mode helm--remap-mouse-mode async-bytecomp-package-mode editorconfig-mode cl-old-struct-compat-mode tooltip-mode electric-indent-mode menu-bar-mode file-name-shadow-mod\
e font-lock-mode auto-composition-mode auto-encryption-mode auto-compression-mode column-number-mode line-number-mode transient-mark-mode abbrev-mode)
variables: ((indent-tabs-mode nil) (tab-width 4))
custom variables: ((php-executable /usr/bin/php) (php-site-url https://www.php.net/) (php-manual-url en) (php-search-url nil) (php-completion-file ~/.emacs.d/php/php-completion-file) (php-manual-path ) (php-search-documentation-function\
 php-search-web-documentation) (php-search-documentation-browser-function nil) (php-class-suffix-when-insert ::) (php-namespace-suffix-when-insert \) (php-default-major-mode php-mode) (php-html-template-major-mode web-mode) (php-blade-t\
emplate-major-mode web-mode) (php-template-mode-alist ((\.blade . web-mode) (\.phpt\' . php-mode) (\.phtml\' . web-mode))) (php-mode-maybe-hook nil) (php-default-builtin-web-server-port 3939) (php-imenu-generic-expression php-imenu-gene\
ric-expression-default) (php-re-detect-html-tag php-re-detect-html-tag-default))
c-indentation-style: pear
c-style-variables: ((c-basic-offset 4) (c-comment-only-line-offset 0) (c-indent-comment-alist ((anchored-comment column . 0) (end-block space . 1) (cpp-end-block space . 2))) (c-indent-comments-syntactically-p nil) (c-block-comment-pref\
ix * ) (c-comment-prefix-regexp ((pike-mode . //+!?\|\**) (awk-mode . #+) (other . //+\|\**))) (c-cleanup-list (scope-operator)) (c-hanging-braces-alist ((brace-list-open) (brace-entry-open) (statement-cont) (substatement-open after) (b\
lock-close . c-snug-do-while) (extern-lang-open after) (namespace-open after) (module-open after) (composition-open after) (inexpr-class-open after) (inexpr-class-close before) (arglist-cont-nonempty))) (c-hanging-colons-alist nil) (c-h\
anging-semi&comma-criteria (c-semi&comma-inside-parenlist)) (c-backslash-column 48) (c-backslash-max-column 72) (c-special-indent-hook nil) (c-label-minimum-indentation 1))
c-doc-comment-style: ((java-mode . javadoc) (pike-mode . autodoc) (c-mode . gtkdoc) (c++-mode . gtkdoc))
c-offsets-alist: ((inexpr-class . 0) (inexpr-statement . +) (lambda-intro-cont . +) (inlambda . 0) (template-args-cont c-lineup-template-args +) (incomposition . +) (inmodule . +) (innamespace . +) (inextern-lang . +) (composition-close\
 . 0) (module-close . 0) (namespace-close . 0) (extern-lang-close . 0) (composition-open . 0) (module-open . 0) (namespace-open . 0) (extern-lang-open . 0) (objc-method-call-cont c-lineup-ObjC-method-call-colons c-lineup-ObjC-method-cal\
l +) (objc-method-args-cont . c-lineup-ObjC-method-args) (objc-method-intro . [0]) (friend . 0) (cpp-define-intro c-lineup-cpp-define +) (cpp-macro-cont . +) (cpp-macro . [0]) (inclass . +) (stream-op . c-lineup-streamop) (arglist-cont-\
nonempty first php-lineup-cascaded-calls php-c-lineup-arglist) (arglist-cont first php-lineup-cascaded-calls 0) (comment-intro . 0) (catch-clause . 0) (else-clause . 0) (do-while-closure . 0) (access-label . -) (case-label . 0) (substat\
ement . +) (statement-case-intro . +) (statement . 0) (brace-entry-open . 0) (brace-list-entry . 0) (brace-list-close . 0) (block-close . 0) (block-open . 0) (inher-cont . c-lineup-multi-inher) (inher-intro . +) (member-init-cont . c-li\
neup-multi-inher) (member-init-intro . +) (annotation-var-cont . +) (annotation-top-cont . 0) (topmost-intro . 0) (knr-argdecl . 0) (func-decl-cont . +) (inline-close . 0) (class-close . 0) (class-open . 0) (defun-block-intro . +) (defu\
n-close . 0) (defun-open . 0) (c . c-lineup-C-comments) (string . c-lineup-dont-change) (topmost-intro-cont first php-lineup-cascaded-calls +) (brace-list-intro . +) (brace-list-open . 0) (inline-open . 0) (arglist-close . 0) (arglist-i\
ntro . +) (statement-cont first php-lineup-cascaded-calls php-lineup-string-cont +) (statement-case-open . 0) (label . +) (substatement-label . 2) (substatement-open . 0) (knr-argdecl-intro . +) (statement-block-intro . +))
buffer: (:length 1357)
--- PHP-MODE DEBUG END ---
cweiske commented 1 year ago

The bug does actually exist if the code has an equal sign. Wrong:

$pages = $foo->bar()
       ->baz();

I would expect this:

$pages = $foo->bar()
    ->baz();

Using (c-offsets-alist . ((statement-cont . +))) instead of (c-offsets-alist . ((case-label . 0))) seems to work, but I'm not sure about the implications.

cweiske commented 1 year ago

@zonuexe please reopen - only one problem is solved with #746, but not the identation-after-= one.

zonuexe commented 6 months ago

@cweiske Perhaps merging #777 resolved this issue. This problem seems to have been introduced by some strange change in the past unrelated to the PEAR Coding Standards. Please feel free to send any feedback regarding PEAR style to #776.

Thank you for your report!

cweiske commented 6 months ago

This is fixed - thank you!