for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Entity meta trait file
*
* @package EBloodBank
* @subpackage Traits
* @since 1.0
*/
namespace EBloodBank\Traits;
* Entity meta trait
trait EntityMeta
{
* Entity meta
* @var array
protected $meta = [];
* Get entity meta value
* @return mixed
* @since 1.4
public function getMeta(string $key, $fallback = '')
$value = $fallback;
if (! is_array($this->meta)) {
is_array($this->meta)
true
return $value;
}
if (! isset($this->meta[$key])) {
$value = $this->meta[$key];
* Set entity meta value
* @return void
public function setMeta(string $key, $value, $sanitize = false, $validate = true)
if (is_null($this->meta)) {
is_null($this->meta)
false
$this->meta = [];
if ($sanitize) {
$value = static::sanitizeMeta($key, $value);
if (! $validate || static::validateMeta($key, $value)) {
$this->meta[$key] = $value;
* Delete meta value
public function deleteMeta(string $key)
unset($this->meta[$key]);
* Sanitize meta value
* @static
public static function sanitizeMeta(string $key, $value)
$key
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
public static function sanitizeMeta(/** @scrutinizer ignore-unused */ string $key, $value)
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
* Validate meta value
* @return bool
public static function validateMeta(string $key, $value)
public static function validateMeta(/** @scrutinizer ignore-unused */ string $key, $value)
$value
public static function validateMeta(string $key, /** @scrutinizer ignore-unused */ $value)
return true;