summaryrefslogtreecommitdiff
path: root/src/Validators/RequiredValidator.php
blob: 488a0acdfbef756e44e70b37a84168236f2505e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

namespace Askonomm\Bouncer\Validators;

/**
 * Implements a length validator that has a job of validating 
 * that a given string is of correct length.
 * 
 * @author Asko Nomm <asko@bien.ee>
 */
class RequiredValidator implements Validator
{
    /**
     * Returns a boolean `true` when given `$value` is present 
     * and not empty. Returns `false` otherwise.
     *
     * @param string $value
     * @param mixed $modifier
     * @return boolean
     */
    public static function validate(mixed $value, mixed $modifier = null): bool
    {
        return isset($value) && $value !== '';
    }

    /**
     * Composes the error message in case the validation fails.
     *
     * @param string $field
     * @param mixed $modifier
     * @return string
     */
    public static function composeError(string $field, mixed $modifier = null): string
    {
        return "${field} is required.";
    }
}