Skip to content

Commit

Permalink
Requested Changes Pt. 3
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-rueegg committed Jan 18, 2024
1 parent 93cf892 commit 0e017a8
Show file tree
Hide file tree
Showing 12 changed files with 523 additions and 424 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private function validateUnderlyingObjectType(?object $object)
return true;
}

if (DataTypeHelper::filterClassType($object, $this->mustBeInstanceOf, false)) { //|| $object->asa($instance) !== null
if (DataTypeHelper::matchClassType($object, $this->mustBeInstanceOf)) { //|| $object->asa($instance) !== null
return true;
}

Expand Down
43 changes: 31 additions & 12 deletions protected/humhub/exceptions/InvalidArgumentExceptionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ trait InvalidArgumentExceptionTrait
protected bool $isInstantiating = true;

/**
* @param string $parameterOrMessage Name of parameter in question, or alternatively the full message string containing at
* least one space character (ASCII 32). In this case, `$valid` and `$given` are considered to be
* `$code` and `$previous` respectively
* @param string $parameterOrMessage Name of parameter in question, or alternatively the full message string
* containing at least one space character (ASCII 32). In this case, `$valid` and `$given` are considered to be
* `$code` and `$previous` respectively
* @param string|string[] $valid (List of) valid parameter(s)
* @param mixed $given Parameter received
* @param int $code Optional exception code
Expand All @@ -41,11 +41,23 @@ public function __construct($parameterOrMessage, $valid = null, $given = null, $

try {
if (!is_string($parameterOrMessage)) {
throw new InvalidArgumentTypeException('$parameterOrMessage', ['string'], $parameterOrMessage, 0, $this);
throw new InvalidArgumentTypeException(
'$parameterOrMessage',
['string'],
$parameterOrMessage,
0,
$this
);
}

if (empty($parameterOrMessage = trim($parameterOrMessage))) {
throw new InvalidArgumentValueException('$parameterOrMessage', 'non-empty string', $parameterOrMessage, 0, $this);
throw new InvalidArgumentValueException(
'$parameterOrMessage',
'non-empty string',
$parameterOrMessage,
0,
$this
);
}

// check if $parameter is actually the $message
Expand All @@ -56,12 +68,19 @@ public function __construct($parameterOrMessage, $valid = null, $given = null, $
$previous ??= $given;
}
} else {
$trace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$trace = end($trace);
$this->methodName = ltrim(($trace['class'] ?? '') . '::' . ($trace['function'] ?? 'unknown method'), ':');

$this->parameter = $parameterOrMessage;

if (false !== $pos = strrpos($parameterOrMessage, '::')) {
$this->methodName = trim(substr($parameterOrMessage, 0, $pos), ':');
$this->parameter = trim(substr($parameterOrMessage, $pos), ':');
} else {
$trace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$trace = end($trace);
$this->methodName = ltrim(
($trace['class'] ?? '') . '::' . ($trace['function'] ?? 'unknown method'),
':'
);

$this->parameter = $parameterOrMessage;
}
try {
$this->setValid($valid);
} catch (InvalidArgumentTypeException $t) {
Expand All @@ -86,7 +105,7 @@ public function __construct($parameterOrMessage, $valid = null, $given = null, $
}

/**
* @see static::__construct()
* @see static::__construct()
* @noinspection PhpUnhandledExceptionInspection
* @noinspection PhpDocMissingThrowsInspection
*/
Expand Down

0 comments on commit 0e017a8

Please sign in to comment.