Git Product home page Git Product logo

Comments (11)

kukulich avatar kukulich commented on July 28, 2024 3

@mhujer "Typehints for primitive values should be always used" and more should be solved in https://github.com/slevomat/coding-standard/blob/2.0-dev/SlevomatCodingStandard/Sniffs/TypeHints/TypeHintDeclarationSniff.php

from coding-standard.

VasekPurchart avatar VasekPurchart commented on July 28, 2024 1

Yea, I am sure planning add these, we are actively using them, I was just waiting if there would be any potential tweaks and wanted to release it as 1.0, so was finding out if there is something else worth adding/changing/removing.

The rules for PHP 7 stuff:

  • declare(strict_types = 1) on a separate line - this is because i think there will be more of these declarations in the future and also it fits more with the overall Consistence standard, where everything is more structured
<?php

declare(strict_types = 1);

// ...
  • return type hints are the same as parameter typehints, so no FQN
  • return type hints are written with colon just after closing parenthesis and a space after the semicolon:
<?php

function foo(): string
{
    return 'hello';
}

@mhujer I am not sure, what do you mean by

Primitive type hints

?

Also the thing I was still thinking about was if PHP 7.1s nullable types should be marked differently in PHPDocs (perhaps using the ? as well) or if it should be just |null as it was until now. I am inclining to the second variant because there can be more types and also it seems cleaner from the typing point of view.

from coding-standard.

TomasVotruba avatar TomasVotruba commented on July 28, 2024

I this most of those you can find at Slevomat slevomat/coding-standard#53

It is not merged yet though.

from coding-standard.

ondrejmirtes avatar ondrejmirtes commented on July 28, 2024

Yep, we have support for a lot of 7.0 features in the 2.0-dev branch. I'm responsible for finishing and polishing 2.0 but I prioritized working on PHPStan over the holidays :)

You can find out what will be in 2.0 here in this Trello board. Unfortunately PHP 7.1 was released meanwhile so I feel the obligation for the Slevomat CS to also correctly work with 7.1 features.

from coding-standard.

ondrejmirtes avatar ondrejmirtes commented on July 28, 2024

Our Slevomat CS sniff about declaring strict types is configurable, so there can be zero to N lines between PHP opening tag and the declare statement. We personally use 0 lines so it looks like this: <?php declare(strict_types = 1); mainly because this feature was described in the RFC this way and it's the most compact version. Also, if there will be multiple things like this in the future, they will probably fall in a single declare statement, like when you're declaring ticks today.

from coding-standard.

TomasVotruba avatar TomasVotruba commented on July 28, 2024

@VasekPurchart

@mhujer I am not sure, what do you mean by

Primitive type hints

Probably scalar type hints, like string in public function method(string $args).

from coding-standard.

VasekPurchart avatar VasekPurchart commented on July 28, 2024

Yea, but I am not sure if there is anything what should be decided in the scalar parameter type hints :)

from coding-standard.

TomasVotruba avatar TomasVotruba commented on July 28, 2024

I see :)

from coding-standard.

mhujer avatar mhujer commented on July 28, 2024

@ondrejmirtes I'm already using development branch of Slevomat-sniffs because of PHP 7 :-)

@VasekPurchart I meant that the primitive typehints will affect do/don't related to the PHPDoc - https://github.com/consistence/coding-standard/blob/master/consistence-coding-standard.md#methods-without-phpdoc. And also that something like "Typehints for primitive values should be always used" can be added.

from coding-standard.

VasekPurchart avatar VasekPurchart commented on July 28, 2024

I have finally had the time to write this up: #9 PHP 7.0 and 7.1 coding standard rules, in the end I managed to get there also rules for PHP 7.1 (and a few other not mentioned here before).

Please check it if you see some odd things or something that I might have forgotten.

from coding-standard.

mhujer avatar mhujer commented on July 28, 2024

Resolved with 1.0 release https://github.com/consistence/coding-standard/releases/tag/1.0

from coding-standard.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.