Passed
Pull Request — main (#138)
by Andrey
12:48
created

Validation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 14
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateType() 0 8 3
1
<?php
2
3
namespace Helldar\Support\Concerns;
4
5
use Helldar\Support\Exceptions\ForbiddenVariableTypeException;
6
use Helldar\Support\Facades\Helpers\Str;
7
8
trait Validation
9
{
10
    /**
11
     * @param  mixed  $haystack
12
     * @param  array|string  $needles
13
     */
14
    protected function validateType($haystack, $needles): void
15
    {
16
        $type = gettype($haystack);
17
18
        if (! Str::contains($type, $needles)) {
19
            $needles = is_array($needles) ? implode(', ', $needles) : $needles;
20
21
            throw new ForbiddenVariableTypeException($type, $needles);
22
        }
23
    }
24
}
25