Passed
Pull Request — master (#2428)
by Vincent
03:30
created

ChainDataPersister::remove()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\DataPersister;
15
16
/**
17
 * Chained data persisters.
18
 *
19
 * @author Baptiste Meyer <[email protected]>
20
 */
21
final class ChainDataPersister implements ContextAwareDataPersisterInterface
22
{
23
    /** @internal */
24
    public $persisters;
25
26
    /**
27
     * @param DataPersisterInterface[] $persisters
28
     */
29
    public function __construct(/* iterable */ $persisters)
30
    {
31
        $this->persisters = $persisters;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function supports($data, array $context = []): bool
38
    {
39
        foreach ($this->persisters as $persister) {
40
            if ($persister->supports($data, $context)) {
0 ignored issues
show
Unused Code introduced by
The call to ApiPlatform\Core\DataPer...erInterface::supports() has too many arguments starting with $context. ( Ignorable by Annotation )

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

40
            if ($persister->/** @scrutinizer ignore-call */ supports($data, $context)) {

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
41
                return true;
42
            }
43
        }
44
45
        return false;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function persist($data, array $context = [])
52
    {
53
        foreach ($this->persisters as $persister) {
54
            if ($persister->supports($data, $context)) {
0 ignored issues
show
Unused Code introduced by
The call to ApiPlatform\Core\DataPer...erInterface::supports() has too many arguments starting with $context. ( Ignorable by Annotation )

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

54
            if ($persister->/** @scrutinizer ignore-call */ supports($data, $context)) {

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
55
                return $persister->persist($data, $context) ?? $data;
0 ignored issues
show
Unused Code introduced by
The call to ApiPlatform\Core\DataPer...terInterface::persist() has too many arguments starting with $context. ( Ignorable by Annotation )

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

55
                return $persister->/** @scrutinizer ignore-call */ persist($data, $context) ?? $data;

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
56
            }
57
        }
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function remove($data, array $context = [])
64
    {
65
        foreach ($this->persisters as $persister) {
66
            if ($persister->supports($data, $context)) {
0 ignored issues
show
Unused Code introduced by
The call to ApiPlatform\Core\DataPer...erInterface::supports() has too many arguments starting with $context. ( Ignorable by Annotation )

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

66
            if ($persister->/** @scrutinizer ignore-call */ supports($data, $context)) {

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
67
                $persister->remove($data, $context);
0 ignored issues
show
Unused Code introduced by
The call to ApiPlatform\Core\DataPer...sterInterface::remove() has too many arguments starting with $context. ( Ignorable by Annotation )

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

67
                $persister->/** @scrutinizer ignore-call */ 
68
                            remove($data, $context);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
68
69
                return;
70
            }
71
        }
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function removeElementFromCollection($data, array $context = [])
78
    {
79
        foreach ($this->persisters as $persister) {
80
            if ($persister->supports($data, $context)) {
0 ignored issues
show
Unused Code introduced by
The call to ApiPlatform\Core\DataPer...erInterface::supports() has too many arguments starting with $context. ( Ignorable by Annotation )

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

80
            if ($persister->/** @scrutinizer ignore-call */ supports($data, $context)) {

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
81
                $persister->removeElementFromCollection($data, $context);
0 ignored issues
show
Bug introduced by
The method removeElementFromCollection() does not exist on ApiPlatform\Core\DataPer...\DataPersisterInterface. Did you maybe mean remove()? ( Ignorable by Annotation )

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

81
                $persister->/** @scrutinizer ignore-call */ 
82
                            removeElementFromCollection($data, $context);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
83
                return;
84
            }
85
        }
86
    }
87
}
88