EmbeddedDocumentSerializerTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 309
Duplicated Lines 27.18 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 8
dl 84
loc 309
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 37 1
A testCreateEmbeddedDocument() 15 15 1
A testCreateEmbeddedNoTargetDocument() 0 23 1
A testCreateNoMetadata() 16 16 1
A testCreateThorwsWhenNoTargetNoMetadata() 0 14 1
A testCreateMetadataConflict() 0 11 1
A testSerialize() 25 25 1
A testSerializeMismatchingTargetDocument() 28 28 1
A testSerializeNoTargetDocument() 0 45 1
B testIsChanged() 0 79 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
4
namespace Doctrine\Tests\ODM\CouchDB\Mapping;
5
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Doctrine\ODM\CouchDB\Mapping\EmbeddedDocumentSerializer;
8
use Doctrine\ODM\CouchDB\Mapping\ClassMetadataFactory;
9
use Doctrine\ODM\CouchDB\Mapping\MetadataResolver\DoctrineResolver;
10
/*
11
    public function __constrct(DocumentManager $dm)
12
    public function serializeEmbeddedDocument($embeddedValue, $embeddedFieldMapping)
13
    public function createEmbeddedDocument($data, $embeddedFieldMapping)
14
    public function compare($jsonValue, $embeddedDocument)
15
*/
16
17
class EmbeddedDocumentSerializerTest extends \Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase
18
{
19
    private $serializer;
20
    public function setUp()
21
    {
22
        $dm = $this->createDocumentManager();
23
        $this->metadataFactory = new ClassMetadataFactory($dm);
0 ignored issues
show
Bug introduced by
The property metadataFactory 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...
24
        $resolver = new DoctrineResolver();
25
        $this->serializer = new EmbeddedDocumentSerializer($this->metadataFactory, $resolver);
26
27
        $this->arrayDataFixture = array(
0 ignored issues
show
Bug introduced by
The property arrayDataFixture 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...
28
            'type' => 'Doctrine.Tests.ODM.CouchDB.Mapping.Embedded',
29
            'name' => 'embedded-1',
30
            'embeds' => array(
31
                'one' => array(
32
                    'type' => 'Doctrine.Tests.ODM.CouchDB.Mapping.Nested',
33
                    'nestedName' => 'a111'
34
                    ),
35
                'two' => array(
36
                    'type' => 'Doctrine.Tests.ODM.CouchDB.Mapping.Nested',
37
                    'nestedName' => 'a222'
38
                    )
39
                ),
40
            );
41
        $this->embedOneFixture = array(
0 ignored issues
show
Bug introduced by
The property embedOneFixture 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...
42
                'type' => 'Doctrine.Tests.ODM.CouchDB.Mapping.Embedded',
43
                'name' => 'embeddedAnyOne',
44
45
            );
46
        $this->embedAnyFixture = array(
0 ignored issues
show
Bug introduced by
The property embedAnyFixture 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...
47
            'any_1' => array(
48
                'type' => 'Doctrine.Tests.ODM.CouchDB.Mapping.Embedded',
49
                'name' => 'embedAny_1'
50
                ),
51
            'any_2' => array(
52
                'type' => 'Doctrine.Tests.ODM.CouchDB.Mapping.Nested',
53
                'nestedName' => 'embedAny_2'
54
                )
55
            );
56
    }
57
58 View Code Duplication
    public function testCreateEmbeddedDocument()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        $embedderMetadata =
61
            $this->metadataFactory->getMetadataFor('Doctrine\Tests\ODM\CouchDB\Mapping\Embedder');
62
63
        $instance = $this->serializer->createEmbeddedDocument(
64
            $this->arrayDataFixture,
65
            $embedderMetadata->fieldMappings['embedded']);
66
67
        $this->assertNotNull($instance);
68
        $this->assertEquals('embedded-1', $instance->name);
69
        $this->assertTrue($instance->embeds->containsKey('one'));
70
        $this->assertTrue($instance->embeds->containsKey('two'));
71
        $this->assertCount(2, $instance->embeds);
72
    }
73
74
    public function testCreateEmbeddedNoTargetDocument()
