-
Notifications
You must be signed in to change notification settings - Fork 56
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
Replace inline docblock declarations with assertions #47
Changes from all commits
ab72a32
ebb76f2
c5873a5
f797ff6
c8e32d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -311,6 +311,8 @@ | |||
<rule ref="SlevomatCodingStandard.PHP.UselessParentheses"/> | ||||
<!-- Forbid useless semicolon `;` --> | ||||
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/> | ||||
<!-- Require /* @var type $foo */ and similar simple inline annotations to be replaced by assert() --> | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this sniff support There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not. However it is reported (and fixed) by coding-standard/lib/Doctrine/ruleset.xml Line 200 in e008cac
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible that both can be used? The first one fixing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A CS rule enforcing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Last time I used NetBeans (granted, a while ago), it only supported vardoc syntax ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That changed a long time ago: at the moment, the ecosystem is pushing for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Ocramius Not sure I undrestand you well but the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||
<rule ref="SlevomatCodingStandard.PHP.RequireExplicitAssertion"/> | ||||
<!-- Require use of short versions of scalar types (i.e. int instead of integer) --> | ||||
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/> | ||||
<!-- Require the `null` type hint to be in the last position of annotations --> | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
$simpleType = expression(); | ||
assert($simpleType instanceof Type); | ||
|
||
$typeDeclaredAfterExpression = expression(); | ||
assert($typeDeclaredAfterExpression instanceof Type); | ||
|
||
$typeDeclaredViaAssertion = expression(); | ||
assert($typeDeclaredViaAssertion instanceof Type); | ||
|
||
$unionType = expression(); | ||
assert($unionType instanceof Type1 || $unionType instanceof Type2); | ||
|
||
$intersectionType = expression(); | ||
assert($intersectionType instanceof Type1 && $intersectionType instanceof Type2); | ||
|
||
$nullableType = expression(); | ||
assert($nullableType instanceof Type || $nullableType === null); | ||
|
||
$multipleScalarTypes = expression(); | ||
assert(is_int($multipleScalarTypes) || is_float($multipleScalarTypes) || is_bool($multipleScalarTypes) || is_string($multipleScalarTypes) || is_array($multipleScalarTypes) || $multipleScalarTypes === null); | ||
|
||
/** @var Potato $variableThatIsNowhereToBeFound */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** @var Type $simpleType */ | ||
$simpleType = expression(); | ||
|
||
$typeDeclaredAfterExpression = expression(); | ||
/** @var Type $typeDeclaredAfterExpression */ | ||
|
||
$typeDeclaredViaAssertion = expression(); | ||
assert($typeDeclaredViaAssertion instanceof Type); | ||
|
||
/** @var Type1|Type2 $unionType */ | ||
$unionType = expression(); | ||
|
||
/** @var Type1&Type2 $intersectionType */ | ||
$intersectionType = expression(); | ||
|
||
/** @var Type|null $nullableType */ | ||
$nullableType = expression(); | ||
|
||
/** @var int|float|bool|string|array|null $multipleScalarTypes */ | ||
$multipleScalarTypes = expression(); | ||
|
||
/** @var Potato $variableThatIsNowhereToBeFound */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@malarzm @deeky666 I'm likely raising a separate PR for stable slevomat release pinning by @kukulich.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC pinning a commit could lead to weird side effects where we can end up with vendor requirements from current
dev-master
while code in pinned commit could require something else.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes: this is not for a stable release yet. I'd need a SemVer selector for the release to be tagged.