CoffeeCodeDataRepository   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A find() 0 17 4
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