for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Nip\Collections\Traits;
use Exception;
/**
* Class OperationsOnItemsTrait
* @package Nip\Collections\Traits
*/
trait OperationsOnItemsTrait
{
* Execute a callback over each item.
*
* @param callable $callback
* @return $this
public function each(callable $callback)
foreach ($this as $key => $item) {
if ($callback($item, $key) === false) {
break;
}
return $this;
* @param $key
* @param $value
* @throws Exception
public function valueAdd($key, $value)
if (!$this->has($key)) {
has()
If this is a false-positive, you can also ignore this issue in your code via the ignore-call annotation
ignore-call
if (!$this->/** @scrutinizer ignore-call */ has($key)) {
$this->set($key, $value);
set()
$this->/** @scrutinizer ignore-call */
set($key, $value);
return;
$currentValue = $this->get($key, 0);
get()
/** @scrutinizer ignore-call */
$currentValue = $currentValue === null ? 0 : $currentValue;
if (!is_numeric($currentValue)) {
throw new Exception("Current value for key {$key} is not numeric. [{$value}] provided. ");
$this->set($key, ($currentValue + $value));
public function valueSubtract($key, $value)
$this->set($key, ($currentValue - $value));