| Conditions | 16 |
| Paths | 16384 |
| Total Lines | 140 |
| Code Lines | 90 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 23 |
| CRAP Score | 41.756 |
| 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 | 12 | public function __invoke(Connection $connection): Message |
|
| 31 | { |
||
| 32 | 12 | $header = $connection->wait(); |
|
| 33 | $bodySize = $header |
||
| 34 | 12 | ->values() |
|
| 35 | 12 | ->first() |
|
| 36 | 12 | ->original() |
|
| 37 | 12 | ->value(); |
|
| 38 | $flagBits = $header |
||
| 39 | 12 | ->values() |
|
| 40 | 12 | ->get(1) |
|
| 41 | 12 | ->original() |
|
| 42 | 12 | ->value(); |
|
| 43 | 12 | $payload = new Str(''); |
|
| 44 | |||
| 45 | 12 | while ($payload->length() !== $bodySize) { |
|
| 46 | 12 | $payload = $payload->append( |
|
| 47 | (string) $connection |
||
| 48 | 12 | ->wait() |
|
| 49 | 12 | ->values() |
|
| 50 | 12 | ->first() |
|
| 51 | 12 | ->original() |
|
| 52 | ); |
||
| 53 | } |
||
| 54 | |||
| 55 | 12 | $message = new Generic($payload); |
|
| 56 | $properties = $header |
||
| 57 | 12 | ->values() |
|
| 58 | 12 | ->drop(2); |
|
| 59 | |||
| 60 | 12 | if ($flagBits & (1 << 15)) { |
|
| 61 | [$topLevel, $subType] = explode( |
||
|
2 ignored issues
–
show
|
|||
| 62 | '/', |
||
| 63 | (string) $properties->first()->original() |
||
| 64 | ); |
||
| 65 | $message = $message->withContentType(new ContentType( |
||
| 66 | $topLevel, |
||
| 67 | $subType |
||
| 68 | )); |
||
| 69 | $properties = $properties->drop(1); |
||
| 70 | } |
||
| 71 | |||
| 72 | 12 | if ($flagBits & (1 << 14)) { |
|
| 73 | $message = $message->withContentEncoding(new ContentEncoding( |
||
| 74 | (string) $properties->first()->original() |
||
| 75 | )); |
||
| 76 | $properties = $properties->drop(1); |
||
| 77 | } |
||
| 78 | |||
| 79 | 12 | if ($flagBits & (1 << 13)) { |
|
| 80 | $message = $message->withHeaders( |
||
| 81 | $properties |
||
| 82 | ->first() |
||
| 83 | ->original() |
||
| 84 | ->reduce( |
||
| 85 | new Map('string', 'mixed'), |
||
| 86 | static function(Map $carry, string $key, Value $value): Map { |
||
| 87 | return $carry->put( |
||
| 88 | $key, |
||
| 89 | $value->original() |
||
| 90 | ); |
||
| 91 | } |
||
| 92 | ) |
||
| 93 | ); |
||
| 94 | $properties = $properties->drop(1); |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($flagBits & (1 << 12)) { |
||
| 98 | $message = $message->withDeliveryMode( |
||
| 99 | $properties->first()->original()->value() === DeliveryMode::persistent()->toInt() ? |
||
| 100 | DeliveryMode::persistent() : DeliveryMode::nonPersistent() |
||
| 101 | ); |
||
| 102 | $properties = $properties->drop(1); |
||
| 103 | } |
||
| 104 | |||
| 105 | if ($flagBits & (1 << 11)) { |
||
| 106 | $message = $message->withPriority(new Priority( |
||
| 107 | $properties->first()->original()->value() |
||
| 108 | )); |
||
| 109 | $properties = $properties->drop(1); |
||
| 110 | } |
||
| 111 | |||
| 112 | if ($flagBits & (1 << 10)) { |
||
| 113 | $message = $message->withCorrelationId(new CorrelationId( |
||
| 114 | (string) $properties->first()->original() |
||
| 115 | )); |
||
| 116 | $properties = $properties->drop(1); |
||
| 117 | } |
||
| 118 | |||
| 119 | if ($flagBits & (1 << 9)) { |
||
| 120 | $message = $message->withReplyTo(new ReplyTo( |
||
| 121 | (string) $properties->first()->original() |
||
| 122 | )); |
||
| 123 | $properties = $properties->drop(1); |
||
| 124 | } |
||
| 125 | |||
| 126 | if ($flagBits & (1 << 8)) { |
||
| 127 | $message = $message->withExpiration(new ElapsedPeriod( |
||
| 128 | (int) (string) $properties->first()->original() |
||
| 129 | )); |
||
| 130 | $properties = $properties->drop(1); |
||
| 131 | } |
||
| 132 | |||
| 133 | if ($flagBits & (1 << 7)) { |
||
| 134 | $message = $message->withId(new Id( |
||
| 135 | (string) $properties->first()->original() |
||
| 136 | )); |
||
| 137 | $properties = $properties->drop(1); |
||
| 138 | } |
||
| 139 | |||
| 140 | if ($flagBits & (1 << 6)) { |
||
| 141 | $message = $message->withTimestamp( |
||
| 142 | $properties->first()->original() |
||
| 143 | ); |
||
| 144 | $properties = $properties->drop(1); |
||
| 145 | } |
||
| 146 | |||
| 147 | if ($flagBits & (1 << 5)) { |
||
| 148 | $message = $message->withType(new Type( |
||
| 149 | (string) $properties->first()->original() |
||
| 150 | )); |
||
| 151 | $properties = $properties->drop(1); |
||
| 152 | } |
||
| 153 | |||
| 154 | if ($flagBits & (1 << 4)) { |
||
| 155 | $message = $message->withType(new UserId( |
||
| 156 | (string) $properties->first()->original() |
||
| 157 | )); |
||
| 158 | $properties = $properties->drop(1); |
||
| 159 | } |
||
| 160 | |||
| 161 | if ($flagBits & (1 << 3)) { |
||
| 162 | $message = $message->withType(new AppId( |
||
| 163 | (string) $properties->first()->original() |
||
| 164 | )); |
||
| 165 | $properties = $properties->drop(1); |
||
| 166 | } |
||
| 167 | |||
| 168 | return $message; |
||
| 169 | } |
||
| 170 | } |
||
| 171 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.