AlterNotPropertyTrait
Provides an alteration to invert boolean values.
This trait defines a single alteration type Alter::NOT which will invert a boolean value
or an array of boolean values. Non-boolean values will be cast to boolean before inversion.
Example usage in AlterDocumentTrait:
$this->alters = [
'active' => Alter::NOT, // single boolean
'flags' => Alter::NOT, // array of booleans
];
$data = [
'active' => true,
'flags' => [true, false, true],
];
$result = $this->alter($data);
// $result = [
// 'active' => false,
// 'flags' => [false, true, false],
// ]
Supported input types:
bool→ returns the opposite boolean.array<bool>→ returns a new array with all elements inverted.- any other value → cast to boolean and inverted.
Tags
Table of Contents
Methods
- alterNotProperty() : bool|array<string|int, mixed>
- Invert a boolean value or an array of booleans.
Methods
alterNotProperty()
Invert a boolean value or an array of booleans.
public
alterNotProperty(mixed $value[, bool &$modified = false ]) : bool|array<string|int, mixed>
Parameters
- $value : mixed
-
The value to alter. Can be a boolean, array of booleans, or any other value.
- $modified : bool = false
-
Reference flag set to true if the value is altered.
Tags
Return values
bool|array<string|int, mixed> —Returns the inverted boolean or array of inverted booleans.