Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
b2cd2866
Unverified
Commit
b2cd2866
authored
Jan 22, 2020
by
Andreas Braun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-511: Allow passing multiple types to InvalidArgumentException
parent
8567a314
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
3 deletions
+26
-3
InvalidArgumentException.php
src/Exception/InvalidArgumentException.php
+26
-3
No files found.
src/Exception/InvalidArgumentException.php
View file @
b2cd2866
...
...
@@ -18,8 +18,12 @@
namespace
MongoDB\Exception
;
use
MongoDB\Driver\Exception\InvalidArgumentException
as
DriverInvalidArgumentException
;
use
function
array_pop
;
use
function
count
;
use
function
get_class
;
use
function
gettype
;
use
function
implode
;
use
function
is_array
;
use
function
is_object
;
use
function
sprintf
;
...
...
@@ -28,13 +32,32 @@ class InvalidArgumentException extends DriverInvalidArgumentException implements
/**
* Thrown when an argument or option has an invalid type.
*
* @param string $name Name of the argument or option
* @param mixed $value Actual value (used to derive the type)
* @param string $expectedType Expected type
* @param string
$name Name of the argument or option
* @param mixed
$value Actual value (used to derive the type)
* @param string
|string[]
$expectedType Expected type
* @return self
*/
public
static
function
invalidType
(
$name
,
$value
,
$expectedType
)
{
if
(
is_array
(
$expectedType
))
{
switch
(
count
(
$expectedType
))
{
case
1
:
$typeString
=
array_pop
(
$expectedType
);
break
;
case
2
:
$typeString
=
implode
(
'" or "'
,
$expectedType
);
break
;
default
:
$lastType
=
array_pop
(
$expectedType
);
$typeString
=
sprintf
(
'%s", or "%s'
,
implode
(
'", "'
,
$expectedType
),
$lastType
);
break
;
}
$expectedType
=
$typeString
;
}
return
new
static
(
sprintf
(
'Expected %s to have type "%s" but found "%s"'
,
$name
,
$expectedType
,
is_object
(
$value
)
?
get_class
(
$value
)
:
gettype
(
$value
)));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment