Giter VIP home page Giter VIP logo

phpstan-enum's Introduction

Enum class reflection extension for PHPStan

Packagist Version GitHub Workflow Status

This extension defines dynamic methods for MyCLabs\Enum\Enum subclasses.

Usage

To use this extension, require it with Composer

composer require --dev timeweb/phpstan-enum

If you also install phpstan/extension-installer then you're all set!

Manual installation

If you don't want to use phpstan/extension-installer, include extension.neon in your project's PHPStan config:

includes:
  - vendor/timeweb/phpstan-enum/extension.neon

Install for Local Development

With docker

git clone [email protected]:timeweb/phpstan-enum.git
cd phpstan-enum
make docker-build
make install
make phpunit

Without docker (localy installed actual version of php, composer, etc)

git clone [email protected]:timeweb/phpstan-enum.git
cd phpstan-enum
make install
make phpunit

phpstan-enum's People

Contributors

anwinged avatar babeuloula avatar burned42 avatar dmitrivereshchagin avatar jdecool avatar jeroenvanoort avatar juntereiner avatar ondrejmirtes avatar rincler avatar samizdam avatar shadowhand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpstan-enum's Issues

Add rule to check for checking value in `match` or `switch` instruction

Example:

/**
 * @extends Enum<int>
 */
class MyEnum extends Enum
{
    public const FOO = 1;
    public const BAR = 2;

    public function getLabel(): string {
        return match ($this->value) {
            self::FOO => 'foo-value',
            self::BAR => 'bar-value',
        };
    }
}

Will output errors because it phpstan consider that values from ]-ING;0] and [3;+INF] are not checked.

Looking for maintainers ?

I'm interesting to help maintaining this plugin.

Are you looking for new maintainers ? I will be happy to help you.

Class Timeweb\PHPStan\Rule\EnumAlwaysUsedConstants not found.

After updating from 2.2.4 to 2.3.0 I got this exception when running phpstan:

In Resolver.php line 110:
Service '0366': Class Timeweb\PHPStan\Rule\EnumAlwaysUsedConstants not found.

The mentioned class does indeed not exist, but there's a class Timeweb\PHPStan\Rule\EnumAlwaysUsedConstantsExtension (introduced in #18). When adjusting the class name in extension.neon phpstan runs fine.

Add NoDuplicateEnumValue rule

it could be interesting to add rule that check the enum values are unique.

class MyEnum extends Enum
{
    public const FOO = 1;
    public const BAR = 2;
}

Update packagist hooks

It seems integration between packagist and this repo is no longer working. Packagist reports 2.0.1 as the newest version while 2.1 is the current tag.

Prepare for PHPStan 1.0

Hello everyone ๐Ÿ‘‹

I announced today that PHPStan 1.0 is going to be released on November 1st 2021.

I'm approaching you as one of the most popular PHPStan extensions. I'd love if you could prepare your code for PHPStan 1.0 in advance so that it's ready to release on the same day.

Here's a brief guide how to approach the upgrade:

  1. Create a branch ๐ŸŒด
  2. Update your composer.json to "phpstan/phpstan": "^1.0", add "minimum-stability": "dev" and "prefer-stable": true if necessary.
  3. Update your code with the BC breaks below in mind. ๐Ÿ”ง
  4. Fix the code so that it passes PHPStan's analysis ๐Ÿค“
  5. Wait for PHPStan 1.0 release on November 1st, merge your branch and tag the next major version ๐Ÿ‘

Thank you!


Here are the BC breaks. The list is huge but most of those have very little impact.

There are new rules around using PHPStan internals in regard to backward compatibility promise: https://phpstan.org/developing-extensions/backward-compatibility-promise

It's possible that not everything you use is covered by it - so I'm here to help you to transition to correct usage, or add some @api annotations in PHPStan itself so that more is covered by the promise. Let me know!

BC breaks for end-users

The following are interesting only if you create a custom ruleset in your configuration file:

BC breaks for extension developers

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.