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

private functions in rules may be better as protected #655

Closed
buggedcom opened this issue Mar 16, 2016 · 3 comments
Closed

private functions in rules may be better as protected #655

buggedcom opened this issue Mar 16, 2016 · 3 comments

Comments

@buggedcom
Copy link

Is there a reason, or have you considered using protected functions in rules instead of private ones. The reason I ask is that I would to create a child classed based on KeySet called NonStrictKeySet that allowed to specify a set of keys that should exist, but also allow anything else to exist too.

The problem is that when overloading the hasValidStructure function, because it is private the child classes overloaded function is not seen by the parent class. Having the function as protected would have allowed this and meant that I would not have needed to duplicate the entire code of KeySet aside 1 line.

@henriquemoody
Copy link
Member

I believe that everything is private until there is a reason to make it public or protected.

Since the KeySet is a concrete rule, there is no reason to have protected properties nor methods. If that's the case, we should created something like AbstractKeySet and then extend it on KeySet and NonStrictKeySet.

However, as I see, NonStrictKeySet is not even necessary, since if have a chain of key() rules, it validates only the present keys, anything else can exist with no problem, they are just not validated. Or maybe I didn't understand you, if that's the case, can you elaborate?

@henriquemoody
Copy link
Member

I'm closing issues that are too old, and I'm not really looking at them all. If this is still relevant, please comment here and I will reopen this issue.

Thanks for reporting! 🐼

@kakenbok
Copy link

testing needs more access

Just upgraded to v2 and now try to figure out how to deal with the accessibility changes ... :-)

I need some inspection possibilities to auto-generate test fixtures. For example, I generate a more complex object graph:

obj1:type1
- [obj3:type2, obj3:type2]
- obj4:type3

I make sure that all of these objects are valid using code like this:

$rules = $obj3->validator->getRules();

foreach ($rules as $rule) {
    if ($rule instanceof Length) {
        if ($rule->minValue && $rule->minValue > 1) {
            $min = $rule->minValue;
        }
    }
}

$obj3->title = $this->fakeWord($min);

Any idea how to accomplish such an inspection now ... without using reflection?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants