| Conditions | 11 |
| Paths | 16 |
| Total Lines | 52 |
| Code Lines | 31 |
| 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 |
||
| 45 | public function __construct(string $name) |
||
| 46 | { |
||
| 47 | if ($name === '') { |
||
| 48 | throw new \InvalidArgumentException('Mailbox name cannot be empty'); |
||
| 49 | } |
||
| 50 | |||
| 51 | if (isset(self::RFC_3501_FIXED[$name])) { |
||
| 52 | return; |
||
| 53 | } |
||
| 54 | |||
| 55 | $index = 0; |
||
| 56 | $state = self::PARSE_STATE_UNQUOTED; |
||
| 57 | while (isset($name[$index])) { |
||
| 58 | $char = $name[$index]; |
||
| 59 | |||
| 60 | switch ($state) { |
||
| 61 | case self::PARSE_STATE_UNQUOTED: |
||
| 62 | if ($char === '"') { |
||
| 63 | $state = self::PARSE_STATE_QUOTED; |
||
| 64 | break; |
||
| 65 | } |
||
| 66 | |||
| 67 | if (strlen($char) !== strcspn($char, self::RFC_3501_ASTRING)) { |
||
| 68 | throw new \InvalidArgumentException( |
||
| 69 | \sprintf( |
||
| 70 | 'Invalid mailbox character %s, use a quoted string for a broader range of allowed character', |
||
| 71 | $char |
||
| 72 | ) |
||
| 73 | ); |
||
| 74 | } |
||
| 75 | break; |
||
| 76 | case self::PARSE_STATE_QUOTED: |
||
| 77 | if ($char === '"') { |
||
| 78 | $state = self::PARSE_STATE_UNQUOTED; |
||
| 79 | break; |
||
| 80 | } |
||
| 81 | |||
| 82 | if (strlen($char) !== strcspn($char, self::RFC_3501_TEXT_CHAR)) { |
||
| 83 | throw new \InvalidArgumentException('Invalid mailbox name'); |
||
| 84 | } |
||
| 85 | break; |
||
| 86 | } |
||
| 87 | |||
| 88 | $index++; |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($state === self::PARSE_STATE_QUOTED) { |
||
| 92 | throw new \InvalidArgumentException('Unfinished quoted literal'); |
||
| 93 | } |
||
| 94 | |||
| 95 | $this->name = $name; |
||
| 96 | } |
||
| 97 | |||
| 105 | } |