Conditions | 1 |
Paths | 1 |
Total Lines | 77 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types=1); |
||
86 | public function testProductRanking() |
||
87 | { |
||
88 | $context = Context::createDefaultContext(Defaults::TENANT_ID); |
||
89 | |||
90 | $p1 = Uuid::uuid4()->getHex(); |
||
91 | $productId2 = Uuid::uuid4()->getHex(); |
||
92 | |||
93 | $this->productRepository->upsert([ |
||
94 | ['id' => $p1, 'name' => 'test product 1', 'price' => ['gross' => 10, 'net' => 9], 'tax' => ['name' => 'test', 'rate' => 5], 'manufacturer' => ['name' => 'test']], |
||
95 | ['id' => $productId2, 'name' => 'test product 2', 'price' => ['gross' => 10, 'net' => 9], 'tax' => ['name' => 'test', 'rate' => 5], 'manufacturer' => ['name' => 'test']], |
||
96 | ['id' => Uuid::uuid4()->getHex(), 'name' => 'notmatch', 'price' => ['gross' => 10, 'net' => 9], 'tax' => ['name' => 'test', 'rate' => 5], 'manufacturer' => ['name' => 'test']], |
||
97 | ['id' => Uuid::uuid4()->getHex(), 'name' => 'notmatch', 'price' => ['gross' => 10, 'net' => 9], 'tax' => ['name' => 'test', 'rate' => 5], 'manufacturer' => ['name' => 'test']], |
||
98 | ], $context); |
||
99 | |||
100 | $result = $this->search->search('product', 1, 20, $context, $this->userId); |
||
101 | |||
102 | //no audit log exists? product 1 was insert first and should match first |
||
103 | self::assertEquals(2, $result['total']); |
||
104 | self::assertCount(2, $result['data']); |
||
105 | |||
106 | /** @var ProductStruct $first */ |
||
107 | $first = $result['data'][0]; |
||
108 | self::assertInstanceOf(ProductStruct::class, $first); |
||
109 | |||
110 | /** @var ProductStruct $second */ |
||
111 | $second = $result['data'][1]; |
||
112 | self::assertInstanceOf(ProductStruct::class, $second); |
||
113 | |||
114 | $firstScore = $first->getExtension('search')->get('_score'); |
||
115 | $secondScore = $second->getExtension('search')->get('_score'); |
||
116 | |||
117 | self::assertSame($secondScore, $firstScore); |
||
118 | |||
119 | $this->productRepository->update([ |
||
120 | ['id' => $productId2, 'price' => ['gross' => 15, 'net' => 1]], |
||
121 | ['id' => $productId2, 'price' => ['gross' => 20, 'net' => 1]], |
||
122 | ['id' => $productId2, 'price' => ['gross' => 25, 'net' => 1]], |
||
123 | ['id' => $productId2, 'price' => ['gross' => 30, 'net' => 1]], |
||
124 | ], Context::createDefaultContext(Defaults::TENANT_ID)); |
||
125 | |||
126 | $changes = $this->getVersionData(ProductDefinition::getEntityName(), $productId2, Defaults::LIVE_VERSION); |
||
127 | $this->assertNotEmpty($changes); |
||
128 | |||
129 | $this->connection->executeUpdate('UPDATE version_commit_data SET user_id = NULL'); |
||
130 | $this->connection->executeUpdate( |
||
131 | "UPDATE version_commit_data SET user_id = :user |
||
132 | WHERE entity_name = :entity |
||
133 | AND JSON_EXTRACT(entity_id, '$.id') = :id", |
||
134 | [ |
||
135 | 'id' => $productId2, |
||
136 | 'entity' => ProductDefinition::getEntityName(), |
||
137 | 'user' => Uuid::fromStringToBytes($this->userId), |
||
138 | ] |
||
139 | ); |
||
140 | |||
141 | $result = $this->search->search('product', 1, 20, $context, $this->userId); |
||
142 | |||
143 | self::assertEquals(2, $result['total']); |
||
144 | self::assertCount(2, $result['data']); |
||
145 | |||
146 | /** @var ProductStruct $first */ |
||
147 | $first = $result['data'][0]; |
||
148 | self::assertInstanceOf(ProductStruct::class, $first); |
||
149 | |||
150 | /** @var ProductStruct $second */ |
||
151 | $second = $result['data'][1]; |
||
152 | self::assertInstanceOf(ProductStruct::class, $second); |
||
153 | |||
154 | // `product-2` should now be boosted |
||
155 | self::assertSame($first->getId(), $productId2); |
||
156 | self::assertSame($second->getId(), $p1); |
||
157 | |||
158 | $firstScore = $first->getExtension('search')->get('_score'); |
||
159 | $secondScore = $second->getExtension('search')->get('_score'); |
||
160 | |||
161 | self::assertTrue($firstScore > $secondScore); |
||
162 | } |
||
163 | |||
183 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.