for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace suda\orm\struct;
trait ArrayDataTrait
{
use PropertyDataTrait;
/**
* 表数据
*
* @var array
*/
protected $data = [];
public function offsetSet($offset, $value)
$this->__set($offset, $value);
}
public function offsetExists($offset)
return $this->__isset($offset);
public function offsetUnset($offset)
$this->__unset($offset);
public function offsetGet($offset)
return $this->__get($offset);
* 设置值
* @param string $name
* @param mixed $value
public function __set(string $name, $value)
$this->assertFieldName($name);
$this->data[$name] = $value;
* 获取参数值
* @return mixed
public function __get(string $name)
return $this->data[$name] ?? null;
* 判断是否设置
* @return boolean
public function __isset(string $name)
return array_key_exists($name, $this->data);
* 取消设置值
public function __unset(string $name)
unset($this->data[$name]);
* 断言字段
* @return void
protected function assertFieldName(string $name)
if ($this->checkFieldExist($name) === false) {
$this->checkFieldExist($name) === false
false
throw new InvalidArgumentException(sprintf('[%s] has no attribute %s', static::class, $name), 0);
suda\orm\struct\InvalidArgumentException
InvalidArgumentException
\
* 检查字段是否存在
public function checkFieldExist(string $name)
$name
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
public function checkFieldExist(/** @scrutinizer ignore-unused */ string $name)
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
return true;