Merge pull request #7595 from JakubOnderka/code-cleanup-vol4

Code cleanup vol4
pull/7612/head
Jakub Onderka 2021-07-22 14:03:19 +02:00 committed by GitHub
commit fe548afdea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 14 deletions

View File

@ -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
];
@ -77,7 +77,7 @@ class AttachmentScan extends AppModel
$moduleInfo = $this->loadModuleInfo($this->attachmentScanModuleName);
if (in_array('attachment', $moduleInfo['types'])) {
if (in_array('attachment', $moduleInfo['types'], true)) {
$fakeAttribute = [
'uuid' => CakeText::uuid(),
'event_id' => 1,
@ -427,7 +427,7 @@ class AttachmentScan extends AppModel
if (!isset($object['template_uuid'])) {
continue;
}
if (in_array($object['template_uuid'], $this->signatureTemplates)) {
if (in_array($object['template_uuid'], self::SIGNATURE_TEMPLATES, true)) {
$software = null;
$signatures = array();
foreach ($object['Attribute'] as $attribute) {
@ -469,7 +469,7 @@ class AttachmentScan extends AppModel
throw new Exception("Module $moduleName not found.");
}
if (!in_array('expansion', $module['meta']['module-type'])) {
if (!in_array('expansion', $module['meta']['module-type'], true)) {
throw new Exception("Module $moduleName must be expansion type.");
}
@ -521,7 +521,7 @@ class AttachmentScan extends AppModel
*/
private function checkType($type)
{
if (!in_array($type, [self::TYPE_ATTRIBUTE, self::TYPE_SHADOW_ATTRIBUTE])) {
if (!in_array($type, [self::TYPE_ATTRIBUTE, self::TYPE_SHADOW_ATTRIBUTE], true)) {
throw new InvalidArgumentException("Type must be 'Attribute' or 'ShadowAttribute', '$type' provided.");
}
}

View File

@ -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);
}
/**

View File

@ -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])) {