1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 16:22:42 +01:00
phorge-arcanist/src/utils
Valerio Bozzolan b996b4799b phutil_nonempty_scalar(): don't throw when receiving a boolean scalar
Summary:
Note that booleans are scalars. Full stop.

| is_scalar($v)    | Result |
|------------------|--------|
| `"foo"`          | true   |
| `""`             | true   |
| `null`           | true   |
| `0`              | true   |
| `0.5`            | true   |
| `true`           | true   |
| `false`          | true   |
| `new stdclass()` | false  |
| `array()`        | false  |

Note that phutil_nonempty_scalar() was designed just to tell
whenever a scalar is "empty" or not. So it must not explode
when receiving a valid scalar.

So the question is not whenever a boolean is a scalar or not,
but whenever is empty or not. But also this is a clear fact:

| `$v`    | `is_scalar($v)` | `!is_empty($v)` | `if(strlen($v))`|
|---------|-----------------|-----------------|-----------------|
| `true`  | `true`          | `true`          | `true`          |
| `false` | `true`          | `false`         | `false`         |

In short, now the function does not explode anymore with bool
values. Instead, it says whenever are empty or not.

In bold the exact changes:

| Value             |`phutil_nonempty_scalar($v)`|
|-------------------|----------------------------|
| `"foo"`           | true                       |
| `""`              | false                      |
| `null`            | false                      |
| `0`               | true                       |
| `0.5`             | true                       |
|`obj` with tostring| true                       |
|`obj` withno tostr.| Exception                  |
| `array()`         | Exception                  |
| `true`            | ~~Exception~~ **true**     |
| `false`           | ~~Exception~~ **false**    |

Closes T15239

Test Plan:
- check if it makes sense to you
- check the few usages

Reviewers: O1 Blessed Committers, avivey

Reviewed By: O1 Blessed Committers, avivey

Subscribers: speck, tobiaswiese, Matthew, Cigaryno

Maniphest Tasks: T15239

Differential Revision: https://we.phorge.it/D25117
2023-07-18 12:41:43 +02:00
..
__tests__ phutil_nonempty_scalar(): don't throw when receiving a boolean scalar 2023-07-18 12:41:43 +02:00
AbstractDirectedGraph.php Remove final from private functions for PHP 8 compatibility 2021-01-10 22:05:20 +00:00
ArcanistNonblockingGuard.php Avoid leaving stdin in nonblocking mode after a modern prompt 2021-05-30 01:33:15 -07:00
CaseInsensitiveArray.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilArray.php Provide additional Arcanist PHP 8.1 fixes 2021-12-09 16:42:19 -08:00
PhutilArrayCheck.php Allow PhutilArrayCheck to accept a list of objects as a context 2020-05-30 03:37:42 -07:00
PhutilArrayWithDefaultValue.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilBufferedIterator.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilCallbackFilterIterator.php Provide additional Arcanist PHP 8.1 fixes 2021-12-09 16:42:19 -08:00
PhutilChunkedIterator.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilCowsay.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilDirectedScalarGraph.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilEditDistanceMatrix.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilExampleBufferedIterator.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilExecutionEnvironment.php Merge utility/support changes from "wilds" to "master" 2020-02-13 14:10:09 -08:00
PhutilHashingIterator.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilLunarPhase.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilProxyIterator.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilRope.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilSortVector.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilStreamIterator.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
PhutilSystem.php Return STDIN, STDOUT, and STDERR file descriptors from parent process 2022-05-05 10:27:22 -07:00
PhutilUTF8StringTruncator.php Fully merge "libphutil/" into "arcanist/" 2020-02-12 15:17:38 -08:00
utf8.php Do not pass a null string to mb_convert_case() for PHP 8.1 compatibility 2023-05-04 12:39:17 +02:00
utils.php phutil_nonempty_scalar(): don't throw when receiving a boolean scalar 2023-07-18 12:41:43 +02:00
viewutils.php Remove all product name literals in "pht()" in Arcanist 2022-04-25 12:21:31 -07:00