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