Failed Conditions
Push — master ( f708ed...e3206a )
by Florent
07:39 queued 05:10
created

Hash::getLength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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