Failed Conditions
Pull Request — master (#115)
by Florent
05:43 queued 02:42
created

Hash   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A sha1() 0 4 1
A sha256() 0 4 1
A sha384() 0 4 1
A sha512() 0 4 1
A __construct() 0 5 1
A getLength() 0 4 1
A hash() 0 4 1
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\Util;
13
14
class Hash
15
{
16
    /**
17
     * Hash Parameter.
18
     *
19
     * @var string
20
     */
21
    private $hash;
22
23
    /**
24
     * Hash Length.
25
     *
26
     * @var int
27
     */
28
    private $length;
29
30
    /**
31
     * @return \Jose\Util\Hash
32
     */
33
    public static function sha1()
34
    {
35
        return new self('sha1', 20);
36
    }
37
38
    /**
39
     * @return \Jose\Util\Hash
40
     */
41
    public static function sha256()
42
    {
43
        return new self('sha256', 32);
44
    }
45
46
    /**
47
     * @return \Jose\Util\Hash
48
     */
49
    public static function sha384()
50
    {
51
        return new self('sha384', 48);
52
    }
53
54
    /**
55
     * @return \Jose\Util\Hash
56
     */
57
    public static function sha512()
58
    {
59
        return new self('sha512', 64);
60
    }
61
62
    /**
63
     * @param string $hash
64
     * @param int    $length
65
     */
66
    private function __construct($hash, $length)
67
    {
68
        $this->hash = $hash;
69
        $this->length = $length;
70
    }
71
72
    /**
73
     * @return int
74
     */
75
    public function getLength()
76
    {
77
        return $this->length;
78
    }
79
80
    /**
81
     * Compute the HMAC.
82
     *
83
     * @param string $text
84
     *
85
     * @return string
86
     */
87
    public function hash($text)
0 ignored issues
show
Best Practice introduced by
Using PHP4-style constructors that are named like the class is not recommend; better use the more explicit __construct method.
Loading history...
88
    {
89
        return hash($this->hash, $text, true);
90
    }
91
}
92