mirror of https://github.com/MISP/MISP
chg: [internal] Use const arrays
parent
cc51526b7a
commit
1a30c2f7dc
|
@ -22,7 +22,7 @@ class AttachmentScan extends AppModel
|
|||
* List of supported object templates
|
||||
* @var string[]
|
||||
*/
|
||||
private $signatureTemplates = [
|
||||
private const SIGNATURE_TEMPLATES = [
|
||||
'4dbb56ef-4763-4c97-8696-a2bfc305cf8e', // av-signature
|
||||
'984c5c39-be7f-4e1e-b034-d3213bac51cb', // sb-signature
|
||||
];
|
||||
|
@ -427,7 +427,7 @@ class AttachmentScan extends AppModel
|
|||
if (!isset($object['template_uuid'])) {
|
||||
continue;
|
||||
}
|
||||
if (in_array($object['template_uuid'], $this->signatureTemplates, true)) {
|
||||
if (in_array($object['template_uuid'], self::SIGNATURE_TEMPLATES, true)) {
|
||||
$software = null;
|
||||
$signatures = array();
|
||||
foreach ($object['Attribute'] as $attribute) {
|
||||
|
|
|
@ -358,7 +358,7 @@ class Attribute extends AppModel
|
|||
if (!empty($this->data['Attribute']['type'])) {
|
||||
$compositeTypes = $this->getCompositeTypes();
|
||||
// explode composite types in value1 and value2
|
||||
if (in_array($this->data['Attribute']['type'], $compositeTypes)) {
|
||||
if (in_array($this->data['Attribute']['type'], $compositeTypes, true)) {
|
||||
$pieces = explode('|', $this->data['Attribute']['value']);
|
||||
if (2 != count($pieces)) {
|
||||
throw new InternalErrorException(__('Composite type, but value not explodable'));
|
||||
|
@ -754,7 +754,7 @@ class Attribute extends AppModel
|
|||
return true;
|
||||
}
|
||||
|
||||
private $__hexHashLengths = array(
|
||||
private const HEX_HAS_LENGTHS = array(
|
||||
'authentihash' => 64,
|
||||
'md5' => 32,
|
||||
'imphash' => 32,
|
||||
|
@ -812,7 +812,7 @@ class Attribute extends AppModel
|
|||
if ($this->isHashValid($type, $value)) {
|
||||
return true;
|
||||
} else {
|
||||
$length = $this->__hexHashLengths[$type];
|
||||
$length = self::HEX_HAS_LENGTHS[$type];
|
||||
return __('Checksum has an invalid length or format (expected: %s hexadecimal characters). Please double check the value or select type "other".', $length);
|
||||
}
|
||||
case 'tlsh':
|
||||
|
@ -885,7 +885,7 @@ class Attribute extends AppModel
|
|||
case 'filename|sha3-512':
|
||||
case 'filename|authentihash':
|
||||
$parts = explode('|', $type);
|
||||
$length = $this->__hexHashLengths[$parts[1]];
|
||||
$length = self::HEX_HAS_LENGTHS[$parts[1]];
|
||||
if (preg_match("#^.+\|[0-9a-f]{" . $length . "}$#", $value)) {
|
||||
$returnValue = true;
|
||||
} else {
|
||||
|
@ -4251,11 +4251,10 @@ class Attribute extends AppModel
|
|||
*/
|
||||
private function isHashValid($type, $value)
|
||||
{
|
||||
if (!isset($this->__hexHashLengths[$type])) {
|
||||
if (!isset(self::HEX_HAS_LENGTHS[$type])) {
|
||||
throw new InvalidArgumentException("Invalid hash type '$type'.");
|
||||
}
|
||||
$length = $this->__hexHashLengths[$type];
|
||||
return strlen($value) === $length && ctype_xdigit($value);
|
||||
return strlen($value) === self::HEX_HAS_LENGTHS[$type] && ctype_xdigit($value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,7 +15,8 @@ class AuditLogBehavior extends ModelBehavior
|
|||
/** @var bool */
|
||||
private $enabled;
|
||||
|
||||
private $skipFields = [
|
||||
// Hash is faster that in_array
|
||||
private const SKIP_FIELDS = [
|
||||
'id' => true,
|
||||
'lastpushedid' => true,
|
||||
'timestamp' => true,
|
||||
|
@ -291,7 +292,7 @@ class AuditLogBehavior extends ModelBehavior
|
|||
$dbFields = $model->schema();
|
||||
$changedFields = [];
|
||||
foreach ($model->data[$model->alias] as $key => $value) {
|
||||
if (isset($this->skipFields[$key])) {
|
||||
if (isset(self::SKIP_FIELDS[$key])) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($dbFields[$key])) {
|
||||
|
|
Loading…
Reference in New Issue