Passed
Pull Request — master (#32)
by Bruno
08:58
created

Graphql::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Code;
4
5
use Formularium\Exception\ClassNotFoundException;
6
use Formularium\Exception\Exception;
7
use Formularium\Field;
8
use Formularium\Model;
9
10
class Graphql
11
{
12
    public Model $model;
13
    
14
    public function __construct(Model $model)
15
    {
16
        $this->model = $model;
17
    }
18
19
    /**
20
     * Generates a GraphQL query for this model.
21
     *
22
     * @param array $params User supplied list of parameters, which may be used
23
     * to control behavior (like recursion).
24
     * @return string
25
     */
26
    public function generate(array $params = []): string
27
    {
28
        $defs = [];
29
        foreach ($this->model->getFields() as $field) {
30
            /**
31
             * @var Field $field
32
             */
33
            $defs[] = $this->datatype->getGraphqlField($field->getName(), $params);
0 ignored issues
show
Bug Best Practice introduced by
The property datatype does not exist on Formularium\Code\Graphql. Did you maybe forget to declare it?
Loading history...
34
        }
35
        return join("\n", $defs);
36
    }
37
}
38