Completed
Pull Request — master (#29)
by
unknown
06:10
created

MutationObjectHandler::toArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 3
1
<?php
2
3
namespace Softonic\GraphQL\Mutation\Traits;
4
5
use Softonic\GraphQL\Mutation\MutationObject;
6
7
trait MutationObjectHandler
8
{
9 32
    public function hasChanged(): bool
10
    {
11 32
        if ($this->hasChanged) {
0 ignored issues
show
Bug introduced by
The property hasChanged does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
12 28
            return true;
13
        }
14
15 32
        foreach ($this->arguments as $argument) {
0 ignored issues
show
Bug introduced by
The property arguments does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
16 32
            if ($argument instanceof MutationObject && $argument->hasChanged()) {
17 28
                $this->hasChanged = true;
18
19 32
                return true;
20
            }
21
        }
22
23 16
        return false;
24
    }
25
26 12
    public function toArray(): array
27
    {
28 12
        $item = [];
29 12
        foreach ($this->arguments as $key => $value) {
30 12
            $item[$key] = $value instanceof \JsonSerializable ? $value->toArray() : $value;
0 ignored issues
show
Bug introduced by
The class JsonSerializable does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
31
        }
32
33 12
        return $item;
34
    }
35
}
36