for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Jaxon\Response\Plugin\DataBag;
use function is_array;
use function array_map;
class DataBag
{
/**
* @var array
*/
protected $aData = [];
* @var bool
protected $bTouched = false;
* The constructor
*
* @param array $aData
public function __construct(array $aData)
// Ensure all contents are arrays.
$this->aData = array_map(function($aValue) {
return is_array($aValue) ? $aValue : [];
}, $aData);
}
* @return bool
public function touched(): bool
return $this->bTouched;
* @return array
public function getAll(): array
return $this->aData;
* @param string $sBag
* @param string $sKey
* @param mixed $xValue
* @return void
public function set(string $sBag, string $sKey, $xValue)
$this->bTouched = true;
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
$a = "a"; $ab = "ab"; $abc = "abc";
will produce issues in the first and second line, while this second example
will produce no issues.
$this->aData[$sBag][$sKey] = $xValue;
* @return mixed
public function get(string $sBag, string $sKey, $xValue = null)
return $this->aData[$sBag][$sKey] ?? $xValue;