75
    {
76
        $embedderMetadata =
77
            $this->metadataFactory->getMetadataFor('Doctrine\Tests\ODM\CouchDB\Mapping\Embedder');
78
79
        $instance = $this->serializer->createEmbeddedDocument(
80
            $this->embedOneFixture,
81
            $embedderMetadata->fieldMappings['embedAnyOne']);
82
        $this->assertInstanceOf('Doctrine\Tests\ODM\CouchDB\Mapping\Embedded', $instance);
83
        $this->assertEquals('embeddedAnyOne', $instance->name);
84
85
        $instance = $this->serializer->createEmbeddedDocument(
86
            $this->embedAnyFixture,
87
            $embedderMetadata->fieldMappings['embedAny']);
88
        $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection',$instance);
89
        $this->assertCount(2, $instance);
90
        $this->assertTrue($instance->containsKey('any_1'));
91
        $this->assertTrue($instance->containsKey('any_2'));
92
        $this->assertInstanceOf('Doctrine\Tests\ODM\CouchDB\Mapping\Embedded', $instance['any_1']);
93
        $this->assertInstanceOf('Doctrine\Tests\ODM\CouchDB\Mapping\Nested', $instance['any_2']);
94
        $this->assertEquals('embedAny_1', $instance['any_1']->name);
95
        $this->assertEquals('embedAny_2', $instance['any_2']->nestedName);
96
    }
97
98
    /**
99
     * If there is no doctrine_metadata inside of an embedded array, classmetadata should help
100
     */
101 View Code Duplication
    public function testCreateNoMetadata()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
    {
103
        unset($this->arrayDataFixture['doctrine_metadata']);
104
105
        $embedderMetadata =
106
            $this->metadataFactory->getMetadataFor('Doctrine\Tests\ODM\CouchDB\Mapping\Embedder');
107
108
        $instance = $this->serializer->createEmbeddedDocument(
109
            $this->arrayDataFixture,
110
            $embedderMetadata->fieldMappings['embedded']);
111
        $this->assertNotNull($instance);
112
        $this->assertEquals('embedded-1', $instance->name);
113
        $this->assertTrue($instance->embeds->containsKey('one'));
114
        $this->assertTrue($instance->embeds->containsKey('two'));
115
        $this->assertCount(2, $instance->embeds);
116
    }
117
118
    public function testCreateThorwsWhenNoTargetNoMetadata()
119
    {
120
        $embedderMetadata =
121
            $this->metadataFactory->getMetadataFor('Doctrine\Tests\ODM\CouchDB\Mapping\Embedder');
122
123
        $this->arrayDataFixture['embedAny'] = $this->embedAnyFixture;
124
        unset($this->arrayDataFixture['embedAny']['any_2']['doctrine_metadata']);
125
126
        $this->setExpectedException('InvalidArgumentException');
127
        $instance = $this->serializer->createEmbeddedDocument(
0 ignored issues
show
Unused Code introduced by
$instance is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
128
            $this->arrayDataFixture,
129
            $embedderMetadata->fieldMappings['embedAny']);
130
131
    }
132
133
    public function testCreateMetadataConflict()
134
    {
135
        $embedderMetadata =
136
            $this->metadataFactory->getMetadataFor('Doctrine\Tests\ODM\CouchDB\Mapping\Embedder');
137
138
        $this->arrayDataFixture['embeds']['two']['type'] = 'Doctrine.Tests.ODM.CouchDB.Mapping.Embedded';
139
        $this->setExpectedException('InvalidArgumentException');
140
        $instance = $this->serializer->createEmbeddedDocument(
0 ignored issues
show
Unused Code introduced by
$instance is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
141
            $this->arrayDataFixture,
142
            $embedderMetadata->fieldMappings['embedAny']);
143
    }
144
145 View Code Duplication
    public function testSerialize()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
