| Conditions | 7 | 
| Paths | 7 | 
| Total Lines | 66 | 
| Code Lines | 42 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 2 | ||
| Bugs | 1 | Features | 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  | 
            ||
| 106 | private function parseDsn()  | 
            ||
| 107 |     { | 
            ||
| 108 |         $dsn = $this->configuration->mustHave('dsn')->getParameter('dsn'); | 
            ||
| 109 | if (!preg_match(  | 
            ||
| 110 | '#([a-z]+)://([^:@]+)(?::([^@]*))?(?:@([\w\.-]+|!/.+[^/]!)(?::(\w+))?)?/(.+)#',  | 
            ||
| 111 | $dsn,  | 
            ||
| 112 | $matches  | 
            ||
| 113 |         )) { | 
            ||
| 114 |             throw new ConnectionException(sprintf('Could not parse DSN "%s".', $dsn)); | 
            ||
| 115 | }  | 
            ||
| 116 | |||
| 117 |         if ($matches[1] == null || $matches[1] !== 'pgsql') { | 
            ||
| 118 | throw new ConnectionException(  | 
            ||
| 119 | sprintf(  | 
            ||
| 120 | "bad protocol information '%s' in dsn '%s'. Pomm does only support 'pgsql' for now.",  | 
            ||
| 121 | $matches[1],  | 
            ||
| 122 | $dsn  | 
            ||
| 123 | )  | 
            ||
| 124 | );  | 
            ||
| 125 | }  | 
            ||
| 126 | |||
| 127 | $adapter = $matches[1];  | 
            ||
| 128 | |||
| 129 |         if ($matches[2] === null) { | 
            ||
| 130 | throw new ConnectionException(  | 
            ||
| 131 | sprintf(  | 
            ||
| 132 | "No user information in dsn '%s'.",  | 
            ||
| 133 | $dsn  | 
            ||
| 134 | )  | 
            ||
| 135 | );  | 
            ||
| 136 | }  | 
            ||
| 137 | |||
| 138 | $user = $matches[2];  | 
            ||
| 139 | $pass = $matches[3];  | 
            ||
| 140 | |||
| 141 |         if (preg_match('/!(.*)!/', $matches[4], $host_matches)) { | 
            ||
| 142 | $host = $host_matches[1];  | 
            ||
| 143 |         } else { | 
            ||
| 144 | $host = $matches[4];  | 
            ||
| 145 | }  | 
            ||
| 146 | |||
| 147 | $port = $matches[5];  | 
            ||
| 148 | |||
| 149 |         if ($matches[6] === null) { | 
            ||
| 150 | throw new ConnectionException(  | 
            ||
| 151 | sprintf(  | 
            ||
| 152 | "No database name in dsn '%s'.",  | 
            ||
| 153 | $dsn  | 
            ||
| 154 | )  | 
            ||
| 155 | );  | 
            ||
| 156 | }  | 
            ||
| 157 | |||
| 158 | $database = $matches[6];  | 
            ||
| 159 | $this->configuration  | 
            ||
| 160 |             ->setParameter('adapter', $adapter) | 
            ||
| 161 |             ->setParameter('user', $user) | 
            ||
| 162 |             ->setParameter('pass', $pass) | 
            ||
| 163 |             ->setParameter('host', $host) | 
            ||
| 164 |             ->setParameter('port', $port) | 
            ||
| 165 |             ->setParameter('database', $database) | 
            ||
| 166 |             ->mustHave('user') | 
            ||
| 167 |             ->mustHave('database') | 
            ||
| 168 | ;  | 
            ||
| 169 | |||
| 170 | return $this;  | 
            ||
| 171 | }  | 
            ||
| 172 | |||
| 245 |