{"action":"created","issue":{"url":"https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/547","repository_url":"https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards","labels_url":"https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/547/labels{/name}","comments_url":"https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/547/comments","events_url":"https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/547/events","html_url":"https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/547","id":143862083,"number":547,"title":"Spacing for Return Types","user":{"login":"GaryJones","id":88371,"avatar_url":"https://avatars2.githubusercontent.com/u/88371?v=4","gravatar_id":"","url":"https://api.github.com/users/GaryJones","html_url":"https://github.com/GaryJones","followers_url":"https://api.github.com/users/GaryJones/followers","following_url":"https://api.github.com/users/GaryJones/following{/other_user}","gists_url":"https://api.github.com/users/GaryJones/gists{/gist_id}","starred_url":"https://api.github.com/users/GaryJones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GaryJones/subscriptions","organizations_url":"https://api.github.com/users/GaryJones/orgs","repos_url":"https://api.github.com/users/GaryJones/repos","events_url":"https://api.github.com/users/GaryJones/events{/privacy}","received_events_url":"https://api.github.com/users/GaryJones/received_events","type":"User","site_admin":false},"labels":[{"id":197939849,"url":"https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/labels/Type:%20Enhancement","name":"Type: Enhancement","color":"84b6eb","default":false},{"id":197940028,"url":"https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/labels/Type:%20Question","name":"Type: Question","color":"cc317c","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-03-28T00:02:07Z","updated_at":"2017-08-03T22:33:15Z","closed_at":null,"body":"For PHP 7, the format for adding return types appears to be of the format:\n\n`function foo( $arg ): array {`\n\nThis format of characters and whitespace between `)` and `{` can be seen in examples on:\n- [PHP Manual](http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration)\n- [PHP Return Type RFC](https://wiki.php.net/rfc/return_types)\n- Draft [PSR-12](https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md#45-method-and-function-arguments)\n- [SitePoint](http://www.sitepoint.com/php-7-revolution-return-types-removed-artifacts/) example.\n- [This blog post](https://blog.engineyard.com/2015/what-to-expect-php-7)\n- [And this blog post](https://blog.feryn.eu/php-7-is-now-available-new-features-improvements/) (which has no space after the return type.)\n\nJust for a counter-argument, [this post](https://www.digitalocean.com/company/blog/getting-ready-for-php-7/) puts a space before the `:`.\n\nRegardless, the current WPCS flags up `):` as `Expected one space after closing parenthesis`. It doesn't flag up no space between the return type and `{`.\n\nWe, as WPCS, either need to make a decision that `): array {` is correct for the WordPress community, or that particular combination of characters / tokens should be excluded from whitespace checks until TPTB have updated the coding standards.\n"},"comment":{"url":"https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/comments/320107927","html_url":"https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/547#issuecomment-320107927","issue_url":"https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/547","id":320107927,"user":{"login":"GaryJones","id":88371,"avatar_url":"https://avatars2.githubusercontent.com/u/88371?v=4","gravatar_id":"","url":"https://api.github.com/users/GaryJones","html_url":"https://github.com/GaryJones","followers_url":"https://api.github.com/users/GaryJones/followers","following_url":"https://api.github.com/users/GaryJones/following{/other_user}","gists_url":"https://api.github.com/users/GaryJones/gists{/gist_id}","starred_url":"https://api.github.com/users/GaryJones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GaryJones/subscriptions","organizations_url":"https://api.github.com/users/GaryJones/orgs","repos_url":"https://api.github.com/users/GaryJones/repos","events_url":"https://api.github.com/users/GaryJones/events{/privacy}","received_events_url":"https://api.github.com/users/GaryJones/received_events","type":"User","site_admin":false},"created_at":"2017-08-03T22:33:15Z","updated_at":"2017-08-03T22:33:15Z","body":"Most of the rest of the PHP World uses no space for return types, but the WP historical code style would suggest using a space.\r\n\r\n> Always put spaces after commas, and on both sides of logical, comparison, string and assignment operators.\r\n> -- https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#space-usage\r\n\r\nMy preference, is that for something \"relatively\" new (and not yet found in WP core, or many plugins) that there's a good case for sticking with no-space:\r\n\r\n- default auto-formatting by IDEs just works - many may not even have an option to include a space there,\r\n- examples in WP and PHP tutorials match,\r\n- possibly able to inherit a sniff from an existing standard to check this, instead of having to write a current one (which in turn means it could be added to a ruleset far quicker and adopted consistently in the community).\r\n\r\nIn terms of the space before the `:` for the return type, the Handbook explicitly says that the `case` in a switch block must have no space before the colon (and likewise for the CSS standards), so there is prior-art in WP core for having no space before colons (as well as the rest of the PHP community).\r\n\r\n----\r\n\r\nAlong the same lines and with exactly the same arguments, there is also:\r\n\r\n```php\r\ndeclare(strict_types=1);\r\n```\r\n\r\n```php\r\ndeclare( strict_types = 1 );\r\n```\r\n\r\nAs well as the points I mentioned above for keeping with no-space, the extra argument here is that this isn't going to vary massively - there's only something like three possible values to go inside `declare()`, so it is very much a boilerplate flag, rather than logic that needs readability.\r\n\r\n`declare( strict_types = 0 )` would be redundant AFAIK, so the only realistic value is `1`. That, therefore, doesn't make it logic in the intent that the existing Handbook sentence was written; the logic is \"is there statement there or not\", not what the parts of it are.\r\n\r\nIt's also always going to be at the top of the file, probably with a clear line space before any `namespace` or `use` statements, well away from any other blocks of code, so I can't see that readability is an issue.\r\n\r\nI agree that exceptions make for a bad approach to writing standards.\r\n\r\nBut then, the existing Handbook already has inconsistencies. Space usage of `['a']` vs `[ $a ]`, lack of spaces around type-casts like `(array)`, trailing comma usage of single-line vs multi-line arrays etc. All of them are in the middle of business logic. What I'm referring to is a declare statement at the top of a file.\r\n"}}
{"actor":{"display_login":"GaryJones"}}