146
    {
147
        $embedderMetadata =
148
            $this->metadataFactory->getMetadataFor('Doctrine\Tests\ODM\CouchDB\Mapping\Embedder');
149
150
        $embedder = new Embedder;
151
        $embedder->id = 'embedder-1';
152
153
        $embedded = new Embedded;
154
        $embedded->name = 'embedded-1';
155
156
        $nested1 = new Nested;
157
        $nested1->nestedName = 'a111';
158
        $embedded->embeds['one'] = $nested1;
159
        $nested2 = new Nested;
160
        $nested2->nestedName = 'a222';
161
        $embedded->embeds['two'] = $nested2;
162
163
        $embedder->embedded = $embedded;
164
        $arrayData = $this->serializer->serializeEmbeddedDocument(
165
            $embedded,
166
            $embedderMetadata->fieldMappings['embedded']);
167
168
        $this->assertEquals($this->arrayDataFixture, $arrayData);
169
    }
170
171 View Code Duplication
    public function testSerializeMismatchingTargetDocument()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
172
    {
173
        $embedderMetadata =
174
            $this->metadataFactory->getMetadataFor('Doctrine\Tests\ODM\CouchDB\Mapping\Embedder');
175
176
        $embedder = new Embedder;
177
        $embedder->id = 'embedder-1';
178
179
        $embedded = new Embedded;
180
        $embedded->name = 'embedded-1';
181
182
        $nested1 = new Nested;
183
        $nested1->nestedName = 'a111';
184
        $embedded->embeds['one'] = $nested1;
185
        $nested2 = new Embedded;
186
        $nested2->name = 'a222';
187
        $embedded->embeds['two'] = $nested2;
188
189
        $embedder->embedded = $embedded;
190
191
        $this->setExpectedException('InvalidArgumentException');
192
        $arrayData = $this->serializer->serializeEmbeddedDocument(
193
            $embedded,
194
            $embedderMetadata->fieldMappings['embedded']);
195
196
        $this->assertEquals($this->arrayDataFixture, $arrayData);
197
198
    }
199
200
    public function testSerializeNoTargetDocument()
201
    {
202
        $embedder = new Embedder;
203
        $embeddedMany_1 = new Embedded;
204
        $embeddedMany_1->name = 'embeddedMany_1';
205
        $embeddedMany_2 = new Nested;
206
        $embeddedMany_2->nestedName = 'embeddedMany_2';
207
208
        $embedder->embedAny = array($embeddedMany_1, $embeddedMany_2);
209
210
        $embedOne = new Nested;
211
        $embedOne->nestedName = 'embedOne';
212
        $embedder->embedAnyOne = $embedOne;
213
214
        $embedderMetadata =
215
            $this->metadataFactory->getMetadataFor('Doctrine\Tests\ODM\CouchDB\Mapping\Embedder');
216
217
        $arrayData = $this->serializer->serializeEmbeddedDocument(
218
            $embedder->embedAny,
0 ignored issues
show
Documentation introduced by
$embedder->embedAny is of type array<integer,object<Doc...DB\\Mapping\\Nested>"}>, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
219
            $embedderMetadata->fieldMappings['embedAny']);
220
221
        $this->assertEquals(
222
            array(
223
                array(
224
                    'type' => 'Doctrine.Tests.ODM.CouchDB.Mapping.Embedded',
225
                    'name' => 'embeddedMany_1',
226
                    'embeds' => array(),
227
                    ),
228
                array(
229
                    'type' => 'Doctrine.Tests.ODM.CouchDB.Mapping.Nested',
230
                    'nestedName' => 'embeddedMany_2'
231
                    )
232
                ),
233
            $arrayData);
234
235
        $arrayData = $this->serializer->serializeEmbeddedDocument(
236
            $embedder->embedAnyOne,
237
            $embedderMetadata->fieldMappings['embedAnyOne']);
238
        $this->assertEquals(
239
            array(
240
                'type' => 'Doctrine.Tests.ODM.CouchDB.Mapping.Nested',
241
                'nestedName' => 'embedOne'
242
                ),
243
            $arrayData);
244
    }
245
246
    public function testIsChanged()
247
    {
248
        $embedderMetadata =
249
            $this->metadataFactory->getMetadataFor('Doctrine\Tests\ODM\CouchDB\Mapping\Embedder');
250
251
        $fieldMapping = $embedderMetadata->fieldMappings['embedded'];
252
        $instance = $this->serializer->createEmbeddedDocument(
253
            $this->arrayDataFixture,
254
            $fieldMapping);
255
256
        $this->assertFalse($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
257
258
        $name = $instance->name;
259
        $instance->name = 'changed';
260
        $this->assertTrue($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
261
        $instance->name = $name;
262
        $this->assertFalse($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
263
264
265
        $nestedName = $instance->embeds['one']->nestedName;
266
        $instance->embeds['one']->nestedName = 'changed';
267
        $this->assertTrue($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
268
        $instance->embeds['one']->nestedName = $nestedName;
269
        $this->assertFalse($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
270
271
        // testing same data representation but different class
272
        $newNested = new Nested2;
273
        $newNested->nestedName = $nestedName;
274
        $instance->embeds['one'] = $newNested;
275
        $this->assertTrue($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
276
277
        $newNested = new Nested;
278
        $newNested->nestedName = $nestedName;
279
        $instance->embeds['one'] = $newNested;
280
        $this->assertFalse($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
281
282
        // testing that to null a property is a change
283
        $instance->embeds['one']->nestedName = null;
284
        $this->assertTrue($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
285
286
        $instance->embeds['one']->nestedName = $nestedName;
287
        $this->assertFalse($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
288
289
        // adding a new value is a change
290
        $instance->embeds['three'] = new Nested;
291
        $this->assertTrue($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
292
        unset($instance->embeds['three']);
293
        $this->assertFalse($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
294
295
        // removing one is a change
296
        unset($instance->embeds['two']);
297
        $this->assertTrue($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
298
299
        // same number of embeds, but different key
300
        $instance->embeds['1'] = new Nested;
301
        $this->assertTrue($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
302
303
304
        // -----------------------------------------------------------------------------
305
        //  reset things
306
        // -----------------------------------------------------------------------------
307
        $instance = $this->serializer->createEmbeddedDocument(
308
            $this->arrayDataFixture,
309
            $embedderMetadata->fieldMappings['embedded']);
310
        $this->assertFalse($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
311
312
313
        // adding an EmbedOne type of embedded document
314
        // also tesing the no targetDocument case
315
        $instance->embedOne = new Nested;
316
        $this->assertTrue($this->serializer->isChanged($instance, $this->arrayDataFixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
317
318
        $fixture = $this->arrayDataFixture;
319
        $fixture['embedOne'] = array('doctrine_metadata'=>array('type'=>'Doctrine.Tests.ODM.CouchDB.Mapping.Nested'));
320
        $this->assertFalse($this->serializer->isChanged($instance, $fixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$fixture is of type array<string,array<strin...\\\"string\\\"}>\"}>"}>, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
321
322
        $instance->embedOne->nestedName = 'so this is nested';
323
        $this->assertTrue($this->serializer->isChanged($instance, $fixture, $fieldMapping));
0 ignored issues
show
Documentation introduced by
$instance is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$fixture is of type array<string,array<strin...\\\"string\\\"}>\"}>"}>, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
324
    }
325
}
326
327
328
329
330
/**
331
 * @Document
332
 */
333
class Embedder {
334
    /**
335
     * @Id(strategy="ASSIGNED")
336
     */
337
    public $id;
338
339
    /**
340
     * @EmbedOne(targetDocument="Doctrine\Tests\ODM\CouchDB\Mapping\Embedded")
341
     */
342
    public $embedded;
343
344
    /**
345
     * @EmbedOne
346
     */
347
    public $embedAnyOne;
348
349
    /**
350
     * @EmbedMany
351
     */
352
    public $embedAny = array();
353
}
354
355
/**
356
 * @EmbeddedDocument
357
 */
358
class Embedded {
359
    /**
360
     * @Field
361
     */
362
    public $name;
363
364
    /**
365
     * @EmbedMany(targetDocument="Doctrine\Tests\ODM\CouchDB\Mapping\Nested")
366
     */
367
    public $embeds = array();
368
369
    /**
370
     * @EmbedOne
371
     */
372
    public $embedOne;
373
}
374
375
/**
376
 * @EmbeddedDocument
377
 */
378
class Nested {
379
    /**
380
     * @Field
381
     */
382
    public $nestedName;
383
}
384
385
/**
386
 * @EmbeddedDocument
387
 */
388
class Nested2 extends Nested {
389
    /**
390
     * @Field
391
     */
392
    public $nestedName;
393
}
394