| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 58 | public function testNotifyCreate() |
||
| 59 | { |
||
| 60 | self::assertEquals($this->serviceKey, $this->pagerDutyNType->getServiceKey()); |
||
| 61 | |||
| 62 | $incident = $this->createIncidentMock(); |
||
| 63 | |||
| 64 | $incident |
||
|
|
|||
| 65 | ->expects(self::any()) |
||
| 66 | ->method('getStatus') |
||
| 67 | ->willReturn(IncidentInterface::STATUS_OK + 1); |
||
| 68 | |||
| 69 | $incidentOk = $this->createIncidentMock(); |
||
| 70 | |||
| 71 | $incidentOk |
||
| 72 | ->expects(self::any()) |
||
| 73 | ->method('getStatus') |
||
| 74 | ->willReturn(IncidentInterface::STATUS_OK); |
||
| 75 | |||
| 76 | $subject = $this->createSubject('target', '* * * * *'); |
||
| 77 | |||
| 78 | $event = new Event(); |
||
| 79 | $event->serviceKey = $this->serviceKey; |
||
| 80 | $event->description = $incident->getIdent(); |
||
| 81 | $event->incidentKey = 'hci_0'; |
||
| 82 | $event->details = [ |
||
| 83 | 'log' => $incident->getMessage(), |
||
| 84 | 'status' => $incident->getStatus(), |
||
| 85 | 'type' => $incident->getType(), |
||
| 86 | 'id' => $incident->getId(), |
||
| 87 | ]; |
||
| 88 | |||
| 89 | $this->eventClientMock |
||
| 90 | ->expects(self::at(0)) |
||
| 91 | ->method('post') |
||
| 92 | ->with($event); |
||
| 93 | |||
| 94 | $event2 = clone $event; |
||
| 95 | $event2->details = null; |
||
| 96 | $event2->description = null; |
||
| 97 | $event2->eventType = Event::EVENT_TYPE_RESOLVE; |
||
| 98 | |||
| 99 | $this->eventClientMock |
||
| 100 | ->expects(self::at(1)) |
||
| 101 | ->method('post') |
||
| 102 | ->with($event2); |
||
| 103 | |||
| 104 | |||
| 105 | |||
| 106 | $this->pagerDutyNType->notify($subject, $incident); |
||
| 107 | $this->pagerDutyNType->notify($subject, $incidentOk); |
||
| 108 | |||
| 109 | } |
||
| 110 | |||
| 118 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: