Completed
Push — develop ( f5141e...bd86d7 )
by Franck
18:00
created

Color::getHashCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of PHPPresentation - A pure PHP library for reading and writing
4
 * presentations documents.
5
 *
6
 * PHPPresentation is free software distributed under the terms of the GNU Lesser
7
 * General Public License version 3 as published by the Free Software Foundation.
8
 *
9
 * For the full copyright and license information, please read the LICENSE
10
 * file that was distributed with this source code. For the full list of
11
 * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12
 *
13
 * @link        https://github.com/PHPOffice/PHPPresentation
14
 * @copyright   2009-2015 PHPPresentation contributors
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
18
namespace PhpOffice\PhpPresentation\Style;
19
20
use PhpOffice\PhpPresentation\ComparableInterface;
21
22
/**
23
 * \PhpOffice\PhpPresentation\Style\Color
24
 */
25
class Color implements ComparableInterface
26
{
27
    /* Colors */
28
    const COLOR_BLACK                       = 'FF000000';
29
    const COLOR_WHITE                       = 'FFFFFFFF';
30
    const COLOR_RED                         = 'FFFF0000';
31
    const COLOR_DARKRED                     = 'FF800000';
32
    const COLOR_BLUE                        = 'FF0000FF';
33
    const COLOR_DARKBLUE                    = 'FF000080';
34
    const COLOR_GREEN                       = 'FF00FF00';
35
    const COLOR_DARKGREEN                   = 'FF008000';
36
    const COLOR_YELLOW                      = 'FFFFFF00';
37
    const COLOR_DARKYELLOW                  = 'FF808000';
38
39
    /**
40
     * ARGB - Alpha RGB
41
     *
42
     * @var string
43
     */
44
    private $argb;
45
46
    /**
47
     * Hash index
48
     *
49
     * @var string
50
     */
51
    private $hashIndex;
52
53
    /**
54
     * Create a new \PhpOffice\PhpPresentation\Style\Color
55
     *
56
     * @param string $pARGB
57
     */
58 359
    public function __construct($pARGB = self::COLOR_BLACK)
59
    {
60
        // Initialise values
61 359
        $this->argb            = $pARGB;
62 359
    }
63
64
    /**
65
     * Get ARGB
66
     *
67
     * @return string
68
     */
69 14
    public function getARGB()
70
    {
71 14
        return $this->argb;
72
    }
73
74
    /**
75
     * Set ARGB
76
     *
77
     * @param  string                    $pValue
78
     * @return \PhpOffice\PhpPresentation\Style\Color
79
     */
80 2
    public function setARGB($pValue = self::COLOR_BLACK)
81
    {
82 2
        if ($pValue == '') {
83 1
            $pValue = self::COLOR_BLACK;
84
        }
85 2
        $this->argb = $pValue;
86
87 2
        return $this;
88
    }
89
90
    /**
91
     * Get the alpha % of the ARGB
92
     * Will return 100 if no ARGB
93
     * @return integer
94
     */
95 14
    public function getAlpha()
96
    {
97 14
        $alpha = 100;
98 14
        if (strlen($this->argb) >= 6) {
99 14
            $dec = hexdec(substr($this->argb, 0, 2));
100 14
            $alpha = number_format(( $dec/255 ) * 100, 2);
101
        }
102 14
        return $alpha;
103
    }
104
105
    /**
106
     * Get RGB
107
     *
108
     * @return string
109
     */
110 97
    public function getRGB()
111
    {
112 97
        if (strlen($this->argb) == 6) {
113 1
            return $this->argb;
114
        } else {
115 97
            return substr($this->argb, 2);
116
        }
117
    }
118
119
    /**
120
     * Set RGB
121
     *
122
     * @param  string                    $pValue
123
     * @return \PhpOffice\PhpPresentation\Style\Color
124
     */
125 9
    public function setRGB($pValue = '000000')
126
    {
127 9
        if ($pValue == '') {
128 1
            $pValue = '000000';
129
        }
130 9
        $this->argb = 'FF' . $pValue;
131
132 9
        return $this;
133
    }
134
135
    /**
136
     * Get hash code
137
     *
138
     * @return string Hash code
139
     */
140 104
    public function getHashCode()
141
    {
142 104
        return md5(
143 104
            $this->argb
144 104
            . __CLASS__
145
        );
146
    }
147
148
    /**
149
     * Get hash index
150
     *
151
     * Note that this index may vary during script execution! Only reliable moment is
152
     * while doing a write of a workbook and when changes are not allowed.
153
     *
154
     * @return string Hash index
155
     */
156 1
    public function getHashIndex()
157
    {
158 1
        return $this->hashIndex;
159
    }
160
161
    /**
162
     * Set hash index
163
     *
164
     * Note that this index may vary during script execution! Only reliable moment is
165
     * while doing a write of a workbook and when changes are not allowed.
166
     *
167
     * @param string $value Hash index
168
     */
169 1
    public function setHashIndex($value)
170
    {
171 1
        $this->hashIndex = $value;
172 1
    }
173
}
174