Completed
Push — master ( 7aad34...96e43e )
by Florent
02:35
created

JWEFactory::createJWE()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 13
rs 9.4285
cc 2
eloc 8
nc 2
nop 4
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Factory;
13
14
use Jose\Object\JWE;
15
16
final class JWEFactory
17
{
18
    /**
19
     * @param mixed       $payload
20
     * @param array       $shared_protected_headers
21
     * @param array       $shared_headers
22
     * @param null|string $aad
23
     *
24
     * @return \Jose\Object\JWEInterface
25
     */
26
    public static function createJWE($payload, array $shared_protected_headers = [], array $shared_headers = [], $aad = null)
27
    {
28
        $jwe = new JWE();
29
        $jwe = $jwe->withSharedProtectedHeaders($shared_protected_headers);
30
        $jwe = $jwe->withSharedHeaders($shared_headers);
31
        $jwe = $jwe->withPayload($payload);
32
33
        if (null !== $aad) {
34
            $jwe = $jwe->withAAD($aad);
35
        }
36
37
        return $jwe;
38
    }
39
}
40