Differential D25220 Diff 727 src/applications/transactions/storage/PhabricatorModularTransactionType.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/storage/PhabricatorModularTransactionType.php
Show First 20 Lines • Show All 328 Lines • ▼ Show 20 Lines | abstract class PhabricatorModularTransactionType | ||||
final protected function newInvalidError($message, $xaction = null) { | final protected function newInvalidError($message, $xaction = null) { | ||||
return $this->newError(pht('Invalid'), $message, $xaction); | return $this->newError(pht('Invalid'), $message, $xaction); | ||||
} | } | ||||
final protected function isNewObject() { | final protected function isNewObject() { | ||||
return $this->getEditor()->getIsNewObject(); | return $this->getEditor()->getIsNewObject(); | ||||
} | } | ||||
/** | |||||
* Check whenever a new transaction's value is considered an "empty text" | |||||
* @param mixed $value A string, null, an integer... | |||||
* @param array $xactions Transactions | |||||
*/ | |||||
final protected function isEmptyTextTransaction($value, array $xactions) { | final protected function isEmptyTextTransaction($value, array $xactions) { | ||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
$value = $xaction->getNewValue(); | $value = $xaction->getNewValue(); | ||||
} | } | ||||
return !phutil_nonempty_string($value); | // The $value can be a lot of stuff, null, string, integer and maybe more. | ||||
valerio.bozzolan: I am also glad since making a code like `! nonempty` really makes me semantically mad | |||||
// We cast to string to answer the question "Is this string empty?". | |||||
// Note: Don't use phutil_nonempty_stringlike() since it was not designed | |||||
// for integers. | |||||
// Note: Don't use phutil_nonempty_scalar() since very probably we could | |||||
// receive a boolean, causing exceptions. | |||||
// https://we.phorge.it/T15239 | |||||
$value_clean = phutil_string_cast($value); | |||||
// We made our lives easier and we don't need strlen(something) | |||||
// and we should not. | |||||
return $value_clean === ''; | |||||
} | } | ||||
/** | /** | ||||
* When rendering to external targets (Email/Asana/etc), we need to include | * When rendering to external targets (Email/Asana/etc), we need to include | ||||
* more information that users can't obtain later. | * more information that users can't obtain later. | ||||
*/ | */ | ||||
final protected function isRenderingTargetExternal() { | final protected function isRenderingTargetExternal() { | ||||
// Right now, this is our best proxy for this: | // Right now, this is our best proxy for this: | ||||
▲ Show 20 Lines • Show All 147 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0
I am also glad since making a code like ! nonempty really makes me semantically mad