| Conditions | 5 |
| Paths | 10 |
| Total Lines | 25 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 5.7873 |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | 89 | public static function fromSqlSrvErrors() |
|
| 21 | { |
||
| 22 | 89 | $message = ''; |
|
| 23 | 89 | $sqlState = null; |
|
| 24 | 89 | $errorCode = null; |
|
| 25 | |||
| 26 | 89 | foreach ((array) sqlsrv_errors(SQLSRV_ERR_ERRORS) as $error) { |
|
| 27 | 89 | $message .= 'SQLSTATE [' . $error['SQLSTATE'] . ', ' . $error['code'] . ']: ' . $error['message'] . "\n"; |
|
| 28 | |||
| 29 | 89 | if ($sqlState === null) { |
|
| 30 | 89 | $sqlState = $error['SQLSTATE']; |
|
| 31 | } |
||
| 32 | |||
| 33 | 89 | if ($errorCode !== null) { |
|
| 34 | 88 | continue; |
|
| 35 | } |
||
| 36 | |||
| 37 | 89 | $errorCode = $error['code']; |
|
| 38 | } |
||
| 39 | |||
| 40 | 89 | if (! $message) { |
|
| 41 | $message = 'SQL Server error occurred but no error message was retrieved from driver.'; |
||
| 42 | } |
||
| 43 | |||
| 44 | 89 | return new self(rtrim($message), $sqlState, $errorCode); |
|
| 45 | } |
||
| 47 |