Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add return type rule for closures #1090

Merged
merged 2 commits into from Oct 10, 2018

Conversation

Jean85
Copy link
Member

@Jean85 Jean85 commented Oct 10, 2018

As suggested on Twitter, we should explicitly state how the return type of a closure should be formatted. I've followed (and cited) the same rule as for normal functions/methods.

@BackEndTea
Copy link

How about adding an example with a return type as well?

@KorvinSzanto KorvinSzanto merged commit ddf899f into master Oct 10, 2018
@Jean85 Jean85 deleted the Jean85-psr-12-closures-with-return-type branch October 12, 2018 08:21
sa-tasche pushed a commit to mitgedanken/php-standard-fig that referenced this pull request Sep 24, 2019
* Add previous PSR-5 contributors to meta doc

* Fixed typo: 'a an' -> 'an'

* Add interfaces from the packages.

* Add links to the polls in the metadoc.

* PSR-19: Change GPL-2.0+ to GPL-2.0-or-later

The SPDX identifier `GPL-2.0+` was deprecated. See https://spdx.org/news/news/2018/01/license-list-30-released

* Revise docblock.

* Docblock revision.

* Add rule for increment/decrement operator (php-fig#1089)

As suggested by @MarkBaker [on the ML](https://groups.google.com/d/topic/php-fig/eGClHHNj0JM/discussion), it's reasonable to ask for no whitspace in the case of increment / decrement operators.

* Add return type rule for closures (php-fig#1090)

* Add return type rule for closures

* Add example closure with return type

* Added two paragraphs about middleware and decorating classes

* use `$this->authorizationMap` instead of `$authorizationMap`

* fixes Liskov pluarlity (php-fig#1094)

* be more specific about third party libraries respecting the specification (php-fig#1095)

* Fixed the menu order (php-fig#1091)

* add naming rationale to metadoc (php-fig#1096)

* add naming rationale to metadoc

* reword ambiguous phrase

* remove double space

* a/an (php-fig#1098)

* revert deprecation of link tag

* fix link markdown

* fix 4.3 toc

* match heading name with toc

* remove references to generics

* add links to entrance vote

* Add intersection type.

* consistent case of headings

* Add Intersection type example

* Replace Phing representative

Related to php-fig/www.php-fig.org#228

* Correct summary format

As per PSR-5 standards.

* Move PSR-18 as accepted

* Add implementations references

* Slight grammar cleanup on proposed implementations

* Remove PSR-18 duplicate from review table

* Fix markdown table

* Fix links to PSR-5 and PSR-18 in index

* Describe the format of $_FILES correctly

When the input element's name is a nested array, then format of $_FILES
is more complicated as the nested key names appear underneath the five
_FILES core array element names.

* Update PSR-18-http-client.md

title matches now classname

* Correct summary format

* Require summary to be separated

As per discussion on the mailing list [1], requires that a summary be
separated from other content by two line breaks.

[1]: https://groups.google.com/d/msg/php-fig/59qEeX-VkZU/ZpErzi1fBgAJ

* deprecate double closing brace on inline internal tag

* drop SHOULD to MAY regarding historical }} closing braces

* just use blanket Throwable

* add descriptions of the `@property-read` and `@property-write` variants; replace example with a simpler, more typical example

* corrections per comments

* indicate literal class/trait

* add iterable type

* add iterable to ABNF

* callable is no longer pseudo

* PSR-2 format fix

* remove trailing whitespace

* var syntax does not include variable name

* element is an overloaded term in this example

* remove mentions of Inline PHPDocs for now

* mark four tags as approved by WG

* Migrate to PullApprove v3

* Refactor the PullApprove configuration to v3

* Disable review requests in PullApprove

* Fix PullApprove security group config

* Set secretaries as fallback reviewers

* Revert to PullApprove v2

* Revert back to PullApprove v3; fix conditions as per dropseed/pullapprove-support#120

* Compress PullApprove v3 rules

* Fix PullApprove v3 condition for secretary

* Fix PullApprove v3 condition for secretary, bis

* remove category tag altogether

* remove global tag completely

* remove subpackage tag completely

* remove license tag completely

* remove File-level docblocks altogether

* fix embedded bookmarks

* remove concept of Inline PHPDoc

* remove ending version for deprecated tag

* updates to api tag

* updates to internal tag

* remove references to internal tag' old double-closing-brace syntax

* remove example tag completely

* add braces to inline link syntax

* remove WG approval markers

* explain Name optionality for param tag

* slight adjustments in method tag

* slight adjustments in property tag

* Remove Symfony

* Use Https in Neos and update to recent Flow link

* Clarify that the deprecated version is effective from the given version

* add jaapio to wg

* Move Symfony to former members table

* Remove spaces

* change phpstan rep

* Fix misspelling of "lightweight"

Change "lighweight" to "lightweight" in point 8

* fix typo

* Update the spec proper for the discussed simplification.

* Remove the remainder of Task mentions in the spec.

* Revise meta doc for the simplified approach.

* Add clarifications regarding the dispatch() method return type.

* have - Change the verb form.

The plural verb "have" does not appear to agree with the singular subject "PHP".

* consists - Verify preposition usage

It appears that there is amissing preposition after the word "consists".

* therefore - Add the comma(s)

It appears that you are missing a comma or two with the interrupter "therefore".

* one-per-line - Remove the comma

It appears that you have an unnecessary comma in a compound subject.

* Otherwise - Add a comma

It appears that you are missing a comma after the introductory phrase "Otherwise".

* declarations - Add a comma

It appears that you are missing a comma after the introductory phrase "In nullable type declarations".

* look - Remove the comma

It appears that you have an unnecessary comma in a compound predicate.

* Various language and clarity improvements based on WG feedback.

* Further refinement.

* PSR-14: Provide examples of "high-ceremony" usage

Per discussion within the PSR-14 working group, this patch provides an
explanation of what is meant by the phrase "high-ceremony", along with
implementation examples and narrative that demonstrate the concept in
the specific context of stopping event propagation.

* qa: expand on $returnedEvent ramifications

Per @Crell, this patch expands on the ramifications of `! $returnedEvent instanceof $event`.

* Add link to promise definition.

* Clarify that propagation should be checked before a listener is called, not after.

* Clarify handling of secondary processing from listeners and providers.

* Typo fix.

* Combine paragraphs.

* Fix syntax error

`}` -> `)`.

* Final passthrough on PSR-14

This is my final passthrough on PSR-14. In particular, I looked for the following:

- consistent casing of defined terms. In a few cases, they were left lower-case when it was clear they were referring to a broader definition.
- removal of "that is" phrases. These are a weird idiom, and better phrasing exists in almost every case, even if just dropping to the latin `i.e.`.
- rephrasing where the language was actively getting in the way of understanding.

I plan to do a review of the patch to detail some of the decisions before asking for a review by a WG member.

* Removes another "that is"

* Fix wording around Dispatcher definition

Wording is as discussed during review.

* Clarify Listener return values in relation to Dispatcher

Per conversation during review, we agreed that SHOULD is appropriate for
indicating the suggested void return of listeners, but that dispatchers
MUST disregard any return values from listeners.

This will allow for BC operations that wrap listeners such as the following:

```php
function (object $event) use (/*callable*/ $listener, /*callable*/ $until) : void
{
    $return = $listener($event);
    if ($until($return)) {
        $event->stopPropagation(true);
    }
}
```

without making them explicitly incompatible.

* Revise wording around event identification.

* Fix capitalization.

* Fix code example in PSR-14 example

Add a `void` type hint to the listener example, as the listener SHOULD have a type hint and we want to show the best practice.

* Require type compatible checking.

* Fix minor formatting in headlines + lists

* [PSR-12] Added type casting rule (php-fig#1141)

* [PSR-12] Covered typed properties (php-fig#1144)

* [PSR-12] Covered variadic arguments (php-fig#1142)

* Move type-safe-listener verification statement to the Dispatcher section.

* Move type-as-recommended-distinguisher description to the Providers section.

* Fix typo.

* Move PSR-12 into review

PSR-12 has passed a review readiness vote: https://groups.google.com/d/msg/php-fig/pSGAZowCmHQ/w_FWTcT1FQAJ

* Update .pullapprove.yml

* Update PSR-14 status to Review

* PSR-12: removed unclear statement about unary operators

* extraneous 'the'

* 'MAY' implies spec here, but it's actually just an example being described

* Fix CC terms

* Fix PSR-14 title

* rephrase the delegate example with a thin wrapper

* remove promise exception line as this should not necessary be an exception

* simplify the delegate example with a thin wrapper by keeping only the important part

* improve the phrase syntax a bit by specifying that there is an object wrapped, for clarification

* PSR 12: minor grammatical fix / declare statements

The sentence was grammatically incomplete.

* PSR-12: minor clarification / object declarations

This sentence - as it was - would appear to contradict the first statement in the same section `The extends and implements keywords MUST be declared on the same line as the class name.`

Adding the `, in the case of interfaces,` snippet, takes away the contradiction as interfaces cannot _implement_.

* PSR-12: minor correction / multi-line do-while

A `do-while` statement cannot have the closing parenthesis and opening brace on one line as the closing parenthesis should be followed by a semi-colon, not an opening brace.

* Accept PSR-14

* Align the accepted PSR's table

* aligned word order

`Exception or Error` vs `Error or Exception`

* PSR-12: typos and formatting

* [PSR-12] Punctuation and articles

* restructuring around operators

- remove "excluding `!` which is unary" - unnecessary clarification when `~`, `+` (identity), `-` (negation) are not listed 
- typecasting in PHP is a unary operation - relocating under operators
- removing `insteadof` and `as` from operators - formatting already explained elsewhere 
- moving pipe for multiple exceptions from operators to the `try-catch-finally` section
- restructuring operators section to be grouped by arity

* style rules around optional middle operand of conditional operator

* Update 5.1 to reflect changes to main doc

* Remove new rule around binary ?: variant

* [PSR-12] Added missing control structures statement

See https://groups.google.com/forum/#!topic/php-fig/p94Hef2_ymA

* [PSR-12] Revert article usage (php-fig#1163)

* Update personnel page as per May elections results

* Remove mention of appendix a

Because there is no appendix a

* Refactor PSR-15 meta relevant links to fix website

* Fix typos in documentation/specifications

* psr-12 is approved

* Fix name

* Move PSR-2 to deprecated

* PSR-6 code highlighting

* Update PSR-6-cache.md

* Mark PSR-2 as Deprecated

* "Would" does not exist in RFC 2119

* Missing full stop

* Add example for increment/decrement operators spacing

* Update PSR-6-cache.md

* Fix position of full stop

I presume it should be in front of `PSR-12`, otherwise I don't see any sense in these two sentences.

* [PSR-12] Multiple small impact updates: (php-fig#1183)

- wording/grammar
- new lines coherence
- examples enrichment matching given enumerated domains of application
- italics for word reference quoting
- added exceptions for HEREDOC/NOWDOC to trailing spaces
- switched to ordered list for PHP header file order listing to better reflect ordering
- updated wording to better reflect internal references
- added proposed complements for unary operators needing clarification (especially regarding the ambigous "- $a" / "-$a")

* Revert "[PSR-12] Multiple small impact updates: (php-fig#1183)"

This reverts commit 47bf944.

* Revert "Merge pull request php-fig#1185 from gmponos/patch-1"

This reverts commit ba77fc5, reversing
changes made to 2264dd8.

* Restyled by prettier-markdown


Co-authored-by: Chuck Burgess <ashnazg@php.net>
Co-authored-by: Alessandro Lai <alessandro.lai85@gmail.com>
Co-authored-by: Chris Kankiewicz <Chris@ChrisKankiewicz.com>
Co-authored-by: Larry Garfield <larry@garfieldtech.com>
Co-authored-by: Gary Jones <gary@garyjones.co.uk>
Co-authored-by: Cees-Jan Kiewiet <ceesjank@gmail.com>
Co-authored-by: Tobias Nyholm <tobias.nyholm@gmail.com>
Co-authored-by: Barun <kharelbarun@gmail.com>
Co-authored-by: Margaret Staples <margaret.staples@gmail.com>
Co-authored-by: dantleech <dan.t.leech@gmail.com>
Co-authored-by: David Buchmann <david@liip.ch>
Co-authored-by: Stefano Torresi <stefano@torresi.io>
Co-authored-by: null <37014314+cyrilverloop@users.noreply.github.com>
Co-authored-by: Siad Ardroumli <siad.ardroumli@gmail.com>
Co-authored-by: Ian Littman <iansltx@gmail.com>
Co-authored-by: Woody Gilk <woody.gilk@gmail.com>
Co-authored-by: Rob Allen <rob@akrabat.com>
Co-authored-by: tom tomsen <tom.tomsen@mailbox.org>
Co-authored-by: Rasmus Schultz <rasmus@mindplay.dk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants