These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Hateoas\Tests\Serializer\Metadata; |
||
4 | |||
5 | use Hateoas\Configuration\Embedded; |
||
6 | use Hateoas\Configuration\Exclusion; |
||
7 | use Hateoas\Configuration\Relation; |
||
8 | use Hateoas\Configuration\Route; |
||
9 | use Hateoas\Serializer\Metadata\RelationPropertyMetadata; |
||
10 | use Hateoas\Tests\TestCase; |
||
11 | |||
12 | class RelationPropertyMetadataTest extends TestCase |
||
13 | { |
||
14 | public function test() |
||
15 | { |
||
16 | $propertyMetadata = new RelationPropertyMetadata(); |
||
17 | |||
18 | $this->assertNull($propertyMetadata->groups); |
||
19 | $this->assertNull($propertyMetadata->sinceVersion); |
||
20 | $this->assertNull($propertyMetadata->untilVersion); |
||
21 | $this->assertNull($propertyMetadata->maxDepth); |
||
22 | } |
||
23 | |||
24 | public function testWithExclusion() |
||
25 | { |
||
26 | $propertyMetadata = new RelationPropertyMetadata(new Exclusion( |
||
27 | array('foo', 'bar'), |
||
28 | 1.1, |
||
29 | 2.2, |
||
30 | 42 |
||
31 | )); |
||
32 | |||
33 | $this->assertSame(['foo', 'bar'], $propertyMetadata->groups); |
||
34 | $this->assertSame(1.1, $propertyMetadata->sinceVersion); |
||
35 | $this->assertSame(2.2, $propertyMetadata->untilVersion); |
||
36 | $this->assertSame(42, $propertyMetadata->maxDepth); |
||
37 | } |
||
38 | |||
39 | View Code Duplication | public function testWithEmbeddedRelation() |
|
0 ignored issues
–
show
|
|||
40 | { |
||
41 | $propertyMetadata = new RelationPropertyMetadata(null, new Relation( |
||
42 | 'foo', |
||
43 | null, |
||
44 | new Embedded('bar', array('name' => 'John')) |
||
0 ignored issues
–
show
array('name' => 'John') is of type array<string,string,{"name":"string"}> , but the function expects a string|null .
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...
|
|||
45 | )); |
||
46 | |||
47 | $this->assertSame('foo', $propertyMetadata->name); |
||
48 | $this->assertSame('Hateoas\Configuration\Relation', $propertyMetadata->class); |
||
49 | $this->assertSame( |
||
50 | [ |
||
51 | 'name' => 'Hateoas\Model\Embedded', |
||
52 | 'params' => [], |
||
53 | ], $propertyMetadata->type |
||
54 | ); |
||
55 | } |
||
56 | |||
57 | View Code Duplication | public function testWithLinkRelation() |
|
0 ignored issues
–
show
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...
|
|||
58 | { |
||
59 | $propertyMetadata = new RelationPropertyMetadata(null, new Relation( |
||
60 | 'foo', |
||
61 | new Route('/route', array('foo' => 'bar')) |
||
62 | )); |
||
63 | |||
64 | $this->assertSame('foo', $propertyMetadata->name); |
||
65 | $this->assertSame('Hateoas\Configuration\Relation', $propertyMetadata->class); |
||
66 | $this->assertSame( |
||
67 | [ |
||
68 | 'name' => 'Hateoas\Model\Link', |
||
69 | 'params' => [], |
||
70 | ], $propertyMetadata->type |
||
71 | ); |
||
72 | } |
||
73 | } |
||
74 |
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.