PluginProbe ʕ •ᴥ•ʔ
Transferito: WP Migration / trunk
Transferito: WP Migration vtrunk
trunk 11.4.0 12.0.0 13.1.0 14.0.0 14.0.11 14.0.7 14.1.0 14.1.1 14.1.2 14.1.3 14.1.4
transferito / vendor / aws / aws-sdk-php / src / Crypto / Polyfill / NeedsTrait.php
transferito / vendor / aws / aws-sdk-php / src / Crypto / Polyfill Last commit date
AesGcm.php 11 months ago ByteArray.php 11 months ago Gmac.php 11 months ago Key.php 11 months ago NeedsTrait.php 11 months ago
NeedsTrait.php
39 lines
1 <?php
2 namespace Aws\Crypto\Polyfill;
3
4 use Aws\Exception\CryptoPolyfillException;
5
6 /**
7 * Trait NeedsTrait
8 * @package Aws\Crypto\Polyfill
9 */
10 trait NeedsTrait
11 {
12 /**
13 * Preconditions, postconditions, and loop invariants are very
14 * useful for safe programing. They also document the specifications.
15 * This function is to help simplify the semantic burden of parsing
16 * these constructions.
17 *
18 * Instead of constructions like
19 * if (!(GOOD CONDITION)) {
20 * throw new \Exception('condition not true');
21 * }
22 *
23 * you can write:
24 * needs(GOOD CONDITION, 'condition not true');
25 * @param $condition
26 * @param $errorMessage
27 * @param null $exceptionClass
28 */
29 public static function needs($condition, $errorMessage, $exceptionClass = null)
30 {
31 if (!$condition) {
32 if (!$exceptionClass) {
33 $exceptionClass = CryptoPolyfillException::class;
34 }
35 throw new $exceptionClass($errorMessage);
36 }
37 }
38 }
39