scramble icon indicating copy to clipboard operation
scramble copied to clipboard

Request validation rules documentation based on static analysis instead of `eval`

Open romalytvynenko opened this issue 2 years ago • 1 comments

WIP

fixes #226, fixes #169, fixes #235, fixes #634

This one is another very complex PR, but it ~would allow creating playgrounds for Scramble by making rules evaluation optional and relying on static analysis instead~ will reduce the amount of bugs due to evaluation issues.

To make this possible a bit more features to inference system must be added:

  • [x] Static methods call analysis support
  • [x] Late static binding analysis support (proper handing of static::, self::, __CLASS__)
    • [x] Figure out general approach
    • [x] class const fetching
    • [x] Consts fetching
    • [x] new calls
    • [x] Method calls (static, non-static)
    • [x] Props fetching
  • [x] Consts fetch type inference support
  • [x] Static method calls extensions support
  • [x] Add array_keys function support
  • [x] Inferring type from array value
  • [ ] Inferring type from object value

And to Scramble docs generation:

  • [x] Rule::* methods inference support (via extensions for now)
  • [ ] Rules classes better support
    • [ ] Database rules (exists, unique) and their methods
    • [ ] new Enum|In|* rule creation
  • [ ] New Rules API
  • [ ] Documenting statically analyzed rules (rules type)
  • [ ] Runtime objects -> Types conversion (for class-based rules)

romalytvynenko avatar Sep 26 '23 20:09 romalytvynenko

@romalytvynenko I would enjoy this fix so much :tada:

I'm on same boat as https://github.com/dedoc/scramble/issues/226

benascbr avatar Jan 17 '25 12:01 benascbr

I know this PR has been open a while, but is there anything that could be contributed from the community to bring this into a release?

stefanzweifel avatar May 13 '25 13:05 stefanzweifel

@stefanzweifel the latest Scramble release has error tolerant validation rules evaluation which in most cases will be more efficient than the approach I was going to take with this PR. Have you tried the latest release? If it doesn't work for you, can you tell me more about your use case?

romalytvynenko avatar May 13 '25 15:05 romalytvynenko

@romalytvynenko Nothing specific that results in an error in our current project. Saw the PR and really like the idea of using static analysis.

In our project we were struggling to get the api docs working, as we split our validation rules into instance-specific-request classes; but we could find a solution by using Request::createFrom() to make Scramble happy again.

stefanzweifel avatar May 19 '25 15:05 stefanzweifel

@romalytvynenko thanks for your great work here. :fire:

Is there anything that could be contributed from the community to bring this into a release? I glad to help to complete this PR.

hosni avatar May 28 '25 09:05 hosni

Closing this PR due to many ideas from it were implemented in 0.12.20+ releases.

romalytvynenko avatar Aug 03 '25 09:08 romalytvynenko