Completed
Pull Request — master (#6261)
by Jordi Sala
03:16 queued 22s
created

ModelManager::getModelIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\App\Model;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Collection;
18
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
19
use Sonata\AdminBundle\Datagrid\DatagridInterface;
20
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
21
use Sonata\AdminBundle\Model\LockInterface;
22
use Sonata\AdminBundle\Model\ModelManagerInterface;
23
use Sonata\AdminBundle\Tests\App\Admin\FieldDescription;
24
use Sonata\Exporter\Source\SourceIteratorInterface;
25
26
class ModelManager implements ModelManagerInterface, LockInterface
27
{
28
    /**
29
     * @var FooRepository
30
     */
31
    private $repository;
32
33
    public function __construct(FooRepository $repository)
34
    {
35
        $this->repository = $repository;
36
    }
37
38
    public function getNewFieldDescriptionInstance(string $class, string $name, array $options = []): FieldDescriptionInterface
39
    {
40
        if (!isset($options['route']['name'])) {
41
            $options['route']['name'] = 'edit';
42
        }
43
44
        if (!isset($options['route']['parameters'])) {
45
            $options['route']['parameters'] = [];
46
        }
47
48
        $fieldDescription = new FieldDescription();
49
        $fieldDescription->setName($name);
50
        $fieldDescription->setOptions($options);
51
52
        return $fieldDescription;
53
    }
54
55
    public function create(object $object): void
56
    {
57
    }
58
59
    public function update(object $object): void
60
    {
61
    }
62
63
    public function delete(object $object): void
64
    {
65
    }
66
67
    public function findBy(string $class, array $criteria = []): array
68
    {
69
        return [];
70
    }
71
72
    public function findOneBy(string $class, array $criteria = []): ?object
73
    {
74
        return null;
75
    }
76
77
    public function find(string $class, $id): ?object
78
    {
79
        return $this->repository->byId($id);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->repository->byId($id); of type Sonata\AdminBundle\Tests\App\Model\Foo|null adds the type Sonata\AdminBundle\Tests\App\Model\Foo to the return on line 79 which is incompatible with the return type declared by the interface Sonata\AdminBundle\Model...lManagerInterface::find of type Sonata\AdminBundle\Model\T|null.
Loading history...
80
    }
81
82
    public function batchDelete(string $class, ProxyQueryInterface $queryProxy): void
83
    {
84
    }
85
86
    public function createQuery(string $class, string $alias = 'o'): ProxyQueryInterface
87
    {
88
        throw new \BadMethodCallException('Not implemented.');
89
    }
90
91
    public function getIdentifierValues(object $model): array
92
    {
93
        return [];
94
    }
95
96
    public function getIdentifierFieldNames(string $class): array
97
    {
98
        return [];
99
    }
100
101
    public function getNormalizedIdentifier(object $model): string
102
    {
103
        return $model->getId();
104
    }
105
106
    public function getUrlSafeIdentifier(object $model): string
107
    {
108
        return $this->getNormalizedIdentifier($model);
109
    }
110
111
    public function getModelInstance(string $class): object
112
    {
113
        switch ($class) {
114
            case Translated::class:
115
                return new Translated();
116
            default:
117
                return new Foo('test_id', 'foo_name');
118
        }
119
    }
120
121
    public function getModelCollectionInstance(string $class): Collection
122
    {
123
        return new ArrayCollection();
124
    }
125
126
    public function collectionRemoveElement(Collection $collection, object $element): void
127
    {
128
    }
129
130
    public function collectionAddElement(Collection $collection, object $element): void
131
    {
132
    }
133
134
    public function collectionHasElement(Collection $collection, object $element): bool
135
    {
136
        return true;
137
    }
138
139
    public function collectionClear(Collection $collection): void
140
    {
141
    }
142
143
    public function getDefaultSortValues(string $class): array
144
    {
145
        return [];
146
    }
147
148
    public function getDefaultPerPageOptions(string $class): array
149
    {
150
        return [];
151
    }
152
153
    public function modelReverseTransform(string $class, array $array = []): object
154
    {
155
        throw new \BadMethodCallException('Not implemented.');
156
    }
157
158
    public function modelTransform(string $class, object $instance): object
159
    {
160
        throw new \BadMethodCallException('Not implemented.');
161
    }
162
163
    public function executeQuery(object $query): void
164
    {
165
    }
166
167
    public function getDataSourceIterator(DatagridInterface $datagrid, array $fields, ?int $firstResult = null, ?int $maxResult = null): SourceIteratorInterface
168
    {
169
        throw new \BadMethodCallException('Not implemented.');
170
    }
171
172
    public function getExportFields(string $class): array
173
    {
174
        return [];
175
    }
176
177
    public function addIdentifiersToQuery(string $class, ProxyQueryInterface $query, array $idx): void
178
    {
179
    }
180
181
    public function getLockVersion(object $object)
182
    {
183
        return null;
184
    }
185
186
    public function lock(object $object, ?int $expectedVersion): void
187
    {
188
    }
189
}
190