Skip to content

Commit dea93aa

Browse files
committed
Updated dependencies and use type hinting.
1 parent 3a48356 commit dea93aa

15 files changed

+157
-109
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/.idea/
2+
/.phpunit.result.cache
23
/bin/
34
/doc/
45
/composer.lock
56
/test/report
67
/test/coverage.xml
7-
/vendor/
8+
/vendor/

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: php
22
php:
3-
- '7.0'
43
- '7.1'
5-
- nightly
4+
- '7.2'
5+
- '7.3'
66

77
install:
88
- composer self-update

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
"Exception",
66
"Format"
77
],
8-
"type": "library",
98
"license": "MIT",
109
"require": {
11-
"php": ">=7.0.0"
10+
"php": ">=7.1.0"
1211
},
1312
"require-dev": {
1413
"phing/phing": "^2.0.0",
15-
"phpunit/phpunit": "^6.0.0"
14+
"phpunit/phpunit": "^7.0.0 || ^8.0.0"
1615
},
1716
"autoload": {
1817
"psr-4": {
@@ -25,6 +24,6 @@
2524
}
2625
},
2726
"config": {
28-
"bin-dir": "bin"
27+
"bin-dir": "bin/"
2928
}
3029
}

src/ErrorException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
2-
//----------------------------------------------------------------------------------------------------------------------
2+
declare(strict_types=1);
3+
34
namespace SetBased\Exception;
45

5-
//----------------------------------------------------------------------------------------------------------------------
66
/**
77
* Class for PHP errors.
88
*/
@@ -31,7 +31,7 @@ class ErrorException extends \ErrorException implements NamedException
3131
* @since 1.0.0
3232
* @api
3333
*/
34-
public function getName()
34+
public function getName(): string
3535
{
3636
return isset(self::$ourNames[$this->getCode()]) ? self::$ourNames[$this->getCode()] : 'Error';
3737
}

src/FallenException.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
2-
//----------------------------------------------------------------------------------------------------------------------
2+
declare(strict_types=1);
3+
34
namespace SetBased\Exception;
45

