Passed
Push — master ( ea62c3...cd2ef0 )
by Bruno
09:11
created

ValidatorMetadata::toGraphql()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 18
rs 9.8666
1
<?php declare(strict_types=1);
2
3
namespace Formularium;
4
5
use Formularium\Exception\ClassNotFoundException;
6
use Formularium\Exception\ValidatorException;
7
8
/**
9
 * Abstract base classe to validate data in composition to the validation in
10
 * datatypes.
11
 */
12
class ValidatorMetadata
13
{
14
    public $name;
15
16
    public $comment;
17
18
    /**
19
     * @var ValidatorArgs[]
20
     */
21
    public $args;
22
23
    public function __construct(string $name, string $comment, array $args = [])
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

23
    public function __construct(string $name, string $comment, /** @scrutinizer ignore-unused */ array $args = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
    {
25
        $this->name = $name;
26
        $this->comment = $comment;
27
        $this->args = args;
0 ignored issues
show
Bug introduced by
The constant Formularium\args was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
28
    }
29
30
    public function toGraphql(): string
31
    {
32
        $args = array_map(
33
            function (ValidatorArgs $a) {
34
                return $a->toGraphql();
35
            },
36
            $this->args
37
        );
38
39
        $argString = '';
40
        if ($args) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $args of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
41
            $argString = "(\n" . join("\n", $args) . ')';
42
        }
43
        return <<< EOF
44
"""
45
{$this->comment}
46
"""
47
directive @{$this->name}{$argString} on FIELD_DEFINITION
48
  
49
EOF;
50
    }
51
}
52