From 0346c26963bfefa60ce5e1012f5d3d93e5096fa8 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 27 Sep 2014 11:05:51 +0100 Subject: [PATCH] CS fixes --- examples/example-ajax-only.php | 13 ++-- examples/example-silex.php | 10 +-- examples/example.php | 24 ++++--- src/Whoops/Exception/ErrorException.php | 5 +- src/Whoops/Exception/Formatter.php | 23 ++++--- src/Whoops/Exception/Frame.php | 41 ++++++----- src/Whoops/Exception/FrameCollection.php | 26 +++---- src/Whoops/Exception/Inspector.php | 20 +++--- src/Whoops/Handler/CallbackHandler.php | 6 +- src/Whoops/Handler/Handler.php | 4 +- src/Whoops/Handler/HandlerInterface.php | 11 +-- src/Whoops/Handler/JsonResponseHandler.php | 13 ++-- src/Whoops/Handler/PlainTextHandler.php | 61 ++++++++--------- src/Whoops/Handler/PrettyPageHandler.php | 68 +++++++++---------- src/Whoops/Handler/SoapResponseHandler.php | 4 +- src/Whoops/Handler/XmlResponseHandler.php | 28 +++----- .../Phalcon/WhoopsServiceProvider.php | 22 +++--- .../Provider/Silex/WhoopsServiceProvider.php | 40 +++++------ .../Resources/views/env_details.html.php | 8 +-- .../Resources/views/frame_code.html.php | 10 +-- .../Resources/views/frame_list.html.php | 2 +- src/Whoops/Resources/views/header.html.php | 6 +- src/Whoops/Run.php | 62 +++++++++-------- src/Whoops/Util/Misc.php | 36 +++++----- src/Whoops/Util/TemplateHelper.php | 7 +- src/deprecated/Zend/ExceptionStrategy.php | 19 +++--- src/deprecated/Zend/Module.php | 12 ++-- src/deprecated/Zend/RouteNotFoundStrategy.php | 13 ++-- src/deprecated/Zend/module.config.example.php | 4 +- tests/Whoops/Exception/FormatterTest.php | 15 ++-- .../Whoops/Exception/FrameCollectionTest.php | 34 +++++----- tests/Whoops/Exception/FrameTest.php | 14 ++-- tests/Whoops/Exception/InspectorTest.php | 14 ++-- .../Handler/JsonResponseHandlerTest.php | 6 +- tests/Whoops/Handler/PlainTextHandlerTest.php | 18 +++-- .../Whoops/Handler/PrettyPageHandlerTest.php | 24 +++---- .../Handler/SoapResponseHandlerTest.php | 9 ++- .../Whoops/Handler/XmlResponseHandlerTest.php | 11 ++- tests/Whoops/RunTest.php | 63 ++++++++--------- tests/Whoops/TestCase.php | 4 +- tests/Whoops/Util/MiscTest.php | 6 +- tests/Whoops/Util/TemplateHelperTest.php | 8 +-- tests/deprecated/Zend/ModuleTest.php | 8 +-- 43 files changed, 410 insertions(+), 422 deletions(-) diff --git a/examples/example-ajax-only.php b/examples/example-ajax-only.php index 9f44bd5..bbd6346 100644 --- a/examples/example-ajax-only.php +++ b/examples/example-ajax-only.php @@ -14,23 +14,24 @@ */ namespace Whoops\Example; -use Whoops\Run; -use Whoops\Handler\PrettyPageHandler; -use Whoops\Handler\JsonResponseHandler; + use RuntimeException; +use Whoops\Handler\JsonResponseHandler; +use Whoops\Handler\PrettyPageHandler; +use Whoops\Run; require __DIR__ . '/../vendor/autoload.php'; -$run = new Run; +$run = new Run(); // We want the error page to be shown by default, if this is a // regular request, so that's the first thing to go into the stack: -$run->pushHandler(new PrettyPageHandler); +$run->pushHandler(new PrettyPageHandler()); // Now, we want a second handler that will run before the error page, // and immediately return an error message in JSON format, if something // goes awry. -$jsonHandler = new JsonResponseHandler; +$jsonHandler = new JsonResponseHandler(); // Make sure it only triggers for AJAX requests: $jsonHandler->onlyForAjaxRequests(true); diff --git a/examples/example-silex.php b/examples/example-silex.php index ce9ac5d..d12a2ee 100644 --- a/examples/example-silex.php +++ b/examples/example-silex.php @@ -18,17 +18,17 @@ */ require __DIR__ . '/../vendor/autoload.php'; -use Whoops\Provider\Silex\WhoopsServiceProvider; use Silex\Application; +use Whoops\Provider\Silex\WhoopsServiceProvider; -$app = new Application; +$app = new Application(); $app['debug'] = true; -if($app['debug']) { - $app->register(new WhoopsServiceProvider); +if ($app['debug']) { + $app->register(new WhoopsServiceProvider()); } -$app->get('/', function() use($app) { +$app->get('/', function () use ($app) { throw new RuntimeException("Oh no!"); }); diff --git a/examples/example.php b/examples/example.php index 80c2b99..155f40f 100644 --- a/examples/example.php +++ b/examples/example.php @@ -14,33 +14,36 @@ */ namespace Whoops\Example; -use Whoops\Run; -use Whoops\Handler\PrettyPageHandler; + use Exception as BaseException; +use Whoops\Handler\PrettyPageHandler; +use Whoops\Run; require __DIR__ . '/../vendor/autoload.php'; -class Exception extends BaseException {} +class Exception extends BaseException +{ +} -$run = new Run; -$handler = new PrettyPageHandler; +$run = new Run(); +$handler = new PrettyPageHandler(); // Add a custom table to the layout: $handler->addDataTable('Ice-cream I like', array( 'Chocolate' => 'yes', 'Coffee & chocolate' => 'a lot', 'Strawberry & chocolate' => 'it\'s alright', - 'Vanilla' => 'ew' + 'Vanilla' => 'ew', )); $run->pushHandler($handler); // Example: tag all frames inside a function with their function name -$run->pushHandler(function($exception, $inspector, $run) { +$run->pushHandler(function ($exception, $inspector, $run) { - $inspector->getFrames()->map(function($frame) { + $inspector->getFrames()->map(function ($frame) { - if($function = $frame->getFunction()) { + if ($function = $frame->getFunction()) { $frame->addComment("This frame is within function '$function'", 'cpt-obvious'); } @@ -51,7 +54,8 @@ $run->pushHandler(function($exception, $inspector, $run) { $run->register(); -function fooBar() { +function fooBar() +{ throw new Exception("Something broke!"); } diff --git a/src/Whoops/Exception/ErrorException.php b/src/Whoops/Exception/ErrorException.php index 8a770af..d74e823 100644 --- a/src/Whoops/Exception/ErrorException.php +++ b/src/Whoops/Exception/ErrorException.php @@ -5,10 +5,13 @@ */ namespace Whoops\Exception; + use ErrorException as BaseErrorException; /** * Wraps ErrorException; mostly used for typing (at least now) * to easily cleanup the stack trace of redundant info. */ -class ErrorException extends BaseErrorException {} +class ErrorException extends BaseErrorException +{ +} diff --git a/src/Whoops/Exception/Formatter.php b/src/Whoops/Exception/Formatter.php index a922c42..f14b8e2 100644 --- a/src/Whoops/Exception/Formatter.php +++ b/src/Whoops/Exception/Formatter.php @@ -5,15 +5,15 @@ */ namespace Whoops\Exception; -use Whoops\Util\TemplateHelper; + class Formatter { /** * Returns all basic information about the exception in a simple array * for further convertion to other languages - * @param Inspector $inspector - * @param bool $shouldAddTrace + * @param Inspector $inspector + * @param bool $shouldAddTrace * @return array */ public static function formatExceptionAsDataArray(Inspector $inspector, $shouldAddTrace) @@ -23,21 +23,21 @@ class Formatter 'type' => get_class($exception), 'message' => $exception->getMessage(), 'file' => $exception->getFile(), - 'line' => $exception->getLine() + 'line' => $exception->getLine(), ); - if($shouldAddTrace) { + if ($shouldAddTrace) { $frames = $inspector->getFrames(); $frameData = array(); - foreach($frames as $frame) { + foreach ($frames as $frame) { /** @var Frame $frame */ $frameData[] = array( 'file' => $frame->getFile(), 'line' => $frame->getLine(), 'function' => $frame->getFunction(), 'class' => $frame->getClass(), - 'args' => $frame->getArgs() + 'args' => $frame->getArgs(), ); } @@ -47,7 +47,8 @@ class Formatter return $response; } - public static function formatExceptionPlain(Inspector $inspector) { + public static function formatExceptionPlain(Inspector $inspector) + { $message = $inspector->getException()->getMessage(); $frames = $inspector->getFrames(); @@ -57,7 +58,7 @@ class Formatter $plain .= '"'."\n\n"; $plain .= "Stacktrace:\n"; - foreach($frames as $i => $frame) { + foreach ($frames as $i => $frame) { $plain .= "#". (count($frames) - $i - 1). " "; $plain .= $frame->getClass() ?: ''; $plain .= $frame->getClass() && $frame->getFunction() ? ":" : ""; @@ -67,7 +68,7 @@ class Formatter $plain .= ':'; $plain .= (int) $frame->getLine(). "\n"; } - + return $plain; - } + } } diff --git a/src/Whoops/Exception/Frame.php b/src/Whoops/Exception/Frame.php index 337c0f2..6493f4a 100644 --- a/src/Whoops/Exception/Frame.php +++ b/src/Whoops/Exception/Frame.php @@ -5,6 +5,7 @@ */ namespace Whoops\Exception; + use InvalidArgumentException; use Serializable; @@ -34,12 +35,12 @@ class Frame implements Serializable } /** - * @param bool $shortened + * @param bool $shortened * @return string|null */ public function getFile($shortened = false) { - if(empty($this->frame['file'])) { + if (empty($this->frame['file'])) { return null; } @@ -49,12 +50,12 @@ class Frame implements Serializable // @todo: This can be made more reliable by checking if we've entered // eval() in a previous trace, but will need some more work on the upper // trace collector(s). - if(preg_match('/^(.*)\((\d+)\) : (?:eval\(\)\'d|assert) code$/', $file, $matches)) { + if (preg_match('/^(.*)\((\d+)\) : (?:eval\(\)\'d|assert) code$/', $file, $matches)) { $file = $this->frame['file'] = $matches[1]; $this->frame['line'] = (int) $matches[2]; } - if($shortened && is_string($file)) { + if ($shortened && is_string($file)) { // Replace the part of the path that all frames have in common, and add 'soft hyphens' for smoother line-breaks. $dirname = dirname(dirname(dirname(dirname(dirname(dirname(__DIR__)))))); $file = str_replace($dirname, "…", $file); @@ -103,17 +104,16 @@ class Frame implements Serializable */ public function getFileContents() { - if($this->fileContentsCache === null && $filePath = $this->getFile()) { - + if ($this->fileContentsCache === null && $filePath = $this->getFile()) { // Leave the stage early when 'Unknown' is passed // this would otherwise raise an exception when // open_basedir is enabled. - if($filePath === "Unknown") { + if ($filePath === "Unknown") { return null; } // Return null if the file doesn't actually exist. - if(!is_file($filePath)) { + if (!is_file($filePath)) { return null; } @@ -138,7 +138,7 @@ class Frame implements Serializable { $this->comments[] = array( 'comment' => $comment, - 'context' => $context + 'context' => $context, ); } @@ -147,15 +147,15 @@ class Frame implements Serializable * a filter to only retrieve comments from a specific * context. * - * @param string $filter + * @param string $filter * @return array[] */ public function getComments($filter = null) { $comments = $this->comments; - if($filter !== null) { - $comments = array_filter($comments, function($c) use($filter) { + if ($filter !== null) { + $comments = array_filter($comments, function ($c) use ($filter) { return $c['context'] == $filter; }); } @@ -188,25 +188,24 @@ class Frame implements Serializable * $frame->getFileLines(9, 1); // array( 10 => '...', 11 => '...') * * @throws InvalidArgumentException if $length is less than or equal to 0 - * @param int $start - * @param int $length + * @param int $start + * @param int $length * @return string[]|null */ public function getFileLines($start = 0, $length = null) { - if(null !== ($contents = $this->getFileContents())) { + if (null !== ($contents = $this->getFileContents())) { $lines = explode("\n", $contents); // Get a subset of lines from $start to $end - if($length !== null) - { + if ($length !== null) { $start = (int) $start; $length = (int) $length; if ($start < 0) { $start = 0; } - if($length <= 0) { + if ($length <= 0) { throw new InvalidArgumentException( "\$length($length) cannot be lower or equal to 0" ); @@ -229,7 +228,7 @@ class Frame implements Serializable public function serialize() { $frame = $this->frame; - if(!empty($this->comments)) { + if (!empty($this->comments)) { $frame['_comments'] = $this->comments; } @@ -247,7 +246,7 @@ class Frame implements Serializable { $frame = unserialize($serializedFrame); - if(!empty($frame['_comments'])) { + if (!empty($frame['_comments'])) { $this->comments = $frame['_comments']; unset($frame['_comments']); } @@ -257,7 +256,7 @@ class Frame implements Serializable /** * Compares Frame against one another - * @param Frame $frame + * @param Frame $frame * @return bool */ public function equals(Frame $frame) diff --git a/src/Whoops/Exception/FrameCollection.php b/src/Whoops/Exception/FrameCollection.php index b3af9df..47fffb6 100644 --- a/src/Whoops/Exception/FrameCollection.php +++ b/src/Whoops/Exception/FrameCollection.php @@ -5,13 +5,13 @@ */ namespace Whoops\Exception; -use Whoops\Exception\Frame; -use UnexpectedValueException; -use IteratorAggregate; -use ArrayIterator; + use ArrayAccess; -use Serializable; +use ArrayIterator; use Countable; +use IteratorAggregate; +use Serializable; +use UnexpectedValueException; /** * Exposes a fluent interface for dealing with an ordered list @@ -29,7 +29,7 @@ class FrameCollection implements ArrayAccess, IteratorAggregate, Serializable, C */ public function __construct(array $frames) { - $this->frames = array_map(function($frame) { + $this->frames = array_map(function ($frame) { return new Frame($frame); }, $frames); } @@ -37,7 +37,7 @@ class FrameCollection implements ArrayAccess, IteratorAggregate, Serializable, C /** * Filters frames using a callable, returns the same FrameCollection * - * @param callable $callable + * @param callable $callable * @return FrameCollection */ public function filter($callable) @@ -49,17 +49,17 @@ class FrameCollection implements ArrayAccess, IteratorAggregate, Serializable, C /** * Map the collection of frames * - * @param callable $callable + * @param callable $callable * @return FrameCollection */ public function map($callable) { // Contain the map within a higher-order callable // that enforces type-correctness for the $callable - $this->frames = array_map(function($frame) use($callable) { + $this->frames = array_map(function ($frame) use ($callable) { $frame = call_user_func($callable, $frame); - if(!$frame instanceof Frame) { + if (!$frame instanceof Frame) { throw new UnexpectedValueException( "Callable to " . __METHOD__ . " must return a Frame object" ); @@ -168,7 +168,7 @@ class FrameCollection implements ArrayAccess, IteratorAggregate, Serializable, C /** * Gets the innermost part of stack trace that is not the same as that of outer exception * - * @param FrameCollection $parentFrames Outer exception frames to compare tail against + * @param FrameCollection $parentFrames Outer exception frames to compare tail against * @return Frame[] */ public function topDiff(FrameCollection $parentFrames) @@ -178,10 +178,10 @@ class FrameCollection implements ArrayAccess, IteratorAggregate, Serializable, C $parentFrames = $parentFrames->getArray(); $p = count($parentFrames)-1; - for($i = count($diff)-1; $i >= 0 && $p >= 0; $i--) { + for ($i = count($diff)-1; $i >= 0 && $p >= 0; $i--) { /** @var Frame $tailFrame */ $tailFrame = $diff[$i]; - if($tailFrame->equals($parentFrames[$p])) { + if ($tailFrame->equals($parentFrames[$p])) { unset($diff[$i]); } $p--; diff --git a/src/Whoops/Exception/Inspector.php b/src/Whoops/Exception/Inspector.php index ec7f4cc..5834a22 100644 --- a/src/Whoops/Exception/Inspector.php +++ b/src/Whoops/Exception/Inspector.php @@ -5,6 +5,7 @@ */ namespace Whoops\Exception; + use Exception; class Inspector @@ -72,10 +73,10 @@ class Inspector */ public function getPreviousExceptionInspector() { - if($this->previousExceptionInspector === null) { + if ($this->previousExceptionInspector === null) { $previousException = $this->exception->getPrevious(); - if($previousException) { + if ($previousException) { $this->previousExceptionInspector = new Inspector($previousException); } } @@ -90,14 +91,14 @@ class Inspector */ public function getFrames() { - if($this->frames === null) { + if ($this->frames === null) { $frames = $this->exception->getTrace(); // If we're handling an ErrorException thrown by Whoops, // get rid of the last frame, which matches the handleError method, // and do not add the current exception to trace. We ensure that // the next frame does have a filename / linenumber, though. - if($this->exception instanceof ErrorException && empty($frames[1]['line'])) { + if ($this->exception instanceof ErrorException && empty($frames[1]['line'])) { $frames = array($this->getFrameFromError($this->exception)); } else { $firstFrame = $this->getFrameFromException($this->exception); @@ -124,11 +125,10 @@ class Inspector return $this->frames; } - /** * Given an exception, generates an array in the format * generated by Exception::getTrace() - * @param Exception $exception + * @param Exception $exception * @return array */ protected function getFrameFromException(Exception $exception) @@ -138,15 +138,15 @@ class Inspector 'line' => $exception->getLine(), 'class' => get_class($exception), 'args' => array( - $exception->getMessage() - ) + $exception->getMessage(), + ), ); } /** * Given an error, generates an array in the format * generated by ErrorException - * @param ErrorException $exception + * @param ErrorException $exception * @return array */ protected function getFrameFromError(ErrorException $exception) @@ -155,7 +155,7 @@ class Inspector 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'class' => null, - 'args' => array() + 'args' => array(), ); } } diff --git a/src/Whoops/Handler/CallbackHandler.php b/src/Whoops/Handler/CallbackHandler.php index b039be8..a83c969 100644 --- a/src/Whoops/Handler/CallbackHandler.php +++ b/src/Whoops/Handler/CallbackHandler.php @@ -5,7 +5,7 @@ */ namespace Whoops\Handler; -use Whoops\Handler\Handler; + use InvalidArgumentException; /** @@ -22,11 +22,11 @@ class CallbackHandler extends Handler /** * @throws InvalidArgumentException If argument is not callable - * @param callable $callable + * @param callable $callable */ public function __construct($callable) { - if(!is_callable($callable)) { + if (!is_callable($callable)) { throw new InvalidArgumentException( 'Argument to ' . __METHOD__ . ' must be valid callable' ); diff --git a/src/Whoops/Handler/Handler.php b/src/Whoops/Handler/Handler.php index a6ca5c4..d7e78f1 100644 --- a/src/Whoops/Handler/Handler.php +++ b/src/Whoops/Handler/Handler.php @@ -5,10 +5,10 @@ */ namespace Whoops\Handler; -use Whoops\Handler\HandlerInterface; + +use Exception; use Whoops\Exception\Inspector; use Whoops\Run; -use Exception; /** * Abstract implementation of a Handler. diff --git a/src/Whoops/Handler/HandlerInterface.php b/src/Whoops/Handler/HandlerInterface.php index abf3350..f50bc30 100644 --- a/src/Whoops/Handler/HandlerInterface.php +++ b/src/Whoops/Handler/HandlerInterface.php @@ -5,31 +5,32 @@ */ namespace Whoops\Handler; + +use Exception; use Whoops\Exception\Inspector; use Whoops\Run; -use Exception; interface HandlerInterface { /** - * @return int|null A handler may return nothing, or a Handler::HANDLE_* constant + * @return int|null A handler may return nothing, or a Handler::HANDLE_* constant */ public function handle(); /** - * @param Run $run + * @param Run $run * @return void */ public function setRun(Run $run); /** - * @param Exception $exception + * @param Exception $exception * @return void */ public function setException(Exception $exception); /** - * @param Inspector $inspector + * @param Inspector $inspector * @return void */ public function setInspector(Inspector $inspector); diff --git a/src/Whoops/Handler/JsonResponseHandler.php b/src/Whoops/Handler/JsonResponseHandler.php index 611dd6e..b997438 100644 --- a/src/Whoops/Handler/JsonResponseHandler.php +++ b/src/Whoops/Handler/JsonResponseHandler.php @@ -5,7 +5,7 @@ */ namespace Whoops\Handler; -use Whoops\Handler\Handler; + use Whoops\Exception\Formatter; /** @@ -26,12 +26,12 @@ class JsonResponseHandler extends Handler private $onlyForAjaxRequests = false; /** - * @param bool|null $returnFrames + * @param bool|null $returnFrames * @return bool|$this */ public function addTraceToOutput($returnFrames = null) { - if(func_num_args() == 0) { + if (func_num_args() == 0) { return $this->returnFrames; } @@ -45,7 +45,7 @@ class JsonResponseHandler extends Handler */ public function onlyForAjaxRequests($onlyForAjaxRequests = null) { - if(func_num_args() == 0) { + if (func_num_args() == 0) { return $this->onlyForAjaxRequests; } @@ -61,8 +61,7 @@ class JsonResponseHandler extends Handler { return ( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) - && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') - ; + && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); } /** @@ -70,7 +69,7 @@ class JsonResponseHandler extends Handler */ public function handle() { - if($this->onlyForAjaxRequests() && !$this->isAjaxRequest()) { + if ($this->onlyForAjaxRequests() && !$this->isAjaxRequest()) { return Handler::DONE; } diff --git a/src/Whoops/Handler/PlainTextHandler.php b/src/Whoops/Handler/PlainTextHandler.php index 8dc80c9..b9af925 100644 --- a/src/Whoops/Handler/PlainTextHandler.php +++ b/src/Whoops/Handler/PlainTextHandler.php @@ -7,10 +7,10 @@ */ namespace Whoops\Handler; -use Whoops\Handler\Handler; + use InvalidArgumentException; -use Whoops\Exception\Frame; use Psr\Log\LoggerInterface; +use Whoops\Exception\Frame; /** * Handler outputing plaintext error messages. Can be used @@ -58,8 +58,8 @@ class PlainTextHandler extends Handler /** * Constructor. - * @throws InvalidArgumentException If argument is not null or a LoggerInterface - * @param Psr\Log\LoggerInterface|null $logger + * @throws InvalidArgumentException If argument is not null or a LoggerInterface + * @param Psr\Log\LoggerInterface|null $logger */ public function __construct($logger = null) { @@ -68,13 +68,13 @@ class PlainTextHandler extends Handler /** * Set the output logger interface. - * @throws InvalidArgumentException If argument is not null or a LoggerInterface - * @param Psr\Log\LoggerInterface|null $logger + * @throws InvalidArgumentException If argument is not null or a LoggerInterface + * @param Psr\Log\LoggerInterface|null $logger */ public function setLogger($logger = null) { - if(! (is_null($logger) - || $logger InstanceOf LoggerInterface)) { + if (! (is_null($logger) + || $logger instanceof LoggerInterface)) { throw new InvalidArgumentException( 'Argument to ' . __METHOD__ . " must be a valid Logger Interface (aka. Monolog), " . @@ -95,12 +95,12 @@ class PlainTextHandler extends Handler /** * Add error trace to output. - * @param bool|null $addTraceToOutput + * @param bool|null $addTraceToOutput * @return bool|$this */ public function addTraceToOutput($addTraceToOutput = null) { - if(func_num_args() == 0) { + if (func_num_args() == 0) { return $this->addTraceToOutput; } @@ -111,19 +111,18 @@ class PlainTextHandler extends Handler /** * Add error trace function arguments to output. * Set to True for all frame args, or integer for the n first frame args. - * @param bool|integer|null $addTraceFunctionArgsToOutput + * @param bool|integer|null $addTraceFunctionArgsToOutput * @return null|bool|integer */ public function addTraceFunctionArgsToOutput($addTraceFunctionArgsToOutput = null) { - if(func_num_args() == 0) { + if (func_num_args() == 0) { return $this->addTraceFunctionArgsToOutput; } - if(! is_integer($addTraceFunctionArgsToOutput)) { + if (! is_integer($addTraceFunctionArgsToOutput)) { $this->addTraceFunctionArgsToOutput = (bool) $addTraceFunctionArgsToOutput; - } - else { + } else { $this->addTraceFunctionArgsToOutput = $addTraceFunctionArgsToOutput; } } @@ -152,12 +151,12 @@ class PlainTextHandler extends Handler /** * Restrict error handling to command line calls. - * @param bool|null $onlyForCommandLine + * @param bool|null $onlyForCommandLine * @return null|bool */ public function onlyForCommandLine($onlyForCommandLine = null) { - if(func_num_args() == 0) { + if (func_num_args() == 0) { return $this->onlyForCommandLine; } $this->onlyForCommandLine = (bool) $onlyForCommandLine; @@ -167,12 +166,12 @@ class PlainTextHandler extends Handler * Output the error message only if using command line. * else, output to logger if available. * Allow to safely add this handler to web pages. - * @param bool|null $outputOnlyIfCommandLine + * @param bool|null $outputOnlyIfCommandLine * @return null|bool */ public function outputOnlyIfCommandLine($outputOnlyIfCommandLine = null) { - if(func_num_args() == 0) { + if (func_num_args() == 0) { return $this->outputOnlyIfCommandLine; } $this->outputOnlyIfCommandLine = (bool) $outputOnlyIfCommandLine; @@ -180,12 +179,12 @@ class PlainTextHandler extends Handler /** * Only output to logger. - * @param bool|null $loggerOnly + * @param bool|null $loggerOnly * @return null|bool */ public function loggerOnly($loggerOnly = null) { - if(func_num_args() == 0) { + if (func_num_args() == 0) { return $this->loggerOnly; } @@ -223,12 +222,12 @@ class PlainTextHandler extends Handler /** * Get the frame args var_dump. * @param \Whoops\Exception\Frame $frame [description] - * @param integer $line [description] + * @param integer $line [description] * @return string */ private function getFrameArgsOutput(Frame $frame, $line) { - if($this->addTraceFunctionArgsToOutput() === false + if ($this->addTraceFunctionArgsToOutput() === false || $this->addTraceFunctionArgsToOutput() < $line) { return ''; } @@ -236,7 +235,7 @@ class PlainTextHandler extends Handler // Dump the arguments: ob_start(); var_dump($frame->getArgs()); - if(ob_get_length() > $this->getTraceFunctionArgsOutputLimit()) { + if (ob_get_length() > $this->getTraceFunctionArgsOutputLimit()) { // The argument var_dump is to big. // Discarded to limit memory usage. ob_clean(); @@ -258,7 +257,7 @@ class PlainTextHandler extends Handler */ private function getTraceOutput() { - if(! $this->addTraceToOutput()) { + if (! $this->addTraceToOutput()) { return ''; } $inspector = $this->getInspector(); @@ -267,12 +266,12 @@ class PlainTextHandler extends Handler $response = "\nStack trace:"; $line = 1; - foreach($frames as $frame) { + foreach ($frames as $frame) { /** @var Frame $frame */ $class = $frame->getClass(); $template = "\n%3d. %s->%s() %s:%d%s"; - if(! $class) { + if (! $class) { // Remove method arrow (->) from output. $template = "\n%3d. %s%s() %s:%d%s"; } @@ -298,7 +297,7 @@ class PlainTextHandler extends Handler */ public function handle() { - if(! $this->canProcess()) { + if (! $this->canProcess()) { return Handler::DONE; } @@ -312,15 +311,15 @@ class PlainTextHandler extends Handler $this->getTraceOutput() ); - if($this->getLogger()) { + if ($this->getLogger()) { $this->getLogger()->error($response); } - if(! $this->canOutput()) { + if (! $this->canOutput()) { return Handler::DONE; } - if(class_exists('\Whoops\Util\Misc') + if (class_exists('\Whoops\Util\Misc') && \Whoops\Util\Misc::canSendHeaders()) { header('Content-Type: text/plain'); } diff --git a/src/Whoops/Handler/PrettyPageHandler.php b/src/Whoops/Handler/PrettyPageHandler.php index fb709e5..95294ca 100644 --- a/src/Whoops/Handler/PrettyPageHandler.php +++ b/src/Whoops/Handler/PrettyPageHandler.php @@ -5,12 +5,12 @@ */ namespace Whoops\Handler; -use Whoops\Handler\Handler; -use Whoops\Util\Misc; -use Whoops\Util\TemplateHelper; -use Whoops\Exception\Formatter; + use InvalidArgumentException; use RuntimeException; +use Whoops\Exception\Formatter; +use Whoops\Util\Misc; +use Whoops\Util\TemplateHelper; class PrettyPageHandler extends Handler { @@ -71,7 +71,7 @@ class PrettyPageHandler extends Handler "sublime" => "subl://open?url=file://%file&line=%line", "textmate" => "txmt://open?url=file://%file&line=%line", "emacs" => "emacs://open?url=file://%file&line=%line", - "macvim" => "mvim://open/?url=file://%file&line=%line" + "macvim" => "mvim://open/?url=file://%file&line=%line", ); /** @@ -81,7 +81,7 @@ class PrettyPageHandler extends Handler { if (ini_get('xdebug.file_link_format') || extension_loaded('xdebug')) { // Register editor using xdebug's file_link_format option. - $this->editors['xdebug'] = function($file, $line) { + $this->editors['xdebug'] = function ($file, $line) { return str_replace(array('%f', '%l'), array($file, $line), ini_get('xdebug.file_link_format')); }; } @@ -98,8 +98,7 @@ class PrettyPageHandler extends Handler if (!$this->handleUnconditionally()) { // Check conditions for outputting HTML: // @todo: Make this more robust - if(php_sapi_name() === 'cli') { - + if (php_sapi_name() === 'cli') { // Help users who have been relying on an internal test value // fix their code to the proper method if (isset($_ENV['whoops-test'])) { @@ -114,7 +113,7 @@ class PrettyPageHandler extends Handler } // @todo: Make this more dynamic - $helper = new TemplateHelper; + $helper = new TemplateHelper(); $templateFile = $this->getResource("views/layout.html.php"); $cssFile = $this->getResource("css/whoops.base.css"); @@ -165,9 +164,9 @@ class PrettyPageHandler extends Handler "POST Data" => $_POST, "Files" => $_FILES, "Cookies" => $_COOKIE, - "Session" => isset($_SESSION) ? $_SESSION: array(), - "Environment Variables" => $_ENV - ) + "Session" => isset($_SESSION) ? $_SESSION : array(), + "Environment Variables" => $_ENV, + ), ); if (isset($customCssFile)) { @@ -176,7 +175,7 @@ class PrettyPageHandler extends Handler // Add extra entries list of data tables: // @todo: Consolidate addDataTable and addDataTableCallback - $extraTables = array_map(function($table) { + $extraTables = array_map(function ($table) { return $table instanceof \Closure ? $table() : $table; }, $this->getDataTables()); $vars["tables"] = array_merge($extraTables, $vars["tables"]); @@ -206,8 +205,8 @@ class PrettyPageHandler extends Handler * be flattened with print_r. * * @throws InvalidArgumentException If $callback is not callable - * @param string $label - * @param callable $callback Callable returning an associative array + * @param string $label + * @param callable $callback Callable returning an associative array */ public function addDataTableCallback($label, /* callable */ $callback) { @@ -215,7 +214,7 @@ class PrettyPageHandler extends Handler throw new InvalidArgumentException('Expecting callback argument to be callable'); } - $this->extraTables[$label] = function() use ($callback) { + $this->extraTables[$label] = function () use ($callback) { try { $result = call_user_func($callback); @@ -232,12 +231,12 @@ class PrettyPageHandler extends Handler * Returns all the extra data tables registered with this handler. * Optionally accepts a 'label' parameter, to only return the data * table under that label. - * @param string|null $label + * @param string|null $label * @return array[]|callable */ public function getDataTables($label = null) { - if($label !== null) { + if ($label !== null) { return isset($this->extraTables[$label]) ? $this->extraTables[$label] : array(); } @@ -249,19 +248,18 @@ class PrettyPageHandler extends Handler * Allows to disable all attempts to dynamically decide whether to * handle or return prematurely. * Set this to ensure that the handler will perform no matter what. - * @param bool|null $value + * @param bool|null $value * @return bool|null */ public function handleUnconditionally($value = null) { - if(func_num_args() == 0) { + if (func_num_args() == 0) { return $this->handleUnconditionally; } $this->handleUnconditionally = (bool) $value; } - /** * Adds an editor resolver, identified by a string * name, and that may be a string path, or a callable @@ -275,8 +273,8 @@ class PrettyPageHandler extends Handler * unlink($file); * return "http://stackoverflow.com"; * }); - * @param string $identifier - * @param string $resolver + * @param string $identifier + * @param string $resolver */ public function addEditor($identifier, $resolver) { @@ -295,11 +293,11 @@ class PrettyPageHandler extends Handler * $run->setEditor('sublime'); * * @throws InvalidArgumentException If invalid argument identifier provided - * @param string|callable $editor + * @param string|callable $editor */ public function setEditor($editor) { - if(!is_callable($editor) && !isset($this->editors[$editor])) { + if (!is_callable($editor) && !isset($this->editors[$editor])) { throw new InvalidArgumentException( "Unknown editor identifier: $editor. Known editors:" . implode(",", array_keys($this->editors)) @@ -316,28 +314,28 @@ class PrettyPageHandler extends Handler * file reference. * * @throws InvalidArgumentException If editor resolver does not return a string - * @param string $filePath - * @param int $line + * @param string $filePath + * @param int $line * @return false|string */ public function getEditorHref($filePath, $line) { - if($this->editor === null) { + if ($this->editor === null) { return false; } $editor = $this->editor; - if(is_string($editor)) { + if (is_string($editor)) { $editor = $this->editors[$editor]; } - if(is_callable($editor)) { + if (is_callable($editor)) { $editor = call_user_func($editor, $filePath, $line); } // Check that the editor is a string, and replace the // %line and %file placeholders: - if(!is_string($editor)) { + if (!is_string($editor)) { throw new InvalidArgumentException( __METHOD__ . " should always resolve to a string; got something else instead" ); @@ -377,7 +375,7 @@ class PrettyPageHandler extends Handler */ public function addResourcePath($path) { - if(!is_dir($path)) { + if (!is_dir($path)) { throw new InvalidArgumentException( "'$path' is not a valid directory" ); @@ -420,16 +418,16 @@ class PrettyPageHandler extends Handler { // If the resource was found before, we can speed things up // by caching its absolute, resolved path: - if(isset($this->resourceCache[$resource])) { + if (isset($this->resourceCache[$resource])) { return $this->resourceCache[$resource]; } // Search through available search paths, until we find the // resource we're after: - foreach($this->searchPaths as $path) { + foreach ($this->searchPaths as $path) { $fullPath = $path . "/$resource"; - if(is_file($fullPath)) { + if (is_file($fullPath)) { // Cache the result: $this->resourceCache[$resource] = $fullPath; return $fullPath; diff --git a/src/Whoops/Handler/SoapResponseHandler.php b/src/Whoops/Handler/SoapResponseHandler.php index 47e6bd7..2173dd7 100644 --- a/src/Whoops/Handler/SoapResponseHandler.php +++ b/src/Whoops/Handler/SoapResponseHandler.php @@ -6,7 +6,6 @@ namespace Whoops\Handler; -use Whoops\Handler\Handler; /** * Catches an exception and converts it to an Soap XML @@ -31,7 +30,8 @@ class SoapResponseHandler extends Handler /** * Converts a Exception into a SoapFault XML */ - private function toXml(\Exception $exception) { + private function toXml(\Exception $exception) + { $xml = ''; $xml .= ''; $xml .= ''; diff --git a/src/Whoops/Handler/XmlResponseHandler.php b/src/Whoops/Handler/XmlResponseHandler.php index 7624a73..61ee86c 100644 --- a/src/Whoops/Handler/XmlResponseHandler.php +++ b/src/Whoops/Handler/XmlResponseHandler.php @@ -7,7 +7,6 @@ namespace Whoops\Handler; use SimpleXMLElement; -use Whoops\Handler\Handler; use Whoops\Exception\Formatter; /** @@ -23,12 +22,12 @@ class XmlResponseHandler extends Handler private $returnFrames = false; /** - * @param bool|null $returnFrames + * @param bool|null $returnFrames * @return bool|$this */ public function addTraceToOutput($returnFrames = null) { - if(func_num_args() == 0) { + if (func_num_args() == 0) { return $this->returnFrames; } @@ -54,18 +53,16 @@ class XmlResponseHandler extends Handler } /** - * @param SimpleXMLElement $node Node to append data to, will be modified in place - * @param array|Traversable $data - * @return SimpleXMLElement The modified node, for chaining + * @param SimpleXMLElement $node Node to append data to, will be modified in place + * @param array|Traversable $data + * @return SimpleXMLElement The modified node, for chaining */ private static function addDataToNode(\SimpleXMLElement $node, $data) { assert('is_array($data) || $node instanceof Traversable'); - foreach($data as $key => $value) - { - if (is_numeric($key)) - { + foreach ($data as $key => $value) { + if (is_numeric($key)) { // Convert the key to a valid string $key = "unknownNode_". (string) $key; } @@ -73,13 +70,10 @@ class XmlResponseHandler extends Handler // Delete any char not allowed in XML element names $key = preg_replace('/[^a-z0-9\-\_\.\:]/i', '', $key); - if (is_array($value)) - { + if (is_array($value)) { $child = $node->addChild($key); self::addDataToNode($child, $value); - } - else - { + } else { $value = str_replace('&', '&', print_r($value, true)); $node->addChild($key, $value); } @@ -91,8 +85,8 @@ class XmlResponseHandler extends Handler /** * The main function for converting to an XML document. * - * @param array|Traversable $data - * @return string XML + * @param array|Traversable $data + * @return string XML */ private static function toXml($data) { diff --git a/src/Whoops/Provider/Phalcon/WhoopsServiceProvider.php b/src/Whoops/Provider/Phalcon/WhoopsServiceProvider.php index 89dc8f7..d8d5781 100644 --- a/src/Whoops/Provider/Phalcon/WhoopsServiceProvider.php +++ b/src/Whoops/Provider/Phalcon/WhoopsServiceProvider.php @@ -6,11 +6,11 @@ namespace Whoops\Provider\Phalcon; -use Whoops\Run; -use Whoops\Handler\PrettyPageHandler; -use Whoops\Handler\JsonResponseHandler; use Phalcon\DI; use Phalcon\DI\Exception; +use Whoops\Handler\JsonResponseHandler; +use Whoops\Handler\PrettyPageHandler; +use Whoops\Run; class WhoopsServiceProvider { @@ -24,13 +24,13 @@ class WhoopsServiceProvider } // There's only ever going to be one error page...right? - $di->setShared('whoops.pretty_page_handler', function() { - return new PrettyPageHandler; + $di->setShared('whoops.pretty_page_handler', function () { + return new PrettyPageHandler(); }); // There's only ever going to be one error page...right? - $di->setShared('whoops.json_response_handler', function() { - $jsonHandler = new JsonResponseHandler; + $di->setShared('whoops.json_response_handler', function () { + $jsonHandler = new JsonResponseHandler(); $jsonHandler->onlyForAjaxRequests(true); return $jsonHandler; }); @@ -40,7 +40,7 @@ class WhoopsServiceProvider // This works by adding a new handler to the stack that runs // before the error page, retrieving the shared page handler // instance, and working with it to add new data tables - $phalcon_info_handler = function() use($di) { + $phalcon_info_handler = function () use ($di) { try { $request = $di['request']; } catch (Exception $e) { @@ -54,7 +54,7 @@ class WhoopsServiceProvider 'URI' => $request->getScheme().'://'.$request->getServer('HTTP_HOST').$request->getServer('REQUEST_URI'), 'Request URI' => $request->getServer('REQUEST_URI'), 'Path Info' => $request->getServer('PATH_INFO'), - 'Query String'=> $request->getServer('QUERY_STRING') ?: '', + 'Query String' => $request->getServer('QUERY_STRING') ?: '', 'HTTP Method' => $request->getMethod(), 'Script Name' => $request->getServer('SCRIPT_NAME'), //'Base Path' => $request->getBasePath(), @@ -65,8 +65,8 @@ class WhoopsServiceProvider )); }; - $di->setShared('whoops', function() use($di, $phalcon_info_handler) { - $run = new Run; + $di->setShared('whoops', function () use ($di,$phalcon_info_handler) { + $run = new Run(); $run->pushHandler($di['whoops.pretty_page_handler']); $run->pushHandler($phalcon_info_handler); $run->pushHandler($di['whoops.json_response_handler']); diff --git a/src/Whoops/Provider/Silex/WhoopsServiceProvider.php b/src/Whoops/Provider/Silex/WhoopsServiceProvider.php index c3b758e..69d01d3 100644 --- a/src/Whoops/Provider/Silex/WhoopsServiceProvider.php +++ b/src/Whoops/Provider/Silex/WhoopsServiceProvider.php @@ -5,16 +5,17 @@ */ namespace Whoops\Provider\Silex; -use Whoops\Run; -use Whoops\Handler\Handler; -use Whoops\Handler\PlainTextHandler; -use Whoops\Handler\PrettyPageHandler; -use Silex\ServiceProviderInterface; + +use RuntimeException; use Silex\Application; +use Silex\ServiceProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\HttpException; -use RuntimeException; +use Whoops\Handler\Handler; +use Whoops\Handler\PlainTextHandler; +use Whoops\Handler\PrettyPageHandler; +use Whoops\Run; class WhoopsServiceProvider implements ServiceProviderInterface { @@ -24,11 +25,11 @@ class WhoopsServiceProvider implements ServiceProviderInterface public function register(Application $app) { // There's only ever going to be one error page...right? - $app['whoops.error_page_handler'] = $app->share(function() { - if(PHP_SAPI === 'cli') { - return new PlainTextHandler; + $app['whoops.error_page_handler'] = $app->share(function () { + if (PHP_SAPI === 'cli') { + return new PlainTextHandler(); } else { - return new PrettyPageHandler; + return new PrettyPageHandler(); } }); @@ -37,7 +38,7 @@ class WhoopsServiceProvider implements ServiceProviderInterface // This works by adding a new handler to the stack that runs // before the error page, retrieving the shared page handler // instance, and working with it to add new data tables - $app['whoops.silex_info_handler'] = $app->protect(function() use($app) { + $app['whoops.silex_info_handler'] = $app->protect(function () use ($app) { try { /** @var Request $request */ $request = $app['request']; @@ -50,8 +51,7 @@ class WhoopsServiceProvider implements ServiceProviderInterface /** @var Handler $errorPageHandler */ $errorPageHandler = $app["whoops.error_page_handler"]; - if ($errorPageHandler instanceof PrettyPageHandler) - { + if ($errorPageHandler instanceof PrettyPageHandler) { /** @var PrettyPageHandler $errorPageHandler */ // General application info: @@ -60,7 +60,7 @@ class WhoopsServiceProvider implements ServiceProviderInterface 'Locale' => $app['locale'], 'Route Class' => $app['route_class'], 'Dispatcher Class' => $app['dispatcher_class'], - 'Application Class'=> get_class($app) + 'Application Class' => get_class($app), )); // Request info: @@ -68,7 +68,7 @@ class WhoopsServiceProvider implements ServiceProviderInterface 'URI' => $request->getUri(), 'Request URI' => $request->getRequestUri(), 'Path Info' => $request->getPathInfo(), - 'Query String'=> $request->getQueryString() ?: '', + 'Query String' => $request->getQueryString() ?: '', 'HTTP Method' => $request->getMethod(), 'Script Name' => $request->getScriptName(), 'Base Path' => $request->getBasePath(), @@ -80,15 +80,15 @@ class WhoopsServiceProvider implements ServiceProviderInterface } }); - $app['whoops'] = $app->share(function() use($app) { - $run = new Run; + $app['whoops'] = $app->share(function () use ($app) { + $run = new Run(); $run->allowQuit(false); $run->pushHandler($app['whoops.error_page_handler']); $run->pushHandler($app['whoops.silex_info_handler']); return $run; }); - $app->error(function($e) use ($app){ + $app->error(function ($e) use ($app) { $method = Run::EXCEPTION_HANDLER; ob_start(); @@ -105,5 +105,7 @@ class WhoopsServiceProvider implements ServiceProviderInterface /** * @see Silex\ServiceProviderInterface::boot */ - public function boot(Application $app) {} + public function boot(Application $app) + { + } } diff --git a/src/Whoops/Resources/views/env_details.html.php b/src/Whoops/Resources/views/env_details.html.php index 4f4993d..a3e0a57 100644 --- a/src/Whoops/Resources/views/env_details.html.php +++ b/src/Whoops/Resources/views/env_details.html.php @@ -1,10 +1,10 @@
- $data): ?> + $data): ?>
- + @@ -12,7 +12,7 @@ - $value): ?> + $value): ?> @@ -29,7 +29,7 @@
- $handler): ?> + $handler): ?>
. escape(get_class($handler)) ?>
diff --git a/src/Whoops/Resources/views/frame_code.html.php b/src/Whoops/Resources/views/frame_code.html.php index 4c840b9..4ca28a6 100644 --- a/src/Whoops/Resources/views/frame_code.html.php +++ b/src/Whoops/Resources/views/frame_code.html.php @@ -2,12 +2,12 @@ * @todo: This should PROBABLY be done on-demand, lest * we get 200 frames to process. */ ?>
- $frame): ?> + $frame): ?> getLine(); ?>
getFile(); ?> - getEditorHref($filePath, (int) $line)): ?> + getEditorHref($filePath, (int) $line)): ?> Open: escape($filePath ?: '<#unknown>') ?> @@ -18,14 +18,14 @@
getFileLines($line - 8, 10); // getFileLines can return null if there is no source code if ($range): - $range = array_map(function($line){ return empty($line) ? ' ' : $line;}, $range); + $range = array_map(function ($line) { return empty($line) ? ' ' : $line;}, $range); $start = key($range) + 1; $code = join("\n", $range); ?> @@ -38,7 +38,7 @@ $comments = $frame->getComments(); ?>
- $comment): ?> + $comment): ?>
escape($context) ?> diff --git a/src/Whoops/Resources/views/frame_list.html.php b/src/Whoops/Resources/views/frame_list.html.php index ad1de59..fd9cf7b 100644 --- a/src/Whoops/Resources/views/frame_list.html.php +++ b/src/Whoops/Resources/views/frame_list.html.php @@ -1,7 +1,7 @@ - $frame): ?> + $frame): ?>
. diff --git a/src/Whoops/Resources/views/header.html.php b/src/Whoops/Resources/views/header.html.php index fcc3a5d..32eed37 100644 --- a/src/Whoops/Resources/views/header.html.php +++ b/src/Whoops/Resources/views/header.html.php @@ -1,13 +1,13 @@

- $nameSection): ?> - + $nameSection): ?> + escape($nameSection) ?> escape($nameSection) . ' \\' ?> - + (escape($code) ?>) diff --git a/src/Whoops/Run.php b/src/Whoops/Run.php index 64a2b00..6f9ada0 100644 --- a/src/Whoops/Run.php +++ b/src/Whoops/Run.php @@ -5,13 +5,14 @@ */ namespace Whoops; -use Whoops\Handler\HandlerInterface; -use Whoops\Handler\Handler; -use Whoops\Handler\CallbackHandler; -use Whoops\Exception\Inspector; -use Whoops\Exception\ErrorException; -use InvalidArgumentException; + use Exception; +use InvalidArgumentException; +use Whoops\Exception\ErrorException; +use Whoops\Exception\Inspector; +use Whoops\Handler\CallbackHandler; +use Whoops\Handler\Handler; +use Whoops\Handler\HandlerInterface; class Run { @@ -34,17 +35,17 @@ class Run /** * Pushes a handler to the end of the stack * - * @throws InvalidArgumentException If argument is not callable or instance of HandlerInterface + * @throws InvalidArgumentException If argument is not callable or instance of HandlerInterface * @param Callable|HandlerInterface $handler * @return Run */ public function pushHandler($handler) { - if(is_callable($handler)) { + if (is_callable($handler)) { $handler = new CallbackHandler($handler); } - if(!$handler instanceof HandlerInterface) { + if (!$handler instanceof HandlerInterface) { throw new InvalidArgumentException( "Argument to " . __METHOD__ . " must be a callable, or instance of" . "Whoops\\Handler\\HandlerInterface" @@ -101,7 +102,7 @@ class Run */ public function register() { - if(!$this->isRegistered) { + if (!$this->isRegistered) { // Workaround PHP bug 42098 // https://bugs.php.net/bug.php?id=42098 class_exists("\\Whoops\\Exception\\ErrorException"); @@ -125,7 +126,7 @@ class Run */ public function unregister() { - if($this->isRegistered) { + if ($this->isRegistered) { restore_exception_handler(); restore_error_handler(); @@ -137,12 +138,12 @@ class Run /** * Should Whoops allow Handlers to force the script to quit? - * @param bool|int $exit + * @param bool|int $exit * @return bool */ public function allowQuit($exit = null) { - if(func_num_args() == 0) { + if (func_num_args() == 0) { return $this->allowQuit; } @@ -151,8 +152,8 @@ class Run /** * Silence particular errors in particular files - * @param array|string $patterns List or a single regex pattern to match - * @param int $levels Defaults to E_STRICT | E_DEPRECATED + * @param array|string $patterns List or a single regex pattern to match + * @param int $levels Defaults to E_STRICT | E_DEPRECATED * @return \Whoops\Run */ public function silenceErrorsInPaths($patterns, $levels = 10240) @@ -182,15 +183,15 @@ class Run */ public function sendHttpCode($code = null) { - if(func_num_args() == 0) { + if (func_num_args() == 0) { return $this->sendHttpCode; } - if(!$code) { + if (!$code) { return $this->sendHttpCode = false; } - if($code === true) { + if ($code === true) { $code = 500; } @@ -206,12 +207,12 @@ class Run /** * Should Whoops push output directly to the client? * If this is false, output will be returned by handleException - * @param bool|int $send + * @param bool|int $send * @return bool */ public function writeToOutput($send = null) { - if(func_num_args() == 0) { + if (func_num_args() == 0) { return $this->sendOutput; } @@ -223,7 +224,7 @@ class Run * page. * * @param Exception $exception - * @return string Output generated by handlers + * @return string Output generated by handlers */ public function handleException(Exception $exception) { @@ -246,7 +247,7 @@ class Run $handlerResponse = $handler->handle($exception); - if(in_array($handlerResponse, array(Handler::LAST_HANDLER, Handler::QUIT))) { + if (in_array($handlerResponse, array(Handler::LAST_HANDLER, Handler::QUIT))) { // The Handler has handled the exception in some way, and // wishes to quit execution (Handler::QUIT), or skip any // other handlers (Handler::LAST_HANDLER). If $this->allowQuit @@ -259,22 +260,23 @@ class Run $output = ob_get_clean(); - // If we're allowed to, send output generated by handlers directly // to the output, otherwise, and if the script doesn't quit, return // it so that it may be used by the caller - if($this->writeToOutput()) { + if ($this->writeToOutput()) { // @todo Might be able to clean this up a bit better // If we're going to quit execution, cleanup all other output // buffers before sending our own output: - if($willQuit) { - while (ob_get_level() > 0) ob_end_clean(); + if ($willQuit) { + while (ob_get_level() > 0) { + ob_end_clean(); + } } $this->writeToOutputNow($output); } - if($willQuit) { + if ($willQuit) { exit(1); } @@ -300,7 +302,7 @@ class Run foreach ($this->silencedPatterns as $entry) { $pathMatches = (bool) preg_match($entry["pattern"], $file); $levelMatches = $level & $entry["levels"]; - if ($pathMatches && $levelMatches) { + if ($pathMatches && $levelMatches) { // Ignore the error, abort handling return true; } @@ -346,12 +348,12 @@ class Run /** * Echo something to the browser - * @param string $output + * @param string $output * @return $this */ private function writeToOutputNow($output) { - if($this->sendHttpCode() && \Whoops\Util\Misc::canSendHeaders()) { + if ($this->sendHttpCode() && \Whoops\Util\Misc::canSendHeaders()) { $httpCode = $this->sendHttpCode(); if (function_exists('http_response_code')) { diff --git a/src/Whoops/Util/Misc.php b/src/Whoops/Util/Misc.php index a7366bf..d38dbbf 100644 --- a/src/Whoops/Util/Misc.php +++ b/src/Whoops/Util/Misc.php @@ -8,7 +8,7 @@ namespace Whoops\Util; class Misc { - /** + /** * Can we at this point in time send HTTP headers? * * Currently this checks if we are even serving an HTTP request, @@ -18,27 +18,27 @@ class Misc * * @return bool */ - public static function canSendHeaders() - { - return isset($_SERVER["REQUEST_URI"]) && !headers_sent(); - } + public static function canSendHeaders() + { + return isset($_SERVER["REQUEST_URI"]) && !headers_sent(); + } - /** + /** * Translate ErrorException code into the represented constant. * * @param int $error_code * @return string */ - public static function translateErrorCode($error_code) - { - $constants = get_defined_constants(true); - if (array_key_exists('Core' , $constants)) { - foreach ($constants['Core'] as $constant => $value) { - if (substr($constant, 0, 2) == 'E_' && $value == $error_code) { - return $constant; - } - } - } - return "E_UNKNOWN"; - } + public static function translateErrorCode($error_code) + { + $constants = get_defined_constants(true); + if (array_key_exists('Core' , $constants)) { + foreach ($constants['Core'] as $constant => $value) { + if (substr($constant, 0, 2) == 'E_' && $value == $error_code) { + return $constant; + } + } + } + return "E_UNKNOWN"; + } } diff --git a/src/Whoops/Util/TemplateHelper.php b/src/Whoops/Util/TemplateHelper.php index de24af5..71690de 100644 --- a/src/Whoops/Util/TemplateHelper.php +++ b/src/Whoops/Util/TemplateHelper.php @@ -86,11 +86,11 @@ class TemplateHelper // Pass the helper to the template: $variables["tpl"] = $this; - if($additionalVariables !== null) { + if ($additionalVariables !== null) { $variables = array_replace($variables, $additionalVariables); } - call_user_func(function(){ + call_user_func(function () { extract(func_get_arg(1)); require func_get_arg(0); }, $template, $variables); @@ -129,8 +129,7 @@ class TemplateHelper public function getVariable($variableName, $defaultValue = null) { return isset($this->variables[$variableName]) ? - $this->variables[$variableName] : $defaultValue - ; + $this->variables[$variableName] : $defaultValue; } /** diff --git a/src/deprecated/Zend/ExceptionStrategy.php b/src/deprecated/Zend/ExceptionStrategy.php index acfb355..58c72f0 100644 --- a/src/deprecated/Zend/ExceptionStrategy.php +++ b/src/deprecated/Zend/ExceptionStrategy.php @@ -7,24 +7,26 @@ namespace Whoops\Provider\Zend; use Whoops\Run; -use Zend\Mvc\View\Http\ExceptionStrategy as BaseExceptionStrategy; -use Zend\Mvc\MvcEvent; -use Zend\Mvc\Application; use Zend\Http\Response; +use Zend\Mvc\Application; +use Zend\Mvc\MvcEvent; +use Zend\Mvc\View\Http\ExceptionStrategy as BaseExceptionStrategy; /** * @deprecated Use https://github.com/ghislainf/zf2-whoops */ -class ExceptionStrategy extends BaseExceptionStrategy { - +class ExceptionStrategy extends BaseExceptionStrategy +{ protected $run; - public function __construct(Run $run) { + public function __construct(Run $run) + { $this->run = $run; return $this; } - public function prepareExceptionViewModel(MvcEvent $event) { + public function prepareExceptionViewModel(MvcEvent $event) + { // Do nothing if no error in the event $error = $event->getError(); if (empty($error)) { @@ -47,7 +49,7 @@ class ExceptionStrategy extends BaseExceptionStrategy { case Application::ERROR_EXCEPTION: default: $exception = $event->getParam('exception'); - if($exception) { + if ($exception) { $response = $event->getResponse(); if (!$response || $response->getStatusCode() === 200) { header('HTTP/1.0 500 Internal Server Error', true, 500); @@ -58,5 +60,4 @@ class ExceptionStrategy extends BaseExceptionStrategy { break; } } - } diff --git a/src/deprecated/Zend/Module.php b/src/deprecated/Zend/Module.php index 61456e1..545f8a5 100644 --- a/src/deprecated/Zend/Module.php +++ b/src/deprecated/Zend/Module.php @@ -18,13 +18,12 @@ namespace Whoops; -use Whoops\Run; -use Whoops\Provider\Zend\ExceptionStrategy; -use Whoops\Provider\Zend\RouteNotFoundStrategy; use Whoops\Handler\JsonResponseHandler; use Whoops\Handler\PrettyPageHandler; -use Zend\EventManager\EventInterface; +use Whoops\Provider\Zend\ExceptionStrategy; +use Whoops\Provider\Zend\RouteNotFoundStrategy; use Zend\Console\Request as ConsoleRequest; +use Zend\EventManager\EventInterface; /** * @deprecated Use https://github.com/ghislainf/zf2-whoops @@ -43,7 +42,6 @@ class Module $prettyPageHandler->setEditor($config['view_manager']['editor']); } - $this->run = new Run(); $this->run->register(); $this->run->pushHandler($prettyPageHandler); @@ -71,8 +69,9 @@ class Module $config = $services->get('Config'); //Display exceptions based on configuration and console mode - if ($request instanceof ConsoleRequest || empty($config['view_manager']['display_exceptions'])) + if ($request instanceof ConsoleRequest || empty($config['view_manager']['display_exceptions'])) { return; + } $jsonHandler = new JsonResponseHandler(); @@ -105,5 +104,4 @@ class Module //Detach default RouteNotFoundStrategy $services->get('Zend\Mvc\View\Http\RouteNotFoundStrategy')->detach($events); } - } diff --git a/src/deprecated/Zend/RouteNotFoundStrategy.php b/src/deprecated/Zend/RouteNotFoundStrategy.php index 1934c5b..f1eb7ea 100644 --- a/src/deprecated/Zend/RouteNotFoundStrategy.php +++ b/src/deprecated/Zend/RouteNotFoundStrategy.php @@ -7,23 +7,25 @@ namespace Whoops\Provider\Zend; use Whoops\Run; -use Zend\Mvc\View\Http\RouteNotFoundStrategy as BaseRouteNotFoundStrategy; use Zend\Mvc\MvcEvent; +use Zend\Mvc\View\Http\RouteNotFoundStrategy as BaseRouteNotFoundStrategy; use Zend\Stdlib\ResponseInterface as Response; use Zend\View\Model\ViewModel; /** * @deprecated Use https://github.com/ghislainf/zf2-whoops */ -class RouteNotFoundStrategy extends BaseRouteNotFoundStrategy { - +class RouteNotFoundStrategy extends BaseRouteNotFoundStrategy +{ protected $run; - public function __construct(Run $run) { + public function __construct(Run $run) + { $this->run = $run; } - public function prepareNotFoundViewModel(MvcEvent $e) { + public function prepareNotFoundViewModel(MvcEvent $e) + { $vars = $e->getResult(); if ($vars instanceof Response) { // Already have a response as the result @@ -62,5 +64,4 @@ class RouteNotFoundStrategy extends BaseRouteNotFoundStrategy { throw new \Exception($model->getVariable('message') . ' ' . $model->getVariable('reason')); } - } diff --git a/src/deprecated/Zend/module.config.example.php b/src/deprecated/Zend/module.config.example.php index 1ba0a29..42be30d 100644 --- a/src/deprecated/Zend/module.config.example.php +++ b/src/deprecated/Zend/module.config.example.php @@ -14,7 +14,7 @@ return array( 'json_exceptions' => array( 'display' => true, 'ajax_only' => true, - 'show_trace' => true - ) + 'show_trace' => true, + ), ), ); diff --git a/tests/Whoops/Exception/FormatterTest.php b/tests/Whoops/Exception/FormatterTest.php index 97eb06a..7fce399 100644 --- a/tests/Whoops/Exception/FormatterTest.php +++ b/tests/Whoops/Exception/FormatterTest.php @@ -5,15 +5,16 @@ */ namespace Whoops\Exception; + use Whoops\TestCase; class FormatterTest extends TestCase { - public function testPlain() - { - $msg = 'Sample exception message foo'; - $output = Formatter::formatExceptionPlain(new Inspector(new \Exception($msg))); - $this->assertContains($msg, $output); - $this->assertContains('Stacktrace', $output); - } + public function testPlain() + { + $msg = 'Sample exception message foo'; + $output = Formatter::formatExceptionPlain(new Inspector(new \Exception($msg))); + $this->assertContains($msg, $output); + $this->assertContains('Stacktrace', $output); + } } diff --git a/tests/Whoops/Exception/FrameCollectionTest.php b/tests/Whoops/Exception/FrameCollectionTest.php index 04f4bd3..b25ac86 100644 --- a/tests/Whoops/Exception/FrameCollectionTest.php +++ b/tests/Whoops/Exception/FrameCollectionTest.php @@ -5,9 +5,8 @@ */ namespace Whoops\Exception; -use Whoops\Exception\FrameCollection; + use Whoops\TestCase; -use Mockery as m; class FrameCollectionTest extends TestCase { @@ -29,19 +28,19 @@ class FrameCollectionTest extends TestCase 'line' => $id, 'function' => 'test-' . $id, 'class' => 'MyClass', - 'args' => array(true, 'hello') + 'args' => array(true, 'hello'), ); } /** - * @param int $total + * @param int $total * @return array */ public function getFrameDataList($total) { $total = max((int) $total, 1); $self = $this; - $frames = array_map(function() use($self) { + $frames = array_map(function () use ($self) { return $self->getFrameData(); }, range(1, $total)); @@ -49,12 +48,12 @@ class FrameCollectionTest extends TestCase } /** - * @param array $frames + * @param array $frames * @return Whoops\Exception\FrameCollection */ private function getFrameCollectionInstance($frames = null) { - if($frames === null) { + if ($frames === null) { $frames = $this->getFrameDataList(10); } @@ -108,7 +107,7 @@ class FrameCollectionTest extends TestCase $frames = $this->getFrameCollectionInstance(); // Filter out all frames with a line number under 6 - $frames->filter(function($frame) { + $frames->filter(function ($frame) { return $frame->getLine() <= 5; }); @@ -123,7 +122,7 @@ class FrameCollectionTest extends TestCase $frames = $this->getFrameCollectionInstance(); // Filter out all frames with a line number under 6 - $frames->map(function($frame) { + $frames->map(function ($frame) { $frame->addComment("This is cool", "test"); return $frame; }); @@ -131,7 +130,6 @@ class FrameCollectionTest extends TestCase $this->assertCount(10, $frames); } - /** * @covers Whoops\Exception\FrameCollection::map * @expectedException UnexpectedValueException @@ -141,7 +139,7 @@ class FrameCollectionTest extends TestCase $frames = $this->getFrameCollectionInstance(); // Filter out all frames with a line number under 6 - $frames->map(function($frame) { + $frames->map(function ($frame) { return "bajango"; }); } @@ -155,7 +153,7 @@ class FrameCollectionTest extends TestCase $frames = $frames->getArray(); $this->assertCount(10, $frames); - foreach($frames as $frame) { + foreach ($frames as $frame) { $this->assertInstanceOf('Whoops\\Exception\\Frame', $frame); } } @@ -178,7 +176,7 @@ class FrameCollectionTest extends TestCase public function testCollectionIsIterable() { $frames = $this->getFrameCollectionInstance(); - foreach($frames as $frame) { + foreach ($frames as $frame) { $this->assertInstanceOf('Whoops\\Exception\\Frame', $frame); } } @@ -193,26 +191,26 @@ class FrameCollectionTest extends TestCase $serializedFrames = serialize($frames); $newFrames = unserialize($serializedFrames); - foreach($newFrames as $frame) { + foreach ($newFrames as $frame) { $this->assertInstanceOf('Whoops\\Exception\\Frame', $frame); } } - /** * @covers Whoops\Exception\FrameCollection::topDiff */ - public function testTopDiff(){ + public function testTopDiff() + { $commonFrameTail = $this->getFrameDataList(3); $diffFrame = array('line' => $this->frameIdCounter) + $this->getFrameData(); $frameCollection1 = new FrameCollection(array_merge(array( - $diffFrame + $diffFrame, ), $commonFrameTail)); $frameCollection2 = new FrameCollection(array_merge(array( - $this->getFrameData() + $this->getFrameData(), ), $commonFrameTail)); $diff = $frameCollection1->topDiff($frameCollection2); diff --git a/tests/Whoops/Exception/FrameTest.php b/tests/Whoops/Exception/FrameTest.php index 3d26bb7..d85d1ab 100644 --- a/tests/Whoops/Exception/FrameTest.php +++ b/tests/Whoops/Exception/FrameTest.php @@ -5,9 +5,8 @@ */ namespace Whoops\Exception; -use Whoops\Exception\Frame; + use Whoops\TestCase; -use Mockery as m; class FrameTest extends TestCase { @@ -21,7 +20,7 @@ class FrameTest extends TestCase 'line' => 0, 'function' => 'test', 'class' => 'MyClass', - 'args' => array(true, 'hello') + 'args' => array(true, 'hello'), ); } @@ -31,7 +30,7 @@ class FrameTest extends TestCase */ private function getFrameInstance($data = null) { - if($data === null) { + if ($data === null) { $data = $this->getFrameData(); } @@ -141,7 +140,7 @@ class FrameTest extends TestCase $testComments = array( 'Dang, yo!', 'Errthangs broken!', - 'Dayumm!' + 'Dayumm!', ); $frame->addComment($testComments[0]); @@ -167,7 +166,7 @@ class FrameTest extends TestCase $testComments = array( array('Dang, yo!', 'test'), array('Errthangs broken!', 'test'), - 'Dayumm!' + 'Dayumm!', ); $frame->addComment($testComments[0][0], $testComments[0][1]); @@ -210,7 +209,8 @@ class FrameTest extends TestCase /** * @covers Whoops\Exception\Frame::equals */ - public function testEquals(){ + public function testEquals() + { $frame1 = $this->getFrameInstance(array('line' => 1, 'file' => 'test-file.php')); $frame2 = $this->getFrameInstance(array('line' => 1, 'file' => 'test-file.php')); $this->assertTrue ($frame1->equals($frame2)); diff --git a/tests/Whoops/Exception/InspectorTest.php b/tests/Whoops/Exception/InspectorTest.php index 9302a97..c8b47de 100644 --- a/tests/Whoops/Exception/InspectorTest.php +++ b/tests/Whoops/Exception/InspectorTest.php @@ -5,16 +5,16 @@ */ namespace Whoops\Exception; -use Whoops\Exception\Inspector; -use Whoops\TestCase; + use Exception; +use Whoops\TestCase; class InspectorTest extends TestCase { /** - * @param string $message - * @param int $code - * @param Exception $previous + * @param string $message + * @param int $code + * @param Exception $previous * @return Exception */ protected function getException($message = null, $code = 0, Exception $previous = null) @@ -23,7 +23,7 @@ class InspectorTest extends TestCase } /** - * @param Exception $exception|null + * @param Exception $exception|null * @return Whoops\Exception\Inspector */ protected function getInspectorInstance(Exception $exception = null) @@ -34,7 +34,7 @@ class InspectorTest extends TestCase /** * @covers Whoops\Exception\Inspector::getFrames */ - public function testCorrectNestedFrames($value='') + public function testCorrectNestedFrames($value = '') { // Create manually to have a different line number from the outer $inner = new Exception('inner'); diff --git a/tests/Whoops/Handler/JsonResponseHandlerTest.php b/tests/Whoops/Handler/JsonResponseHandlerTest.php index dcb70ae..187778e 100644 --- a/tests/Whoops/Handler/JsonResponseHandlerTest.php +++ b/tests/Whoops/Handler/JsonResponseHandlerTest.php @@ -5,9 +5,9 @@ */ namespace Whoops\Handler; -use Whoops\TestCase; -use Whoops\Handler\JsonResponseHandler; + use RuntimeException; +use Whoops\TestCase; class JsonResponseHandlerTest extends TestCase { @@ -16,7 +16,7 @@ class JsonResponseHandlerTest extends TestCase */ private function getHandler() { - return new JsonResponseHandler; + return new JsonResponseHandler(); } /** diff --git a/tests/Whoops/Handler/PlainTextHandlerTest.php b/tests/Whoops/Handler/PlainTextHandlerTest.php index c1c3db6..a69dad4 100644 --- a/tests/Whoops/Handler/PlainTextHandlerTest.php +++ b/tests/Whoops/Handler/PlainTextHandlerTest.php @@ -5,16 +5,16 @@ */ namespace Whoops\Handler; -use Whoops\TestCase; -use Whoops\Handler\PlainTextHandler; + use RuntimeException; use StdClass; +use Whoops\TestCase; class PlainTextHandlerTest extends TestCase { /** - * @throws InvalidArgumentException If argument is not null or a LoggerInterface - * @param Psr\Log\LoggerInterface|null $logger + * @throws InvalidArgumentException If argument is not null or a LoggerInterface + * @param Psr\Log\LoggerInterface|null $logger * @return Whoops\Handler\PlainTextHandler */ private function getHandler($logger = null) @@ -45,8 +45,7 @@ class PlainTextHandlerTest extends TestCase $loggerOnly = false, $onlyForCommandLine = false, $outputOnlyIfCommandLine = true - ) - { + ) { $handler = $this->getHandler(); $handler->addTraceToOutput($withTrace); $handler->addTraceFunctionArgsToOutput($withTraceArgs); @@ -301,7 +300,6 @@ class PlainTextHandlerTest extends TestCase $lines = explode("\n", $text); - // Check that the response has the correct value: $this->assertEquals('Stack trace:', $lines[1]); @@ -313,7 +311,7 @@ class PlainTextHandlerTest extends TestCase 'Whoops\Handler\PlainTextHandlerTest', 'getException', __FILE__, - 62 + 61 ), $lines[3] ); @@ -355,7 +353,7 @@ class PlainTextHandlerTest extends TestCase 'Whoops\Handler\PlainTextHandlerTest', 'getException', __FILE__, - 62 + 61 ), $lines[8] ); @@ -402,7 +400,7 @@ class PlainTextHandlerTest extends TestCase 'Whoops\Handler\PlainTextHandlerTest', 'getException', __FILE__, - 62 + 61 ), $lines[8] ); diff --git a/tests/Whoops/Handler/PrettyPageHandlerTest.php b/tests/Whoops/Handler/PrettyPageHandlerTest.php index 0b55b15..29751ec 100644 --- a/tests/Whoops/Handler/PrettyPageHandlerTest.php +++ b/tests/Whoops/Handler/PrettyPageHandlerTest.php @@ -5,10 +5,10 @@ */ namespace Whoops\Handler; -use Whoops\TestCase; -use Whoops\Handler\PrettyPageHandler; -use RuntimeException; + use InvalidArgumentException; +use RuntimeException; +use Whoops\TestCase; class PrettyPageHandlerTest extends TestCase { @@ -17,7 +17,7 @@ class PrettyPageHandlerTest extends TestCase */ private function getHandler() { - $handler = new PrettyPageHandler; + $handler = new PrettyPageHandler(); $handler->handleUnconditionally(); return $handler; } @@ -27,7 +27,7 @@ class PrettyPageHandlerTest extends TestCase */ public function getException() { - return new RuntimeException; + return new RuntimeException(); } /** @@ -102,12 +102,12 @@ class PrettyPageHandlerTest extends TestCase $tableOne = array( 'ice' => 'cream', - 'ice-ice' => 'baby' + 'ice-ice' => 'baby', ); $tableTwo = array( - 'dolan' =>'pls', - 'time' => time() + 'dolan' => 'pls', + 'time' => time(), ); $handler->addDataTable('table 1', $tableOne); @@ -136,7 +136,7 @@ class PrettyPageHandlerTest extends TestCase $handler = $this->getHandler(); $this->assertEmpty($handler->getDataTables()); - $table1 = function() { + $table1 = function () { return array( 'hammer' => 'time', 'foo' => 'bar', @@ -144,7 +144,7 @@ class PrettyPageHandlerTest extends TestCase }; $expected1 = array('hammer' => 'time', 'foo' => 'bar'); - $table2 = function() use ($expected1) { + $table2 = function () use ($expected1) { return array( 'another' => 'table', 'this' => $expected1, @@ -213,7 +213,7 @@ class PrettyPageHandlerTest extends TestCase public function testSetEditorCallable() { $handler = $this->getHandler(); - $handler->setEditor(function($file, $line) { + $handler->setEditor(function ($file, $line) { $file = rawurlencode($file); $line = rawurlencode($line); return "http://google.com/search/?q=$file:$line"; @@ -233,7 +233,7 @@ class PrettyPageHandlerTest extends TestCase public function testAddEditor() { $handler = $this->getHandler(); - $handler->addEditor('test-editor', function($file, $line) { + $handler->addEditor('test-editor', function ($file, $line) { return "cool beans $file:$line"; }); diff --git a/tests/Whoops/Handler/SoapResponseHandlerTest.php b/tests/Whoops/Handler/SoapResponseHandlerTest.php index 9264d7a..362639f 100644 --- a/tests/Whoops/Handler/SoapResponseHandlerTest.php +++ b/tests/Whoops/Handler/SoapResponseHandlerTest.php @@ -4,15 +4,15 @@ */ namespace Whoops\Handler; -use Whoops\TestCase; -use Whoops\Handler\SoapResponseHandler; + use RuntimeException; +use Whoops\TestCase; class SoapResponseHandlerTest extends TestCase { public function testSimpleValid() { - $handler = new SoapResponseHandler; + $handler = new SoapResponseHandler(); $run = $this->getRunInstance(); $run->pushHandler($handler); @@ -43,7 +43,6 @@ class SoapResponseHandlerTest extends TestCase $this->checkField($xml, 'faultstring', $this->getException()->getMessage()); } - /** * Helper for testSimpleValid* */ @@ -61,7 +60,7 @@ class SoapResponseHandlerTest extends TestCase /** * See if passed string is a valid XML document - * @param string $data + * @param string $data * @return bool */ private function isValidXml($data) diff --git a/tests/Whoops/Handler/XmlResponseHandlerTest.php b/tests/Whoops/Handler/XmlResponseHandlerTest.php index 8fc5cdc..26eae81 100644 --- a/tests/Whoops/Handler/XmlResponseHandlerTest.php +++ b/tests/Whoops/Handler/XmlResponseHandlerTest.php @@ -4,15 +4,15 @@ */ namespace Whoops\Handler; -use Whoops\TestCase; -use Whoops\Handler\XmlResponseHandler; + use RuntimeException; +use Whoops\TestCase; class XmlResponseHandlerTest extends TestCase { public function testSimpleValid() { - $handler = new XmlResponseHandler; + $handler = new XmlResponseHandler(); $run = $this->getRunInstance(); $run->pushHandler($handler); @@ -51,7 +51,6 @@ class XmlResponseHandlerTest extends TestCase $this->checkField($xml, 'type', get_class($this->getException())); } - /** * Helper for testSimpleValid* */ @@ -64,12 +63,12 @@ class XmlResponseHandlerTest extends TestCase private function getException() { - return new RuntimeException; + return new RuntimeException(); } /** * See if passed string is a valid XML document - * @param string $data + * @param string $data * @return bool */ private function isValidXml($data) diff --git a/tests/Whoops/RunTest.php b/tests/Whoops/RunTest.php index 063b1b5..053a539 100755 --- a/tests/Whoops/RunTest.php +++ b/tests/Whoops/RunTest.php @@ -5,20 +5,18 @@ */ namespace Whoops; -use Whoops\TestCase; -use Whoops\Run; -use Whoops\Handler\Handler; + use ArrayObject; -use Mockery as m; -use InvalidArgumentException; -use RuntimeException; use Exception; +use InvalidArgumentException; +use Mockery as m; +use RuntimeException; +use Whoops\Handler\Handler; class RunTest extends TestCase { - /** - * @param string $message + * @param string $message * @return Exception */ protected function getException($message = null) @@ -45,8 +43,7 @@ class RunTest extends TestCase ->shouldReceive('setException') ->andReturn(null) - ->mock() - ; + ->mock(); } /** @@ -99,7 +96,7 @@ class RunTest extends TestCase public function testPushClosureBecomesHandler() { $run = $this->getRunInstance(); - $run->pushHandler(function() {}); + $run->pushHandler(function () {}); $this->assertInstanceOf('Whoops\\Handler\\CallbackHandler', $run->popHandler()); } @@ -196,18 +193,18 @@ class RunTest extends TestCase { $run = $this->getRunInstance(); $exception = $this->getException(); - $order = new ArrayObject; + $order = new ArrayObject(); $handlerOne = $this->getHandler(); $handlerTwo = $this->getHandler(); $handlerThree = $this->getHandler(); $handlerOne->shouldReceive('handle') - ->andReturnUsing(function() use($order) { $order[] = 1; }); + ->andReturnUsing(function () use ($order) { $order[] = 1; }); $handlerTwo->shouldReceive('handle') - ->andReturnUsing(function() use($order) { $order[] = 2; }); + ->andReturnUsing(function () use ($order) { $order[] = 2; }); $handlerThree->shouldReceive('handle') - ->andReturnUsing(function() use($order) { $order[] = 3; }); + ->andReturnUsing(function () use ($order) { $order[] = 3; }); $run->pushHandler($handlerOne); $run->pushHandler($handlerTwo); @@ -236,15 +233,13 @@ class RunTest extends TestCase $test = $this; $handlerOne ->shouldReceive('handle') - ->andReturnUsing(function () use($test) { + ->andReturnUsing(function () use ($test) { $test->fail('$handlerOne should not be called'); - }) - ; + }); $handlerTwo ->shouldReceive('handle') - ->andReturn(Handler::LAST_HANDLER) - ; + ->andReturn(Handler::LAST_HANDLER); $run->handleException($this->getException()); @@ -266,10 +261,9 @@ class RunTest extends TestCase $test = $this; $handler ->shouldReceive('handle') - ->andReturnUsing(function () use($test) { + ->andReturnUsing(function () use ($test) { $test->fail('$handler should not be called, error not suppressed'); - }) - ; + }); @trigger_error("Test error suppression"); @@ -288,10 +282,9 @@ class RunTest extends TestCase $test = $this; $handler ->shouldReceive('handle') - ->andReturnUsing(function () use($test) { + ->andReturnUsing(function () use ($test) { $test->fail('$handler should not be called error should be caught'); - }) - ; + }); try { trigger_error('foo', E_USER_NOTICE); @@ -318,10 +311,9 @@ class RunTest extends TestCase $test = $this; $handler ->shouldReceive('handle') - ->andReturnUsing(function () use($test) { + ->andReturnUsing(function () use ($test) { $test->fail('$handler should not be called, error_reporting not respected'); - }) - ; + }); $oldLevel = error_reporting(E_ALL ^ E_USER_NOTICE); trigger_error("Test error reporting", E_USER_NOTICE); @@ -345,10 +337,9 @@ class RunTest extends TestCase $test = $this; $handler ->shouldReceive('handle') - ->andReturnUsing(function () use($test) { + ->andReturnUsing(function () use ($test) { $test->fail('$handler should not be called, silenceErrorsInPaths not respected'); - }) - ; + }); $run->silenceErrorsInPaths('@^'.preg_quote(__FILE__, '@').'$@', E_USER_NOTICE); trigger_error('Test', E_USER_NOTICE); @@ -362,12 +353,12 @@ class RunTest extends TestCase public function testOutputIsSent() { $run = $this->getRunInstance(); - $run->pushHandler(function() { + $run->pushHandler(function () { echo "hello there"; }); ob_start(); - $run->handleException(new RuntimeException); + $run->handleException(new RuntimeException()); $this->assertEquals("hello there", ob_get_clean()); } @@ -379,12 +370,12 @@ class RunTest extends TestCase { $run = $this->getRunInstance(); $run->writeToOutput(false); - $run->pushHandler(function() { + $run->pushHandler(function () { echo "hello there"; }); ob_start(); - $this->assertEquals("hello there", $run->handleException(new RuntimeException)); + $this->assertEquals("hello there", $run->handleException(new RuntimeException())); $this->assertEquals("", ob_get_clean()); } diff --git a/tests/Whoops/TestCase.php b/tests/Whoops/TestCase.php index 6722569..96cc917 100644 --- a/tests/Whoops/TestCase.php +++ b/tests/Whoops/TestCase.php @@ -5,7 +5,7 @@ */ namespace Whoops; -use Whoops\Run; + class TestCase extends \PHPUnit_Framework_TestCase { @@ -14,7 +14,7 @@ class TestCase extends \PHPUnit_Framework_TestCase */ protected function getRunInstance() { - $run = new Run; + $run = new Run(); $run->allowQuit(false); return $run; diff --git a/tests/Whoops/Util/MiscTest.php b/tests/Whoops/Util/MiscTest.php index 1ddba1e..f7d1d2c 100644 --- a/tests/Whoops/Util/MiscTest.php +++ b/tests/Whoops/Util/MiscTest.php @@ -5,15 +5,15 @@ */ namespace Whoops\Util; + use Whoops\TestCase; -use Whoops\Util\Misc; class MiscTest extends TestCase { /** * @dataProvider provideTranslateException * @param string $expected_output - * @param int $exception_code + * @param int $exception_code */ public function testTranslateException($expected_output, $exception_code) { @@ -30,7 +30,7 @@ class MiscTest extends TestCase // When passing a value not equal to an error constant, ensure // E_UNKNOWN is returned. - array('E_UNKNOWN', 3) + array('E_UNKNOWN', 3), ); } } diff --git a/tests/Whoops/Util/TemplateHelperTest.php b/tests/Whoops/Util/TemplateHelperTest.php index 5fd7ba9..bc217b5 100644 --- a/tests/Whoops/Util/TemplateHelperTest.php +++ b/tests/Whoops/Util/TemplateHelperTest.php @@ -5,8 +5,8 @@ */ namespace Whoops\Util; + use Whoops\TestCase; -use Whoops\Util\TemplateHelper; class TemplateHelperTest extends TestCase { @@ -20,7 +20,7 @@ class TemplateHelperTest extends TestCase */ public function setUp() { - $this->helper = new TemplateHelper; + $this->helper = new TemplateHelper(); } /** @@ -101,7 +101,7 @@ class TemplateHelperTest extends TestCase $this->helper->setVariables(array( "name" => "Whoops", "type" => "library", - "desc" => "php errors for cool kids" + "desc" => "php errors for cool kids", )); $this->helper->setVariable("name", "Whoops!"); @@ -110,7 +110,7 @@ class TemplateHelperTest extends TestCase $this->assertEquals($this->helper->getVariables(), array( "name" => "Whoops!", - "desc" => "php errors for cool kids" + "desc" => "php errors for cool kids", )); } } diff --git a/tests/deprecated/Zend/ModuleTest.php b/tests/deprecated/Zend/ModuleTest.php index b6df2dc..0e31731 100644 --- a/tests/deprecated/Zend/ModuleTest.php +++ b/tests/deprecated/Zend/ModuleTest.php @@ -3,8 +3,8 @@ namespace Whoops; class ModuleTest extends \PHPUnit_Framework_TestCase { - public function testAutoload() - { - $this->assertTrue(class_exists('\Whoops\Module')); - } + public function testAutoload() + { + $this->assertTrue(class_exists('\Whoops\Module')); + } }

Value
escape($k) ?> escape(print_r($value, true)) ?>