• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

diego-ninja / granite / 16608963009

29 Jul 2025 10:37PM UTC coverage: 50.423%. First build
16608963009

Pull #5

github

web-flow
Merge 43d8840d7 into 6a6caca51
Pull Request #5: code: adds phpstan level max, pint with per and github actions

321 of 632 new or added lines in 77 files covered. (50.79%)

1132 of 2245 relevant lines covered (50.42%)

9.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.92
/src/Validation/Rules/In.php
1
<?php
2

3
namespace Ninja\Granite\Validation\Rules;
4

5
class In extends AbstractRule
6
{
7
    /**
8
     * Constructor.
9
     *
10
     * @param array $values Allowed values
11
     */
12
    public function __construct(
41✔
13
        private readonly array $values,
14
    ) {}
41✔
15

16
    /**
17
     * Check if the value is one of the allowed values.
18
     *
19
     * @param mixed $value
20
     * @param array|null $allData
21
     * @return bool Whether the value is valid
22
     */
23
    public function validate(mixed $value, ?array $allData = null): bool
36✔
24
    {
25
        return null === $value || in_array($value, $this->values, true);
36✔
26
    }
27

28
    /**
29
     * Get the default error message.
30
     *
31
     * @param string $property Property name being validated
32
     * @return string Default error message
33
     */
34
    protected function defaultMessage(string $property): string
1✔
35
    {
36
        $valuesList = implode(', ', array_map(function ($val) {
1✔
37
            if (is_string($val)) {
1✔
38
                return "'{$val}'";
1✔
39
            }
NEW
40
            if (is_scalar($val) || (is_object($val) && method_exists($val, '__toString'))) {
×
NEW
41
                return (string) $val;
×
42
            }
NEW
43
            return 'non-displayable';
×
44
        }, $this->values));
1✔
45

46
        return sprintf("%s must be one of: %s", $property, $valuesList);
1✔
47
    }
48
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc