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

Use default options in constraint docs #4144

Closed
webmozart opened this issue Aug 18, 2014 · 7 comments
Closed

Use default options in constraint docs #4144

webmozart opened this issue Aug 18, 2014 · 7 comments
Labels
actionable Clear and specific issues ready for anyone to take them. good first issue Ideal for your first contribution! (some Symfony experience may be required) Validator

Comments

@webmozart
Copy link
Contributor

Currently, the basic examples of constraints like GreaterThan don't use the short version for default options:

class Person
{
    /**
     * @Assert\GreaterThan(
     *     value = 18
     * )
     */
    protected $age;
}

The proper (short) way of writing this would be:

class Person
{
    /**
     * @Assert\GreaterThan(18)
     */
    protected $age;
}

I think the "Basic Usage" examples should be fixed in this direction. In addition, a new section "Message Customization" should be added that shows how to write the constraint when customizing the message:

class Person
{
    /**
     * @Assert\GreaterThan(
     *     value = 18,
     *     message = "Restricted to persons older than 18 years."
     * )
     */
    protected $age;
}

The above applies for all configuration styles (annotations, PHP, XML and YAML).

@weaverryan
Copy link
Member

Hey Bernhard!

We show the long way because it's easier to migrate from it to using multiple options (or non-default options) when you need them. I think you outline a way that would show the short way and still the longer way. Personally, I'm kind of a +0. The short syntax looks better and saves you some keystrokes, but I'm uncertain as to how that weighs against the cons (less clarity, harder to know how to use a non-default option).

What do others think?

@xabbuh
Copy link
Member

xabbuh commented Aug 20, 2014

I like the idea of simplifying the basic usage examples. I guess that would make life easier for developers. Though we have to find a way to show how to use them with additional options. Wouldn't it be possible to write a generic chapter for that and link to it from each constraint?

@weaverryan
Copy link
Member

@xabbuh it would be a bit more work, but I'd rather do what Bernhard is showing - show one example with the default value and then immediately after, another example showing more options.

@webmozart
Copy link
Contributor Author

Hey Ryan :) Thanks for your thoughtful response!

less clarity

IMO the shorter version is more clear, as long as you don't use other options. GreaterThan(18) can easily be read out loud.

The point to me is that right now many people don't even know that the short version exists. This should be fixed. As you said, if we show the longer version right after the short example, things should be clear to everyone.

@weaverryan
Copy link
Member

👍

@xabbuh xabbuh added actionable Clear and specific issues ready for anyone to take them. good first issue Ideal for your first contribution! (some Symfony experience may be required) Validator labels Oct 11, 2014
@alexmart
Copy link

I'll give it a try if nobody objects!

xabbuh added a commit that referenced this issue Jun 30, 2016
… (alexmart)

This PR was submitted for the 2.3 branch but it was merged into the 2.7 branch instead (closes #6597).

Discussion
----------

[Validator] Add shorter examples using the default option

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | no
| Applies to    | >= 2.3
| Fixed tickets | #4144

Commits
-------

d3cde84 [Validator] Add shorter examples using the default option
@javiereguiluz
Copy link
Member

Closing as fixed by #6597.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable Clear and specific issues ready for anyone to take them. good first issue Ideal for your first contribution! (some Symfony experience may be required) Validator
Projects
None yet
Development

No branches or pull requests

5 participants