| Conditions | 1 |
| Paths | 1 |
| Total Lines | 54 |
| 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 |
||
| 30 | public function testFakeMapper() |
||
| 31 | { |
||
| 32 | $this->assertCount(1, $this->find('flow.tracker')); |
||
| 33 | $this->assertSame(1, $this->findOrFail('flow.tracker')->id); |
||
| 34 | $this->assertNotNull($this->findOrFail('flow.tracker', 1)); |
||
| 35 | $this->assertNull($this->findOne('flow.tracker', 2)); |
||
| 36 | |||
| 37 | $tracker = $this->create('flow.tracker', [ 'status' => 'ready', ]); |
||
| 38 | $this->assertSame($tracker->status, 'ready'); |
||
| 39 | $this->assertSame($tracker->id, 2); |
||
| 40 | |||
| 41 | $this->assertCount(2, $this->find('flow.tracker')); |
||
| 42 | $this->assertCount(1, $this->find('flow.tracker', [ 'status' => 'ready' ])); |
||
| 43 | |||
| 44 | $this->assertInstanceOf(Repository::class, $this->getRepository('flow.tracker')); |
||
| 45 | |||
| 46 | $mapper = $this->getRepository('flow.tracker')->getMapper(); |
||
| 47 | $this->assertInstanceOf(Mapper::class, $mapper); |
||
| 48 | $this->assertNotNull($mapper); |
||
| 49 | |||
| 50 | $mapper->remove('tracker', [ 'id' => 1 ]); |
||
| 51 | $this->assertCount(1, $this->find('flow.tracker')); |
||
| 52 | $this->assertSame(2, $this->findOne('flow.tracker')->id); |
||
| 53 | $tracker = $this->create('flow.tracker', [ 'status' => 'ready', ]); |
||
| 54 | $this->assertSame($tracker->status, 'ready'); |
||
| 55 | $this->assertSame($tracker->id, 3); |
||
| 56 | $this->assertCount(2, $this->find('flow.tracker')); |
||
| 57 | $this->assertNotNull($this->findOrFail('flow.tracker', 3)); |
||
| 58 | |||
| 59 | $this->create('flow.tracker', ['status' => 'draft']); |
||
| 60 | $this->assertCount(3, $this->find('flow.tracker')); |
||
| 61 | |||
| 62 | $this->remove('flow.tracker', ['status' => 'ready']); |
||
| 63 | $this->assertCount(1, $this->find('flow.tracker')); |
||
| 64 | $this->getRepository('flow.tracker')->remove($this->findOne('flow.tracker')); |
||
| 65 | |||
| 66 | $this->assertCount(0, $this->find('flow.tracker')); |
||
| 67 | |||
| 68 | $tracker = $this->create('flow.tracker', []); |
||
| 69 | $tracker->status = 'ready'; |
||
| 70 | $tracker->save(); |
||
| 71 | $this->assertSame($tracker->id, 1); |
||
| 72 | |||
| 73 | $tracker = $this->findOne('flow.tracker', [ 'status' => 'ready']); |
||
| 74 | $this->assertSame($tracker->status, 'ready'); |
||
| 75 | |||
| 76 | $tracker = $this->findOrCreate('flow.tracker', [ 'id' => 27, 'author' => 'nekufa' ]); |
||
| 77 | $this->assertNotNull($tracker); |
||
| 78 | $this->assertSame($tracker->id, 27); |
||
| 79 | |||
| 80 | $trackerByAuthor = $this->findOrCreate('flow.tracker', [ 'author' => 'nekufa' ]); |
||
| 81 | $this->assertNotNull($trackerByAuthor); |
||
| 82 | $this->assertSame($tracker, $trackerByAuthor); |
||
| 83 | } |
||
| 84 | } |
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: