Skip to content

Remove static from GraphQL\Validator\Rules\ValuesOfCorrectType #851

Closed

Description

@wimski

A lot of static methods are used in ValuesOfCorrectType, but when I take a closer look I can't see why. There seems to be no added benefit in having these static. Would it be possible to remove all the static usage from this class?

The reason I ask is because I want to extend it in order to change the way some error messages are created. This feels related to #711, but I want to do more than a simple string replacement.

Activity

  1. spawnia commented on Apr 26, 2021

    @spawnia
    Collaborator

    There seems to be no added benefit in having these static.

    Those methods can be called without class instantiation, this is done from tests. How would removing static improve extensibility?

    I think the deciciding difference is in how those methods are called. self::method() prevents overrides, while static::method() works.

  2. wimski commented on Apr 26, 2021

    @wimski
    ContributorAuthor

    Those methods can be called without class instantiation, this is done from tests.

    So the only reason they are static is because of tests?

    I think the deciciding difference is in how those methods are called. self::method() prevents overrides, while static::method() works.

    Then replacing self with static would also work for my case.

  3. spawnia commented on Apr 26, 2021

    @spawnia
    Collaborator

    So the only reason they are static is because of tests?

    I just named one reason, there may be many.

    Another one I can think of right now is that static methods are generally easier to reason about; one does (generally) not have to worry about state with them.

    Then replacing self with static would also work for my case.

    Yes. Accepting PRs, but preferrably one that opens up all validation rules for extensibility to ensure consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions