90% of 272OPs |
100% of 48Lines |
76% of 46Branches |
38% of 32Paths |
| Method | OPs | OPs % | Lines | Line % | Branches | Branches % | Paths | Path % |
|---|---|---|---|---|---|---|---|---|
| mageekguy\atoum\includer::__construct() | 10 | 100% | 2 | 100% | 1 | 0% | 1 | 100% |
| mageekguy\atoum\includer::resetErrors() | 9 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
| mageekguy\atoum\includer::setAdapter() | 16 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
| mageekguy\atoum\includer::getAdapter() | 6 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
| mageekguy\atoum\includer::getErrors() | 6 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
| mageekguy\atoum\includer::includePath() | 133 | 86% | 21 | 100% | 19 | 68% | 11 | 27% |
| mageekguy\atoum\includer::getFirstError() | 22 | 100% | 6 | 100% | 4 | 100% | 2 | 100% |
| mageekguy\atoum\includer::errorHandler() | 70 | 89% | 13 | 100% | 18 | 78% | 14 | 14% |
| # | |
|---|---|
| 1 |
<?php |
| 2 |
|
| 3 |
namespace mageekguy\atoum; |
| 4 |
|
| 5 |
use |
| 6 |
mageekguy\atoum, |
| 7 |
mageekguy\atoum\includer |
| 8 |
; |
| 9 |
|
| 10 |
class includer |
| 11 |
{
|
| 12 |
protected $adapter = null; |
| 13 |
protected $errors = array(); |
| 14 |
|
| 15 |
private $path = ''; |
| 16 |
|
| 17 |
public function __construct(atoum\adapter $adapter = null)100% |
| 18 |
{
|
| 19 |
$this->setAdapter($adapter); |
| 20 |
} |
| 21 |
|
| 22 |
public function resetErrors()100% |
| 23 |
{
|
| 24 |
$this->errors = array(); |
| 25 |
|
| 26 |
return $this; |
| 27 |
} |
| 28 |
|
| 29 |
public function setAdapter(atoum\adapter $adapter = null)100% |
| 30 |
{
|
| 31 |
$this->adapter = $adapter ?: new atoum\adapter(); |
| 32 |
|
| 33 |
return $this; |
| 34 |
} |
| 35 |
|
| 36 |
public function getAdapter()100% |
| 37 |
{
|
| 38 |
return $this->adapter; |
| 39 |
} |
| 40 |
|
| 41 |
public function getErrors()100% |
| 42 |
{
|
| 43 |
return $this->errors; |
| 44 |
} |
| 45 |
|
| 46 |
public function includePath($path, \closure $closure = null)100% |
| 47 |
{
|
| 48 |
$this->resetErrors(); |
| 49 |
|
| 50 |
$this->path = (string) $path; |
| 51 |
|
| 52 |
$errorHandler = $this->adapter->set_error_handler(array($this, 'errorHandler')); |
| 53 |
|
| 54 |
$closure = $closure ?: function($path) { include_once($path); };
|
| 55 |
|
| 56 |
$closure($this->path); |
| 57 |
|
| 58 |
$this->adapter->restore_error_handler(); |
| 59 |
|
| 60 |
if (sizeof($this->errors) > 0) |
| 61 |
{
|
| 62 |
$realpath = parse_url($this->path, PHP_URL_SCHEME) !== null ? $this->path : realpath($this->path) ?: $this->path; |
| 63 |
|
| 64 |
if (in_array($realpath, $this->adapter->get_included_files(), true) === false) |
| 65 |
{
|
| 66 |
throw new includer\exception('Unable to include \'' . $this->path . '\'');
|
| 67 |
} |
| 68 |
|
| 69 |
if ($errorHandler !== null) |
| 70 |
{
|
| 71 |
foreach ($this->errors as $error) |
| 72 |
{
|
| 73 |
call_user_func_array($errorHandler, $error); |
| 74 |
} |
| 75 |
|
| 76 |
$this->errors = array(); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
return $this; |
| 81 |
} |
| 82 |
|
| 83 |
public function getFirstError()100% |
| 84 |
{
|
| 85 |
$firstError = null; |
| 86 |
|
| 87 |
if (sizeof($this->errors) > 0) |
| 88 |
{
|
| 89 |
$firstError = $this->errors[0]; |
| 90 |
} |
| 91 |
|
| 92 |
return $firstError; |
| 93 |
} |
| 94 |
|
| 95 |
public function errorHandler($error, $message, $file, $line, $context)100% |
| 96 |
{
|
| 97 |
$errorReporting = $this->adapter->error_reporting(); |
| 98 |
|
| 99 |
if ($errorReporting !== 0 && ($errorReporting & $error)) |
| 100 |
{
|
| 101 |
foreach (array_reverse(debug_backtrace()) as $trace) |
| 102 |
{
|
| 103 |
if (isset($trace['file']) === true && $trace['file'] === $this->path) |
| 104 |
{
|
| 105 |
$file = $this->path; |
| 106 |
$line = $trace['line']; |
| 107 |
|
| 108 |
break; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
$this->errors[] = array($error, $message, $file, $line, $context); |
| 113 |
} |
| 114 |
|
| 115 |
return true; |
| 116 |
} |
| 117 |
} |