Giter Club home page Giter Club logo

Comments (2)

wivaku avatar wivaku commented on August 25, 2024 1

Thanks Tom! Your PHP knowledge is impressive (and you fast responses are appreciated).

Here's my attempt at creating those two (example) methods:

/**
 * @method static self companyA()
 * @method static self companyB()
 * @method static self companyC()
 * @method static self companyAandC()
 */
final class CompanyEnum extends Enum
{
    protected static function obsolete(): array
    {
        return [
          'companyA' => 'merged with company C',
          'companyC' => 'merged with company A',
        ];
    }

    public static function toObsolete() {
        return method_exists(__CLASS__,'obsolete') ? self::obsolete() : [];
    }

    public static function toValidValues() {
        return array_values( array_diff(
            self::toValues(),
            array_keys(self::toObsolete())
        ) );
    }
}

from laravel-enum.

Gummibeer avatar Gummibeer commented on August 25, 2024

Hey,

the only way would be the @deprecated doc-tag - but this doesn't accept arguments and as we use magic methods you can't attach it to a real method.
https://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.deprecated.pkg.html

With PHP8.1 this will be possible as you have a real case COMPANY_A you can add a doc-tag to.
But you can add these two static methods you named your own to the enum in question and do some array_filter, array_diff or whatever logic to reduce it to the ones you want there.

from laravel-enum.

Related Issues (20)

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.