Giter Club home page Giter Club logo

exception-inspector's Introduction

Exception inspector

Inspector for exception stack trace.

Installation

Run

$ composer require narrowspark/exception-inspector

Usage

The Inspector class provides methods to inspect an exception instance, with particular focus on its frames or stack-trace.

<?php

declare(strict_types=1);

use Narrowspark\ExceptionInspector\Frame;
use Narrowspark\ExceptionInspector\FrameCollection;
use Narrowspark\ExceptionInspector\Inspector;

$exception = new \Exception('This is a error');

$inspector = new Inspector($exception);

/**
 * Returns an iterator instance for all the frames in the stack
 * trace for the Exception being inspected.
 *
 * @var \Narrowspark\ExceptionInspector\FrameIterator $frames
 */
$frames = $inspector->getFrames();

// Returns the string name of the Exception being inspected
// A faster way of doing get_class($inspector->getException())
echo $inspector->getExceptionName();

// Returns the string message for the Exception being inspected
// A faster way of doing $inspector->getException()->getMessage()
echo $inspector->getExceptionMessage();

The FrameCollection class exposes a fluent interface to manipulate and examine a collection of Frame instances.

// Returns the number of frames in the collection
echo $frames->count();

// @see [array_filter](https://www.php.net/manual/en/function.array-filter)
// Filter the Frames in the collection with a callable.
// The callable must accept a Frame object, and return
// true to keep it in the collection, or false not to.
$filteredFrames = $frames->filter(function(Frame $frame): bool {
    return true;
});

// @see: [array_map](https://www.php.net/manual/en/function.array-map.php)
// The callable must accept a Frame object, and return
// a Frame object, doesn't matter if it's the same or not
// - will throw an UnexpectedValueException if something
// else is returned.
$mapedFrames = $frames->map(function (Frame $frame): Frame {
    return $frame;
});

The Frame class models a single frame in an exception’s stack trace. You can use it to retrieve info about frame context, file, line number.

You have available functionality to add comments to a frame.

foreach ($frames as $frame) {
    // Returns the file path for the file where this frame occurred.
    $frame->getFile();

    // Returns the line number for this frame
    $frame->getLine();

    // Returns the class name for this frame, if it occurred
    // within a class/instance.
    $frame->getClass();

    // Returns the function name for this frame, if it occurred
    // within a function/method
    $frame->getFunction();

    // Returns an array of arguments for this frame. Empty if no
    // arguments were provided.
    $frame->getArgs();

    // Returns the full file contents for the file where this frame
    // occurred.
    $frame->getFileContents();

    // Returns an array of lines for a file.
    $frame->getFileLines();

    // Optionally scoped to a given range of line numbers.
    // i.e: Frame::getFileLines(0, 3) returns the first 3
    // lines after line 0 (1)
    $frame->getFileLines(0, 3);
}

Versioning

This library follows semantic versioning, and additions to the code ruleset are performed in major releases.

Changelog

Please have a look at CHANGELOG.md.

Contributing

Please have a look at CONTRIBUTING.md.

Thanks whoops for the class interfaces.

Code of Conduct

Please have a look at CODE_OF_CONDUCT.md.

License

This package is licensed using the MIT License.

Please have a look at LICENSE.md.

exception-inspector's People

Contributors

dependabot-preview[bot] avatar prisis avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

prisisforks

exception-inspector's Issues

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - wikimedia/composer-merge-plugin dev-master requires composer-plugin-api ^1.1 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
    - wikimedia/composer-merge-plugin v1.4.1 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
    - wikimedia/composer-merge-plugin 1.5.x-dev is an alias of wikimedia/composer-merge-plugin dev-master and thus requires it to be installed too.
    - Root composer.json requires wikimedia/composer-merge-plugin ^1.4.1 -> satisfiable by wikimedia/composer-merge-plugin[v1.4.1, 1.5.x-dev (alias of dev-master)].

You are using Composer 2, which some of your plugins seem to be incompatible with. Make sure you update your plugins or report a plugin-issue to ask them to support Composer 2.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - Root composer.json requires wikimedia/composer-merge-plugin ^1.4.1 -> satisfiable by wikimedia/composer-merge-plugin[v1.4.1].
    - wikimedia/composer-merge-plugin v1.4.1 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.

You are using Composer 2, which some of your plugins seem to be incompatible with. Make sure you update your plugins or report a plugin-issue to ask them to support Composer 2.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - wikimedia/composer-merge-plugin 1.5.x-dev is an alias of wikimedia/composer-merge-plugin dev-master and thus requires it to be installed too.
    - wikimedia/composer-merge-plugin v1.4.1 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
    - wikimedia/composer-merge-plugin dev-master requires composer-plugin-api ^1.1 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
    - Root composer.json requires wikimedia/composer-merge-plugin ^1.4.1 -> satisfiable by wikimedia/composer-merge-plugin[v1.4.1, 1.5.x-dev (alias of dev-master)].

You are using Composer 2, which some of your plugins seem to be incompatible with. Make sure you update your plugins or report a plugin-issue to ask them to support Composer 2.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - wikimedia/composer-merge-plugin dev-master requires composer-plugin-api ^1.1 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
    - wikimedia/composer-merge-plugin v1.4.1 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
    - wikimedia/composer-merge-plugin 1.5.x-dev is an alias of wikimedia/composer-merge-plugin dev-master and thus requires it to be installed too.
    - Root composer.json requires wikimedia/composer-merge-plugin ^1.4.1 -> satisfiable by wikimedia/composer-merge-plugin[v1.4.1, 1.5.x-dev (alias of dev-master)].

You are using Composer 2, which some of your plugins seem to be incompatible with. Make sure you update your plugins or report a plugin-issue to ask them to support Composer 2.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.