Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumeration #50

Open
jorgecc opened this issue Oct 18, 2018 · 16 comments
Open

Enumeration #50

jorgecc opened this issue Oct 18, 2018 · 16 comments
Assignees
Labels
status: help wanted Backlog type: documentation Not an issue, but rather a document describing how something works type: feature request

Comments

@jorgecc
Copy link

jorgecc commented Oct 18, 2018

Hi there:

I want to know if it's possible to add a feature to simulate enumeration. I tried searching about it and I don't find it. However, I found your library that it's really cool but it's not about enumeration.

For example, something like that

    /**
     * @param $field={ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' }
     */
    public function weekday($field) {...
@klesun
Copy link
Owner

klesun commented Oct 18, 2018

Hi.
I usually write it somehow like this:

    /**
     * @param $field= 'Sun' ?? 'Mon' ?? 'Tue' ?? 'Wed' ?? 'Thu' ?? 'Fri' ?? 'Sat'
     */
    public function weekday($field) {}

image

@klesun
Copy link
Owner

klesun commented Oct 18, 2018

Basically you can write it with any valid php syntax that defines a string:
image

@klesun
Copy link
Owner

klesun commented Oct 18, 2018

Yet another option:
image

@jorgecc
Copy link
Author

jorgecc commented Oct 18, 2018

Thanks, however, it is not visible when you call the function

weekday(''):
rent

@klesun
Copy link
Owner

klesun commented Oct 18, 2018

Oh, yeah, that's actually a feature I was going to implement one day:
#8

Completion of string value passed to the function if this string is used as key name inside

(will actually apply to any string value definition, not just to a key name)
I guess I'll raise it's priority.

@klesun
Copy link
Owner

klesun commented Oct 18, 2018

I'm bad with estimates, but I'll try to implement this by the monday.

@jorgecc
Copy link
Author

jorgecc commented Oct 18, 2018

Thanks.

@klesun
Copy link
Owner

klesun commented Oct 18, 2018

Very basic support is now available in beta release:
https://plugins.jetbrains.com/plugin/9927-deep-assoc-completion/update/51243
image

@King2500
Copy link

What is this [$i] meaning at the end of the list?
Looks a little "special" to me.

@klesun
Copy link
Owner

klesun commented Oct 23, 2018

An undefined variable =-D. A tricky way to tell plugin that $field can be any of the values in the array. Plugin treats unresolved variables/functions as anything, and when you take an anything index from array, you get any value in the array. You can basically write any valid php expression instead of $i, for example rand(), $anyKey or -100.

@berkayunal
Copy link

berkayunal commented Feb 21, 2019

Hi @klesun

How can we autocomplete an option with the enums?

For example:

FileHelper::directories(APPPATH, ["sort_by"=>"modified_time");

sc

Thanks for your help and for this great plugin!

@klesun klesun added status: in progress type: documentation Not an issue, but rather a document describing how something works labels Feb 21, 2019
klesun added a commit that referenced this issue Feb 21, 2019
Not just when you pass this string directly to a function
klesun added a commit that referenced this issue Feb 21, 2019
@klesun
Copy link
Owner

klesun commented Feb 21, 2019

Hi @berkayunal
I did not implement the completion of enum in an array key before I read your comment.
Just posted an update: 2019.02.21.001
Now you should get completion here:
image
And here:
image

@berkayunal
Copy link

Hi @klesun,

Rockin! Thanks for the update 👍

@cmp-nct
Copy link

cmp-nct commented Jan 23, 2023

The array numeration for function params stopped working for me with one of the previous phpstorm updates
tried invalidate caches, didn't help
also tried to up all depths to maximum, maybe something broke

@MatteoOreficeGS
Copy link

It seems also this is supported for props

class MyClass {
    /**
     * @var $tipoCheck = 'passivo' ?? 'attivo'
     */
    private $tipoCheck  = '';

@sfinktah
Copy link

I can't speak to @cmp-nct's claim that it stopped working, what I currently get works, but is also annoyingly including numbers (as many as there are array elements).

image

class {
  public static array $availableOutputSelectors = [
      'ParentSKU', 'ID', 'Brand', 'Model', 'Virtual', 'Name', 'PrimarySupplier', 'Approved', 'IsActive',
      // ... 
  ];

  /** @param array $outputSelectors = [static::$availableOutputSelectors[$any], static::$availableOutputSelectors[$any], ... x 100 
  public function withOutputSelectors(array $outputSelectors): static {
      $this->outputSelectors = array_unique(array_merge($this->outputSelectors, $outputSelectors));
      return $this;
  }

Slightly more complex example as I need to accept an infinite amount of parameters (or array elements) and I couldn't find a neater way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted Backlog type: documentation Not an issue, but rather a document describing how something works type: feature request
Projects
None yet
Development

No branches or pull requests

7 participants