Oihana PHP System

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
author

Marc Alcaraz (ekameleon)

since
1.0.0

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
example
$processor = new class {
use \oihana\traits\alters\AlterNotPropertyTrait;
};

// Single boolean
$modified = false;
$result = $processor->alterNotProperty(true, $modified);
// $result === false
// $modified === true

// Array of booleans
$array = [true, false, true];
$result = $processor->alterNotProperty($array, $modified);
// $result === [false, true, false]
// $modified === true
Return values
bool|array<string|int, mixed>

Returns the inverted boolean or array of inverted booleans.


        
On this page

Search results