PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.0.1
Defender Security – Malware Scanner, Login Security & Firewall v3.0.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / web-auth / metadata-service / src / PatternAccuracyDescriptor.php

PatternAccuracyDescriptor.php in Defender Security – Malware Scanner, Login Security & Firewall 3.0.1, at vendor/web-auth/metadata-service/src/PatternAccuracyDescriptor.php

67 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 /*
6 * The MIT License (MIT)
7 *
8 * Copyright (c) 2014-2021 Spomky-Labs
9 *
10 * This software may be modified and distributed under the terms
11 * of the MIT license. See the LICENSE file for details.
12 */
13
14 namespace Webauthn\MetadataService;
15
16 use function array_key_exists;
17 use Assert\Assertion;
18 use function Safe\sprintf;
19
20 class PatternAccuracyDescriptor extends AbstractDescriptor
21 {
22 /**
23 * @var int
24 */
25 private $minComplexity;
26
27 public function __construct(int $minComplexity, ?int $maxRetries = null, ?int $blockSlowdown = null)
28 {
29 Assertion::greaterOrEqualThan($minComplexity, 0, Utils::logicException('Invalid data. The value of "minComplexity" must be a positive integer'));
30 $this->minComplexity = $minComplexity;
31 parent::__construct($maxRetries, $blockSlowdown);
32 }
33
34 public function getMinComplexity(): int
35 {
36 return $this->minComplexity;
37 }
38
39 public static function createFromArray(array $data): self
40 {
41 $data = Utils::filterNullValues($data);
42 Assertion::keyExists($data, 'minComplexity', Utils::logicException('The key "minComplexity" is missing'));
43 foreach (['minComplexity', 'maxRetries', 'blockSlowdown'] as $key) {
44 if (array_key_exists($key, $data)) {
45 Assertion::integer($data[$key], Utils::logicException(sprintf('Invalid data. The value of "%s" must be a positive integer', $key)));
46 }
47 }
48
49 return new self(
50 $data['minComplexity'],
51 $data['maxRetries'] ?? null,
52 $data['blockSlowdown'] ?? null
53 );
54 }
55
56 public function jsonSerialize(): array
57 {
58 $data = [
59 'minComplexity' => $this->minComplexity,
60 'maxRetries' => $this->getMaxRetries(),
61 'blockSlowdown' => $this->getBlockSlowdown(),
62 ];
63
64 return Utils::filterNullValues($data);
65 }
66 }
67