CoffeeCodeDataRepository::find()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 17
rs 10
1
<?php
2
3
namespace GiovanniALO\DataValidation\Repository;
4
5
use CoffeeCode\DataLayer\DataLayer;
6
7
class CoffeeCodeDataRepository implements DataRepository
8
{
9
    /**
10
     * @param  string  $namespace
11
     * @param  string  $terms
12
     * @param  array|string|null  $params
13
     * @return mixed
14
     * @throws \Exception
15
     */
16
    public function find(
17
        string $namespace,
18
        string $terms,
19
        array|string|null $params = null
20
    ): mixed {
21
        if (!class_exists($namespace)) {
22
            throw new \Exception("{$namespace} não é um modelo DataLayer válido");
23
        }
24
25
        if ($params && is_array($params)) {
26
            $params = http_build_query($params);
27
        }
28
29
        /** @var DataLayer $model */
30
        $model = new $namespace();
31
32
        return $model->find($terms, $params)->fetch();
33
    }
34
}
35