• Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language
    Java
  • License
    MIT License
  • Created over 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Support generics types in PhpStorm via psalm / phpstan docblock

IntelliJ IDEA / PhpStorm PHPStan / Psalm / Generics

Use Replacements:

Build Status Version Downloads Downloads last month Donate to this project using Paypal

Key Value
Plugin url https://plugins.jetbrains.com/plugin/12754-php-generics
Id de.espend.idea.php.generics
Changelog CHANGELOG

!!! Work in progress !!!

Supported

types

/**
 * @[psalm-|phpstan-]template T
 * @[psalm-|phpstan-]param class-string<T> $class
 * @[psalm-|phpstan-]return T
 */
function instantiator(string $class) {
    return new $class();
}

class Foo {}

$a = instantiator(Foo::class); // Psalm knows the result is an object of type Foo

class-string

  • Inspections for not given wrong parameter
    /**
     * @[psalm-|phpstan-]template T as Exception
     * @[psalm-|phpstan-]param T::class $type
     * @return T
     */
    function a(string $type): Exception
    {
        return new $type;
    }

templates

    $collection = new FooCollection();
    
    // its now a type of "Foobar"
    $foobar = $collection->getValue();
    $foobar->get<caret>Foobar(); // method is clickable and autocompletes
    /**
     * @[psalm-|phpstan-]template T
     */
    class Collection
    {
        /**
         * @[psalm-|phpstan-]return T
         */
        public function getValue() {}
    }

    /**
     * @[psalm-|phpstan-]extends Collection<Foobar>
     */
    class FooCollection extends Collection {}

    class Foobar
    {
        public function getFoobar() {}
    }

Object-like arrays

https://psalm.dev/docs/annotating_code/type_syntax/array_types/

    a(['<caret>' => ''])
    /**
     * @[psalm-|phpstan-]param array{foo: string, bar: int} $type
     */
    function a(array $type): Exception
    {
    }

psalm-immutable and psalm-readonly

Inspection to show disallowed write access

class PsalmReadOnly {
    /**
     * @psalm-readonly
     */
    public string $readOnly;
}

/**
 * @psalm-immutable
 */
class PsalmImmutable {
    public string $readOnly;
}

Follows into errors hints

(new PsalmReadOnly())->readOnly = 'test';
(new PsalmImmutable())->readOnly = 'test';

Quality Tools

Provides support for quality tools inspection via directly call PHPStan or Psalm reporting via codestyle format

Limitation / Issues

Screenshots

class-string Object-like arrays Psalm Immutable Quality Tool Template Types

TODO

https://youtrack.jetbrains.com/issue/WI-47158

/**
 * @template T
 */
class Map
{
    /**
     * @param array<string, T>
     */
    public function __construct(array $data = []) {}
    /**
     * @return T
     */
    public function get(string $key) {}
    /**
     * @param T $value
     */
    public function set(string $key, $value): void {}
}
// Automatically inferred as Map<string>
$map = new Map([0 => 'Foo', 1 => 'Bar']);
$map->set(2, true); // Expected string

https://youtrack.jetbrains.com/issue/WI-45248

    class Assert
    {
        /**
         * @psalm-template ExpectedType of object
         * @psalm-param class-string<ExpectedType> $class
         * @psalm-assert ExpectedType $value
         */
        public static function isInstanceOf($value, $class, $message = '')
        {
        }
    }

phpstan/phpdoc-parser#30

/**
* @param array{'foo': int, "bar": string} $a
* @param array{0: int, 1?: int} $a
* @param array{int, int} $a
* @param array{foo: int, bar: string} $a
* @param array{foo:string, bar:?int} $a
*/

Others

 /** @var array<int, string> */

More Repositories

1

crypto-trading-bot

Cryptocurrency trading bot in javascript for Bitfinex, Bitmex, Binance, Bybit ... (public edition)
JavaScript
2,787
star
2

idea-php-symfony2-plugin

IntelliJ IDEA / PhpStorm Symfony Plugin
Java
896
star
3

idea-php-laravel-plugin

Laravel Framework Plugin for PhpStorm / IntelliJ IDEA
Java
571
star
4

uniswap-arbitrage-flash-swap

