mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-25 08:12:40 +01:00
(arc) Unify type-checking for setHref()
type methods
Summary: Introduce `PhutilURI::checkHrefType` to unify type-check of some PHUI objects (See D25357). Ref T15316 Test Plan: Run this script: ``` #!/usr/bin/env php <?php require_once './arcanist/scripts/__init_script__.php'; $valid_inputs = array( 'foo', null, new PhutilURI('http://0@domain.com/'), ); $invalid_inputs = array( 9, new Filesystem(), array(), ); echo "Valid inputs: \n"; foreach ($valid_inputs as $v) { echo("Checking ".gettype($v)." \n"); PhutilURI::checkHrefType($v); } echo "\nError inputs: \n"; foreach ($invalid_inputs as $v) { echo("Checking ".gettype($v)." \n"); PhutilURI::checkHrefType($v); } echo "\n"; ``` Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15316 Differential Revision: https://we.phorge.it/D25356
This commit is contained in:
parent
8a2cb75d63
commit
6c6f47bf9c
1 changed files with 28 additions and 0 deletions
|
@ -561,4 +561,32 @@ final class PhutilURI extends Phobject {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is just a complicated type-check - we'll eventually replace it with a
|
||||
* native type-hint of `PhutilURI | string | null`, when this type-hint is
|
||||
* available (php 8.0).
|
||||
*
|
||||
* Before php 8, and after we suspect there aren't many more cases where this
|
||||
* fails, we'll replace the log with an exception.
|
||||
*/
|
||||
public static function checkHrefType($value) {
|
||||
if ($value === null || is_string($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value instanceof PhutilURI) {
|
||||
return;
|
||||
}
|
||||
|
||||
$report_type = is_object($value) ? get_class($value) : gettype($value);
|
||||
|
||||
// We log stuff with a kind stack trace
|
||||
phlog(
|
||||
pht(
|
||||
'Unexpected value type provided for an HREF field - %s. '.
|
||||
'Please share this stack trace as comment in Task %s',
|
||||
$report_type,
|
||||
'https://we.phorge.it/T15316'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue