GithubHelp home page GithubHelp logo

jeffersonsimaogoncalves / phpstorm-attributes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jetbrains/phpstorm-attributes

1.0 0.0 0.0 12 KB

PhpStorm specific attributes

Home Page: https://packagist.org/packages/jetbrains/phpstorm-attributes

License: Apache License 2.0

PHP 100.00%

phpstorm-attributes's Introduction

PhpStorm attributes

Use these PHP 8 attributes in PhpStorm to get more advanced code completion and analysis.

Learn more in the blog post.

Installation

The attributes are available in PhpStorm 2020.3 and later. They are bundled with PhpStorm so you don’t need to install them separately.

If you are using other static analysis tools and don’t want to get Class not found issues, then you might want to add the attributes package to your composer.json as a dev dependency:

composer require --dev jetbrains/phpstorm-attributes

#[Deprecated]

Use this attribute when you want to notify users that an entity will be removed in the future.

Provide the explanation tip in reason and updating suggestion in replacement.

#[Deprecated(
    reason: 'since Symfony 5.2, use setPublic() instead',
    replacement: '%class%->setPublic(!%parameter0%)'
)]

Deprecated

#[ArrayShape]

Use Array Shape when you deal with object-like arrays and want to specify the keys’ names and types for values to get better coding assistance.

#[ArrayShape([
 // ‘key’ => ’type’,
    ‘key1’ => ‘int’,
    ‘key2’ => ‘string’,
    ‘key3’ => ‘Foo’,
    ‘key3’ => App\PHP 8\Foo::class,
])]
function functionName(...): array

The attribute works with PHP ≤ 7.4 if specified in one line.

ArrayShape

#[Immutable]

Mark properties or entire objects with this attribute if you want to guarantee they won't be changed after initialization.

#[Immutable]
class DTO
{
    public string $val;

    public function __construct(string $val)
    {
        $this->val = $val;
    }
}

The attribute works with PHP ≤ 7.4 if specified in one line.

Immutable

#[Pure]

Use this attribute for functions that do not produce any side effects. All such PHP internal functions are already marked in PhpStorm.

#[Pure]
function compare(Foo $a, Foo $b): int
{
    return $a->a <=> $b->b;
}

Pure

#[ExpectedValues]

Use this attribute to specify which values exactly a function accepts as parameters and which it can return. This will improve coding assistance.

function response(
    #[ExpectedValues(valuesFromClass: Response::class)] $httpStatusCode,
    //...
) {
    //...
}

ExpectedValues

#[NoReturn]

Mark functions that terminate script execution as exit points with this attribute to get a more accurate control flow analysis.

#[NoReturn]
function redirect(): void {
   //...
   exit();
}

NoReturn

#[Language]

Add this attribute to mark string parameters that contain text in some other [programming] language, for example, RegExp, SQL, and so on. This will improve highlighting and reveal additional features of PhpStorm for you.

Language

Bugs and feature requests

Please report any issues to the PhpStorm issue tracker https://youtrack.jetbrains.com/newIssue?project=WI.

Pull requests are also welcome.

phpstorm-attributes's People

Contributors

pronskiy avatar wbars avatar

Stargazers

 avatar

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.