Uniswap flash swap arbitrage solidity contracts
JavaScript
385
star
5

idea-android-studio-plugin

Android Studio Plugin
Java
291
star
6

idea-php-annotation-plugin

Add PHP annotation support for PhpStorm and IntelliJ
Java
242
star
7

idea-php-toolbox

Collections of tools and improvements to make PhpStorm a little bit better
Java
157
star
8

idea-php-shopware-plugin

Shopware Plugin for PhpStorm which extends Symfony Plugin
Java
55
star
9

idea-php-symfony2-plugin-doc

Documentation only !!! for idea-php-symfony2-plugin
Python
49
star
10

idea-php-drupal-symfony2-bridge

PhpStorm plugin to support Symfony components inside Drupal 8
Java
34
star
11

idea-php-toolbox-json-files

PHP
25
star
12

torrent-announcer

Can simulate torrent client requests to a tracker and returns client ips
PHP
17
star
13

idea-php-oxid-plugin

Oxid Plugin for PhpStorm
Java
14
star
14

node-js-crypto-technical-analysis-candlestick-webserver

Candlestick Technical Analysis Http Server based on node.js
JavaScript
10
star
15

drupal-packagist

Provides a Composer packagist page for Drupal projects
PHP
8
star
16

behat-placeholder-extension

Behat placeholder extension
PHP
5
star
17

bittorrent-tracker

Simple BitTorrent Tracker / Proxy
PHP
5
star
18

solidity-multicall-contract

Contract to aggregate multiple contract web3-rpc requests into single request chunks
Solidity
4
star
19

idea-php-behat-plugin

IntelliJ IDEA / PhpStorm Behat Enhancement
Java
4
star
20

ZendDbBundle

Bundle that wraps ZendDb to Symfony2 and Doctrine
PHP
3
star
21

tgudy

TYPO3 Template and Extension
JavaScript
3
star
22

idea-localization-plugin

Extended translation / localization support for PhpStorm / IntelliJ for formats like XLF, XLIFF
Java
3
star
23

espend.de--Delicous-Bookmarks

Main Drupal module that works on b.espend.de to export HTML from Delicous Bookmarks
PHP
2
star
24

e2-fb

Facebook client for Enigma2 / Dreambox
Python
2
star
25

vavoo-iptv-stream-proxy

JavaScript
2
star
26

idea-twig-plugin

PhpStorm / IntelliJ Twig Extended Plugin improvements extracted from Symfony Plugin
Kotlin
2
star
27

Onlinestreams-for-D-Box2

Mediaportal für Neutrino (D-Box2) mit Interface für Popcorn Hour Geräte: einfacher "OnlineStream Proxy" auf Basis des internen Movieplayers. Enthalten Scripts: Youtube, ZDFMediathek, MyVideo, Apple Trailer, Spiegel.TV, kino.de, Tv-Total.de alle in PHP
PHP
2
star
28

idea-badge

Provides badges support for statistics of IntelliJ IDEA / PhpStorm Plugin Repository
PHP
2
star
29

jquery.csspanel

A panel to manipulate simple CSS styles
PHP
1
star
30

http-segmenter

Stream video to your iPhone, iPad, iPod, iOS over http
C
1
star
31

autodesk-inventor-plot-class

This class does some plotting stuff for Autodesk Inventor
Visual Basic
1
star
32

jetbrains-enterprise-plugin-repository

XML API Project for a custom JetBrains Enterprise Plugin Repository
PHP
1
star
33

MyTubeExt

MyTubeExt - Devel fork of MyTube Enigma2 Extension
Python
1
star
34

idea-php-code-usage

Exports a PHP file structure to JSON
Java
1
star
35

vbnettools

Some VB.NET projects like HamachiBroadcastFixGUI
Visual Basic
1
star
36

autodesk-inventor-printbuttons

Configurable toolbar for Autodesk Inventor for plot and print on single button click
Visual Basic
1
star
37

sharemybox.net-enigma2-client

Python Client for sharemybox.net Dreambox and Enigma2 based receiver
Python
1
star
38

idea-php-symfony2-plugin-test

Symfony2 Standard Edition to reflect features and provide tests of PhpStorm Plugin
PHP
1
star