Skip to content

Commit f669416

Browse files
Merge pull request #24 from php-enspired/dev-2.0
2.0
2 parents bbed81c + fddac80 commit f669416

File tree

11 files changed

+331
-513
lines changed

11 files changed

+331
-513
lines changed

.phan/config.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
return [
4+
'directory_list' => ['src', 'vendor'],
5+
'exclude_analysis_directory_list' => ['vendor']
6+
];

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![](https://img.shields.io/github/release/php-enspired/exceptable.svg) ![](https://img.shields.io/badge/PHP-7.0-blue.svg?colorB=8892BF) ![](https://img.shields.io/badge/license-GPL_3.0_only-blue.svg)
1+
![](https://img.shields.io/github/release/php-enspired/exceptable.svg) ![](https://img.shields.io/badge/PHP-7.1-blue.svg?colorB=8892BF) ![](https://img.shields.io/badge/license-GPL_3.0_only-blue.svg)
22

33
how exceptable!
44
===============
@@ -8,7 +8,7 @@ _Exceptables_ make exceptions exceptional. Exceptables provide some nice utilit
88
dependencies
99
------------
1010

11-
Requires php 7.0 or later.
11+
Requires php 7.1 or later.
1212

1313
installation
1414
------------
@@ -56,6 +56,9 @@ see more in [the wiki](https://github.com/php-enspired/exceptable/wiki).
5656
docs
5757
----
5858

59+
**Note**, version 2.0 requires PHP 7.1 or greater, and also introduces a number of changes from the version 1 api.
60+
[Read more](https://github.com/php-enspired/exceptable/wiki/new-in-2.0).
61+
5962
- API:
6063
- [The Exceptable Interface](https://github.com/php-enspired/exceptable/wiki/API:-The-Exceptable-Interface)
6164
- [The Exception Class](https://github.com/php-enspired/exceptable/wiki/API:-The-Exception-Class)

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
"irc": "irc://irc.freenode.net/php-enspired"
1616
},
1717
"require": {
18-
"php": "^7.0"
18+
"php": "^7.1"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "^5.7"
21+
"phan/phan": "^1",
22+
"phpunit/phpunit": "^7"
2223
},
2324
"autoload": {
2425
"psr-4": {
2526
"at\\exceptable\\": "src/"
2627
}
2728
},
2829
"scripts": {
29-
"test:unit" : "vendor/bin/phpunit --bootstrap vendor/autoload.php tests"
30+
"test:phan": "vendor/bin/phan",
31+
"test:unit" : "vendor/bin/phpunit tests"
3032
}
3133
}

phpunit.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
bootstrap="./vendor/autoload.php"
4+
colors="true">
5+
<filter>
6+
<whitelist processUncoveredFilesFromWhitelist="true">
7+
<directory suffix=".php">./src</directory>
8+
</whitelist>
9+
</filter>
10+
</phpunit>

src/Exceptable.php

Lines changed: 16 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* @package at.exceptable
44
* @author Adrian <adrian@enspi.red>
5-
* @copyright 2014 - 2016
5+
* @copyright 2014 - 2018
66
* @license GPL-3.0 (only)
77
*
88
* This program is free software: you can redistribute it and/or modify it
@@ -22,6 +22,8 @@
2222

2323
use Throwable;
2424

25+
use at\exceptable\ExceptableException;
26+
2527
/**
2628
* augmented interface for exceptions.
2729
*
@@ -32,17 +34,8 @@
3234
* exceptable::getSeverity() will need to be aliased when the trait is used.
3335
* - implementations cannot extend from PDOException,
3436
* because it breaks the Throwable interface (its getCode() returns a string).
35-
*
36-
* @method string Throwable::__toString( void )
37-
* @method int Throwable::getCode( void )
38-
* @method string Throwable::getFile( void )
39-
* @method int Throwable::getLine( void )
40-
* @method string Throwable::getMessage( void )
41-
* @method Throwable Throwable::getPrevious( void )
42-
* @method array Throwable::getTrace( void )
43-
* @method string Throwable::getTraceAsString( void )
4437
*/
45-
interface Exceptable extends \Throwable {
38+
interface Exceptable extends Throwable {
4639

4740
/**
4841
* exception severity levels.
@@ -51,57 +44,34 @@ interface Exceptable extends \Throwable {
5144
* @type int WARNING warning
5245
* @type int NOTICE notice
5346
*/
54-
const ERROR = E_ERROR;
55-
const WARNING = E_WARNING;
56-
const NOTICE = E_NOTICE;
57-
58-
/**
59-
* default info for unknown/generic exception cases.
60-
*
61-
* @type int DEFAULT_CODE
62-
* @type int DEFAULT_MESSAGE
63-
* @type int DEFAULT_SEVERITY
64-
*/
65-
const DEFAULT_CODE = 0;
66-
const DEFAULT_MESSAGE = '';
67-
const DEFAULT_SEVERITY = self::ERROR;
47+
public const ERROR = E_ERROR;
48+
public const WARNING = E_WARNING;
49+
public const NOTICE = E_NOTICE;
6850

6951
/**
7052
* gets information about a code known to the implementing class.
7153
*
7254
* @param int $code the exception code to look up
7355
* @throws ExceptableException if the code is not known to the implementation
74-
* @return array a map of info about the code,
75-
* including (at a minimum) its "code", "severity", and "message".
56+
* @return array a map of info about the error condition
7657
*/
77-
public static function get_info(int $code) : array;
58+
public static function getInfo(int $code) : array;
7859

7960
/**
8061
* checks whether the implementation has info about the given code.
8162
*
8263
* @param int $code the code to check
8364
* @return bool true if the code is known; false otherwise
8465
*/
85-
public static function has_info(int $code) : bool;
66+
public static function hasInfo(int $code) : bool;
8667

8768
/**
88-
* @param string $0 exception message
89-
* if omitted, a message must be set based on the exception code
90-
* @param int $1 exception code
91-
* if omitted, a default code must be set
92-
* @param Throwable $2 previous exception
93-
* @param array $3 additional exception context
94-
* @throws ExceptableException if argument(s) are invalid
69+
* @param int $code exception code
70+
* @param array $context additional exception context
71+
* @param Throwable|null $previous previous exception
72+
* @throws ExceptableException if code is invalid
9573
*/
96-
public function __construct(...$args);
97-
98-
/**
99-
* adds contextual info to this exception.
100-
*
101-
* @param array $context map of info to add
102-
* @return $this
103-
*/
104-
public function addContext(array $context) : Exceptable;
74+
public function __construct(int $code, array $context = [], Throwable $previous = null);
10575

10676
/**
10777
* gets contextual info about this exception.
@@ -115,42 +85,12 @@ public function getContext() : array;
11585
*
11686
* @return Throwable the root exception
11787
*/
118-
public function getRoot() : \Throwable;
88+
public function getRoot() : Throwable;
11989

12090
/**
12191
* gets exception severity.
12292
*
12393
* @return int the exception severity
12494
*/
12595
public function getSeverity() : int;
126-
127-
/**
128-
* checks the exception severity.
129-
*
130-
* @return bool true if exception severity is "Error"; false otherwise
131-
*/
132-
public function isError() : bool;
133-
134-
/**
135-
* checks the exception severity.
136-
*
137-
* @return bool true if exception severity is "Warning"; false otherwise
138-
*/
139-
public function isWarning() : bool;
140-
141-
/**
142-
* checks the exception severity.
143-
*
144-
* @return bool true if exception severity is "Notice"; false otherwise
145-
*/
146-
public function isNotice() : bool;
147-
148-
/**
149-
* adds contextual info to this exception.
150-
*
151-
* @param int $severity one of Exceptable::ERROR|WARNING|NOTICE
152-
* @throws ExceptableException if severity is invalid
153-
* @return $this
154-
*/
155-
public function setSeverity(int $severity) : Exceptable;
15696
}

src/ExceptableException.php

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,66 +20,32 @@
2020

2121
namespace at\exceptable;
2222

23-
use at\exceptable\Exceptable,
24-
at\exceptable\Exception;
23+
use at\exceptable\ {
24+
Exceptable,
25+
Exception
26+
};
2527

2628
/**
2729
* exceptableexceptionsexceptableexceptionsexceptableexceptions
28-
*
29-
* @method int \Exception::getCode( void )
30-
* @method string \Exception::getFile( void )
31-
* @method int \Exception::getLine( void )
32-
* @method string \Exception::getMessage( void )
33-
* @method Throwable \Exception::getPrevious( void )
34-
* @method array \Exception::getTrace( void )
35-
* @method string \Exception::getTraceAsString( void )
36-
*
37-
* @method array Exception::get_info( int $code )
38-
* @method bool Exception::has_info( int $code )
39-
* @method void Exception::__construct( string|int|Throwable|array …$args )
40-
* @method string Exception::__toString( void )
41-
* @method Exceptable Exception::addContext( array $context )
42-
* @method array Exception::getContext( void )
43-
* @method Throwable Exception::getRoot( void )
44-
* @method int Exception::getSeverity( void )
45-
* @method bool Exception::isError( void )
46-
* @method bool Exception::isWarning( void )
47-
* @method bool Exception::isNotice( void )
48-
* @method Exceptable Exception::setSeverity( int $severity )
4930
*/
5031
class ExceptableException extends Exception {
5132

5233
/**
53-
* @type int NO_SUCH_CODE invalid exception code.
54-
* @type int INVALID_CONSTRUCT_ARGS invalid/out-of-order constructor arguments.
55-
* @type int INVALID_SEVERITY invalid severity level.
56-
* @type int UNCAUGHT_EXCEPTION uncaught/unhandled exception during runtime.
57-
* @type int INVALID_HANDLER invalid handler (e.g., wrong signature, or throws).
34+
* @type int NO_SUCH_CODE invalid exception code
35+
* @type int UNCAUGHT_EXCEPTION uncaught/unhandled exception during runtime
36+
* @type int INVALID_HANDLER invalid handler (e.g., wrong signature, or throws)
5837
*/
59-
const NO_SUCH_CODE = 1;
60-
const INVALID_CONSTRUCT_ARGS = (1<<1);
61-
const INVALID_SEVERITY = (1<<2);
62-
const UNCAUGHT_EXCEPTION = (1<<3);
63-
const INVALID_HANDLER = (1<<4);
38+
public const NO_SUCH_CODE = 1;
39+
public const UNCAUGHT_EXCEPTION = 2;
40+
public const INVALID_HANDLER = 3;
6441

6542
/** @see Exceptable::INFO */
66-
const INFO = [
43+
public const INFO = [
6744
self::NO_SUCH_CODE => [
6845
'message' => 'no such code',
6946
'severity' => Exceptable::WARNING,
7047
'tr_message' => "no exception code '{code}' is known"
7148
],
72-
self::INVALID_CONSTRUCT_ARGS => [
73-
'message' => 'constructor arguments are invalid and/or out of order',
74-
'severity' => Exceptable::ERROR,
75-
'tr_message' => "constructor arguments are invalid and/or out of order: {args}"
76-
],
77-
self::INVALID_SEVERITY => [
78-
'message' => 'invalid severity',
79-
'severity' => Exceptable::WARNING,
80-
'tr_message' =>
81-
'severity must be one of Exceptable::ERROR|WARNING|NOTICE; {severity} provided'
82-
],
8349
self::UNCAUGHT_EXCEPTION => [
8450
'message' => 'uncaught exception',
8551
'severity' => Exceptable::ERROR,

0 commit comments

Comments
 (0)