Hi Dan

On Wed, Sep 6, 2017 at 8:38 PM, Dan Ackroyd <dan...@basereality.com> wrote:

> On 6 September 2017 at 12:15, Rowan Collins <rowan.coll...@gmail.com>
> wrote:
>
> > If you have suggestions for how the format should look
>
> Don't use a format. Just write code - see below.
>
> > Which is why Yasuo and I have both suggested we work together
>
> If you're going to work together and continue the conversation, please
> can you move this conversation elsewhere?
>
> It doesn't appear to be actually anything to do with PHP internals.
>
> On 4 September 2017 at 07:33, Yasuo Ohgaki <yohg...@ohgaki.net> wrote:
> >
> > Since I didn't get much feedbacks during the RFC discussion, I cannot
> tell
> > what part is disliked.
>
> Yes you did. You got feedback during the discussion and also during
> the vote. For example: http://news.php.net/php.internals/95164
>
> However you continually choose to ignore that feedback.
>
> I will attempt once more, to get the main point through to you.
> Perhaps a small amount of repetition, will get it through:
>
> This type of library should be done in PHP, not in C.
> This type of library should be done in PHP, not in C.
> This type of library should be done in PHP, not in C.
> This type of library should be done in PHP, not in C.
> This type of library should be done in PHP, not in C.
> This type of library should be done in PHP, not in C.
> This type of library should be done in PHP, not in C.
> This type of library should be done in PHP, not in C.
> This type of library should be done in PHP, not in C.
> This type of library should be done in PHP, not in C.
> This type of library should be done in PHP, not in C.
>
> cheers
> Dan
> Ack
>
>
> function validateOrderAmount($value) : int {
>     $count = preg_match("/[^0-9]*/", $value);
>
>     if ($count) {
>         throw new InvalidOrderAmount("The order value must contain
> only digits.");
>     }
>
>     $value = intval($value);
>
>     if ($value < 1) {
>         throw new InvalidOrderAmount("The order value must be one or
> more.");
>     }
>
>     if ($value >= MAX_ORDER_AMOUNT) {
>         throw new InvalidOrderAmount(
>         "Order value to big. Maximum allowed value is ".MAX_ORDER_AMOUNT
>         );
>     }
>
>     return $value;
> }
>


You seems mixing up responsibility between
 - Input validation that should be input handling code's responsibility.
 - Logical validation that should be model code's responsibility .

Please stick to single responsibility principle that you should be well
aware of.
Input handling code should only accepts valid inputs and let other codes
use it.
Other responsibilities are not input handling code's responsibilities.

Your example code should be in logic, not input handling, that is written
by PHP script.

As I wrote in README.md, there are only 3 types of inputs.

 1. Valid data should accepted.
 2. Valid data should accepted, but user's mistake. e.g. Logical error like
your example above.
 3. Invalid. Anything other than 1 and 2 (i.e. Client cannot send these
value)

"validate" module is supposed to take care 3 which is nothing to do with
models, etc.
It should validate against input data spec, not logical meaning of the
input. If
programmer did this, single responsibility principle is broken.

Regards,

--
Yasuo Ohgaki
yohg...@ohgaki.net

Reply via email to