Skip to content

Commit 202a209

Browse files
committed
Convert submodule to regular files for release
1 parent 49d29e3 commit 202a209

File tree

10 files changed

+232
-5
lines changed

10 files changed

+232
-5
lines changed

.gitmodules

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
[submodule "phpstorm-attributes"]
2-
path = meta/attributes/public
3-
url = [email protected]:JetBrains/phpstorm-attributes.git
4-
branch = master

meta/attributes/public

Lines changed: 0 additions & 1 deletion
This file was deleted.

meta/attributes/public/ArrayShape.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace JetBrains\PhpStorm;
4+
5+
use Attribute;
6+
7+
/**
8+
* The attribute specifies possible array keys and their types.
9+
*
10+
* If applied, an IDE will suggest the specified array keys, infer the specified types, and highlight non-specified keys in array access expressions.
11+
*
12+
* Array shapes should be specified with the required $shape parameter whose values should be array literals.<br />
13+
*
14+
* Example: <br />
15+
* <b>#[ArrayShape(["f" => "int", "string", "x" => "float"])]</b>
16+
* This usage applied on an element effectively means that the array has 3 dimensions, the keys are "f", 1, and "x", and the corresponding types are "int", "string", and "float".
17+
*/
18+
#[Attribute(Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER | Attribute::TARGET_PROPERTY)]
19+
class ArrayShape {
20+
public function __construct(array $shape)
21+
{
22+
}
23+
}

meta/attributes/public/Deprecated.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace JetBrains\PhpStorm;
4+
5+
use Attribute;
6+
7+
#[Attribute(Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD | Attribute::TARGET_CLASS | Attribute::TARGET_CLASS_CONSTANT | Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
8+
class Deprecated {
9+
public const PHP_VERSIONS = [
10+
"5.3",
11+
"5.4",
12+
"5.5",
13+
"5.6",
14+
"7.0",
15+
"7.1",
16+
"7.2",
17+
"7.3",
18+
"7.4",
19+
"8.0",
20+
"8.1",
21+
"8.2",
22+
"8.3",
23+
"8.4",
24+
];
25+
26+
/**
27+
* Mark element as deprecated
28+
*
29+
* @param string $reason Reason for deprecation. It will be displayed by PhpStorm via the Deprecated inspection instead of the default message
30+
* @param string $replacement Applicable only to function/method calls: IDE will suggest replacing a deprecated function call with the provided code template.
31+
* The following variables are available in this template:
32+
* <ul>
33+
* <li>%parametersList%: parameters of the function call. For example, for the "f(1,2)" call, %parametersList% will be "1,2"</li>
34+
* <li>%parameter0%,%parameter1%,%parameter2%,...: parameters of the function call. For example, for the "f(1,2)" call, %parameter1% will be "2"</li>
35+
* <li>%name%: For "\x\f(1,2)", %name% will be "\x\f", for "$this->ff()", %name% will be "ff"</li>
36+
* <li>%class%: If the attribute is provided for method "m", then for "$this->f()->m()", %class% will be "$this->f()"</li>
37+
* </ul>
38+
* The following example shows how to wrap a function call in another call and swap arguments:<br />
39+
* "#[Deprecated(replacement: "wrappedCall(%name%(%parameter1%, %parameter0%))")] f($a, $b){}<br />
40+
* f(1,2) will be replaced with wrappedCall(f(2,1))
41+
* @param string $since Element is deprecated starting with the provided PHP language level, applicable only for PhpStorm stubs entries
42+
*/
43+
public function __construct($reason = "", $replacement = "",
44+
#[ExpectedValues(self::PHP_VERSIONS)] $since = "5.6")
45+
{
46+
}
47+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace JetBrains\PhpStorm;
4+
5+
use Attribute;
6+
7+
/**
8+
* The attribute specifies the expected values of an entity: return values for functions and arguments' values for methods.
9+
*
10+
* If the attribute is applied, PhpStorm assumes that only the arguments specified in the attribute constructor can
11+
* be passed/returned. This will affect the following:
12+
* <ul>
13+
* <li><i>Code completion</i> - expected arguments are displayed on the top of the suggestions list when used in comparison expressions</li>
14+
* <li><i>Inspections [when used in a comparison with a value/assignment to/return from method]</i> - the element absent from the expected values list produces the inspection warning</li>
15+
* <li><i>Code generation</i> - for example, when generating the 'switch' statement, all possible expected values are inserted automatically</li>
16+
* </ul>
17+
*
18+
* Expected values can be any of the following:
19+
* <ul>
20+
* <li>numbers</li>
21+
* <li>string literals</li>
22+
* <li>constant references</li>
23+
* <li>class constant references</li>
24+
* </ul>
25+
*
26+
* Expected arguments can be specified in any of the following ways:
27+
* <ul>
28+
* <li><b>#[ExpectedValues(values: [1,2,3])]</b> means that one of the following is expected: `1`, `2`, or `3`</li>
29+
* <li><b>#[ExpectedValues(values: MY_CONST]</b> - default value of MY_CONST is expected to be array creation expression, in this case value of MY_CONST will be inlined</li>
30+
* <li><b>#[ExpectedValues(flags: [1,2,3])]</b> means that a bitmask of the following is expected: `1`, `2`, or `3`</li>
31+
* <li><b>#[ExpectedValues(valuesFromClass: MyClass::class)]</b> means that one of the constants from the class `MyClass` is expected</li>
32+
* <li><b>#[ExpectedValues(flagsFromClass: ExpectedValues::class)]</b> means that a bitmask of the constants from the class `MyClass` is expected</li>
33+
* </ul>
34+
*
35+
* The attribute with the number of provided constructor arguments different from 1 will result in undefined behavior.
36+
* @since 8.0
37+
*/
38+
#[Attribute(Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER | Attribute::TARGET_PROPERTY)]
39+
class ExpectedValues {
40+
public function __construct(array $values = [], array $flags = [], ?string $valuesFromClass = null, ?string $flagsFromClass = null)
41+
{
42+
}
43+
}

meta/attributes/public/Immutable.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace JetBrains\PhpStorm;
4+
5+
use Attribute;
6+
7+
/**
8+
* Mark a property (or all class properties in the case of a class) as immutable.
9+
* By default, an IDE highlights write accesses on such properties if they are located outside a constructor (this scope is customizable, see below).
10+
*
11+
* You can provide a custom allowed write scope by using the following values:
12+
* <ul>
13+
* <li>{@link Immutable::CONSTRUCTOR_WRITE_SCOPE}: write is allowed only in containing class constructor (default choice)</li>
14+
* <li>{@link Immutable::PRIVATE_WRITE_SCOPE}: write is allowed only in places where the property would be accessible if it had 'private' visibility modifier</li>
15+
* <li>{@link Immutable::PROTECTED_WRITE_SCOPE}: write is allowed only in places where the property would be accessible if it had 'protected' visibility modifier</li>
16+
* </ul>
17+
* @since 8.0
18+
*/
19+
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_CLASS)]
20+
class Immutable
21+
{
22+
const CONSTRUCTOR_WRITE_SCOPE = "constructor";
23+
const PRIVATE_WRITE_SCOPE = "private";
24+
const PROTECTED_WRITE_SCOPE = "protected";
25+
26+
public function __construct(#[ExpectedValues(valuesFromClass: Immutable::class)]
27+
$allowedWriteScope = self::CONSTRUCTOR_WRITE_SCOPE)
28+
{
29+
}
30+
}

meta/attributes/public/Language.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace JetBrains\PhpStorm;
4+
5+
use Attribute;
6+
7+
/**
8+
* Specifies that the parameter is a string that represents source code in a different language.
9+
* An IDE will automatically inject the specified language into the passed string literals.
10+
*
11+
* @since 8.0
12+
*/
13+
#[Attribute(Attribute::TARGET_PARAMETER)]
14+
class Language {
15+
/**
16+
* @param string $languageName Language name like "PHP", "SQL", "RegExp", etc...
17+
*/
18+
public function __construct(string $languageName)
19+
{
20+
}
21+
}

meta/attributes/public/NoReturn.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace JetBrains\PhpStorm;
4+
5+
use Attribute;
6+
7+
/**
8+
* You can use this facility to mark the function as halting the execution flow.
9+
* Such marked functions will be treated like die() or exit() calls by control flow inspections.
10+
* In most cases, just annotation function with 0 arguments will work.
11+
* To mark the function as the exit point only when it's called with some constant arguments, specify them in $arguments param
12+
*
13+
* {@see NoReturn::ANY_ARGUMENT}
14+
*/
15+
#[Attribute(Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD)]
16+
class NoReturn {
17+
/**
18+
* Use this constant to skip function argument on the specified position
19+
*/
20+
public const ANY_ARGUMENT = 1;
21+
22+
public function __construct(...$arguments)
23+
{
24+
}
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace JetBrains\PhpStorm;
4+
5+
use Attribute;
6+
7+
/**
8+
* The attribute specifies possible object field names and their types.
9+
*
10+
* If applied, an IDE will suggest the specified field names and infer the specified types.
11+
*
12+
* Example:
13+
* <pre>#[ObjectShape(["age" => "int", "name" => "string"])]</pre>
14+
*
15+
* This usage applied on an element effectively means that the object has 2 fields, the names are <code>"age"</code> and <code>"name"</code>, and the corresponding types are <code>"int"</code> and <code>"string"</code>.
16+
*/
17+
#[Attribute(Attribute::TARGET_FUNCTION|Attribute::TARGET_METHOD|Attribute::TARGET_PARAMETER|Attribute::TARGET_PROPERTY)]
18+
class ObjectShape
19+
{
20+
public function __construct(array $shape) {}
21+
}

meta/attributes/public/Pure.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace JetBrains\PhpStorm;
4+
5+
use Attribute;
6+
7+
/**
8+
* The attribute marks the function that has no impact on the program state or passed parameters used after the function execution.
9+
* This means that a function call that resolves to such a function can be safely removed if the execution result is not used in code afterwards.
10+
*
11+
* @since 8.0
12+
*/
13+
#[Attribute(Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD)]
14+
class Pure
15+
{
16+
/**
17+
* @param bool $mayDependOnGlobalScope Whether the function result may be dependendent on anything except passed variables
18+
*/
19+
public function __construct(bool $mayDependOnGlobalScope = false)
20+
{
21+
}
22+
}

0 commit comments

Comments
 (0)