5-
//----------------------------------------------------------------------------------------------------------------------
66
/**
77
* Class for situations where PHP code has fallen through a switch statement or a combination of if-elseif statements.
88
*/
@@ -13,7 +13,7 @@ class FallenException extends RuntimeException
1313
* Object constructor.
1414
*
1515
* @param string $name The name or description of the variable of expression.
16-
* @param string $value The actual value the variable or expression.
16+
* @param mixed $value The actual value the variable or expression.
1717
*
1818
* @since 1.0.0
1919
* @api
@@ -40,7 +40,7 @@ class FallenException extends RuntimeException
4040
* }
4141
* ```
4242
*/
43-
public function __construct($name, $value)
43+
public function __construct(string $name, $value)
4444
{
4545
parent::__construct("Unknown or unexpected value '%s' for '%s'.", $value, $name);
4646
}

src/FormattedException.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2-
//----------------------------------------------------------------------------------------------------------------------
2+
declare(strict_types=1);
3+
34
namespace SetBased\Exception;
45

5-
//----------------------------------------------------------------------------------------------------------------------
6+
use Exception;
7+
68
/**
79
* Trait for exception classes with format string in constructor.
810
*
@@ -23,7 +25,22 @@
2325
*/
2426
trait FormattedException
2527
{
26-
/* PHP 5.4: doesn't allow us to use __construct in traits. This possible from PHP 5.5 and higher. */
28+
//--------------------------------------------------------------------------------------------------------------------
29+
/**
30+
* Object constructor.
31+
*
32+
* @param mixed ... The arguments, see {@see formattedConstruct()}.
33+
*
34+
* @since 2.0.0
35+
* @api
36+
*/
37+
public function __construct()
38+
{
39+
list($message, $code, $previous) = self::formattedConstruct(func_get_args());
40+
41+
parent::__construct($message, $code, $previous);
42+
}
43+
2744
//--------------------------------------------------------------------------------------------------------------------
2845
/**
2946
* Returns a list of arguments for \Exception::_construct.
@@ -38,6 +55,9 @@ trait FormattedException
3855
* // Exception with a format string
3956
* new MyException('There are %d monkeys in the %s', 5, 'tree');
4057
*
58+
* // Exception with a message
59+
* new MyException('Of all monkey 50% are in the tree');
60+
*
4161
* // Exception with an exception code
4262
* new MyException([$code], 'There are %d monkeys in the %s', 5, 'tree');
4363
*
@@ -55,7 +75,7 @@ trait FormattedException
5575
* @since 1.0.0
5676
* @api
5777
*/
58-
public static function formattedConstruct($args)
78+
public static function formattedConstruct($args): array
5979
{
6080
$code = 0;
6181
$previous = null;
@@ -70,13 +90,13 @@ public static function formattedConstruct($args)
7090
{
7191
if (isset($special[$i]))
7292
{
73-
if ($special[$i] instanceof \Exception) $previous = $special[$i];
93+
if ($special[$i] instanceof Exception) $previous = $special[$i];
7494
elseif (is_int($special[$i])) $code = $special[$i];
7595
}
7696
}
7797
}
7898

79-
return [vsprintf($format, $args), $code, $previous];
99+
return [empty($args) ? $format : vsprintf($format, $args), $code, $previous];
80100
}
81101

82102
//--------------------------------------------------------------------------------------------------------------------

src/LogicException.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
2-
//----------------------------------------------------------------------------------------------------------------------
2+
declare(strict_types=1);
3+
34
namespace SetBased\Exception;
45

5-
//----------------------------------------------------------------------------------------------------------------------
66
/**
77
* Class for errors in program logic.
88
*/
@@ -11,27 +11,11 @@ class LogicException extends \LogicException implements NamedException
1111
//--------------------------------------------------------------------------------------------------------------------
1212
use FormattedException;
1313

14-
//--------------------------------------------------------------------------------------------------------------------
15-
/**
16-
* Object constructor.
17-
*
18-
* @param mixed ... The arguments, see {@see \SetBased\Exception\FormattedException::formattedConstruct}.
19-
*
20-
* @since 1.0.0
21-
* @api
22-
*/
23-
public function __construct()
24-
{
25-
list($message, $code, $previous) = self::formattedConstruct(func_get_args());
26-
27-
parent::__construct($message, $code, $previous);
28-
}
29-
3014
//--------------------------------------------------------------------------------------------------------------------
3115
/**
3216
* {@inheritdoc}
3317
*/
34-
public function getName()
18+
public function getName(): string
3519
{
3620
return 'Programming Error';
3721
}

src/NamedException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
2-
//----------------------------------------------------------------------------------------------------------------------
2+
declare(strict_types=1);
3+
34
namespace SetBased\Exception;
45

5-
//----------------------------------------------------------------------------------------------------------------------
66
/**
77
* Interface for exceptions with user-friendly names.
88
*/
@@ -17,7 +17,7 @@ interface NamedException
1717
* @since 1.0.0
1818
* @api
1919
*/
20-
public function getName();
20+
public function getName(): string;
2121

2222
//--------------------------------------------------------------------------------------------------------------------
2323
}

src/RuntimeException.php

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
2-
//----------------------------------------------------------------------------------------------------------------------
2+
declare(strict_types=1);
3+
34
namespace SetBased\Exception;
45

5-
//----------------------------------------------------------------------------------------------------------------------
66
/**
77
* Class for runtime exceptions.
88
*/
@@ -11,29 +11,11 @@ class RuntimeException extends \RuntimeException implements NamedException
1111
//--------------------------------------------------------------------------------------------------------------------
1212
use FormattedException;
1313

14-
//--------------------------------------------------------------------------------------------------------------------
15-
/**
16-
* Object constructor.
17-
*
18-
* See {@see \SetBased\Exception\FormattedException::formattedConstruct()} for argument list.
19-
*
20-
* @param mixed ... The arguments, see {@see \SetBased\Exception\FormattedException::formattedConstruct()}.
21-
*
22-
* @since 1.0.0
23-
* @api
24-
*/
25-
public function __construct()
26-
{
27-
list($message, $code, $previous) = self::formattedConstruct(func_get_args());
28-
29-
parent::__construct($message, $code, $previous);
30-
}
31-
3214
//--------------------------------------------------------------------------------------------------------------------
3315
/**
3416
* {@inheritdoc}
3517
*/
36-
public function getName()
18+
public function getName(): string
3719
{
3820
return 'Error';
3921
}

test/ErrorExceptionTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
//----------------------------------------------------------------------------------------------------------------------
2+
declare(strict_types=1);
3+
34
namespace SetBased\Exception\Test;
45

56
use PHPUnit\Framework\TestCase;
@@ -14,7 +15,7 @@ class ErrorExceptionTest extends TestCase
1415
/**
1516
* Test ErrorException with valid code.
1617
*/
17-
public function test1()
18+
public function test1(): void
1819
{
1920
try
2021
{
@@ -30,7 +31,7 @@ public function test1()
3031
/**
3132
* Test ErrorException with invalid code.
3233
*/
33-
public function test2()
34+
public function test2(): void
3435
{
3536
try
3637
{

0 commit comments

Comments
 (0)