Completed
Push — v2.0.x ( 7a58b6 )
by Florent
24:58
created

JWSFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A createJWS() 0 7 1
A createJWSWithDetachedPayload() 0 6 2
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2015 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 Base64Url\Base64Url;
15
use Jose\Object\JWS;
16
17
final class JWSFactory
18
{
19
    /**
20
     * JWSFactory constructor.
21
     *
22
     * This factory is not supposed to be instantiated
23
     */
24
    private function __construct() {}
25
26
    /**
27
     * @param mixed $payload
28
     *
29
     * @return \Jose\Object\JWSInterface
30
     */
31
    public static function createJWS($payload)
32
    {
33
        $jws = new JWS();
34
        $jws = $jws->withPayload($payload);
35
36
        return $jws;
37
    }
38
39
    /**
40
     * @param mixed  $payload
41
     * @param string $encoded_payload
42
     *
43
     * @return \Jose\Object\JWSInterface
44
     */
45
    public static function createJWSWithDetachedPayload($payload, &$encoded_payload)
46
    {
47
        $encoded_payload = Base64Url::encode(is_string($payload)?$payload:json_encode($payload));
48
49
        return new JWS();
50
    }
51
}
52