Completed
Push — master ( f68f3b...859d26 )
by Josh
02:07
created

Utf8::outputValidValue()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
ccs 13
cts 13
cp 1
rs 9.0534
cc 4
eloc 13
nc 4
nop 1
crap 4
1
<?php
2
3
/**
4
* @package   s9e\RegexpBuilder
5
* @copyright Copyright (c) 2016 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\RegexpBuilder\Output;
9
10
class Utf8 extends BaseImplementation
11
{
12
	/** {@inheritdoc} */
13
	protected $maxValue = 0x10FFFF;
14
15
	/**
16
	* {@inheritdoc}
17
	*/
18 9
	protected function outputValidValue($value)
19
	{
20 9
		if ($value < 0x80)
21
		{
22 6
			return chr($value);
23
		}
24 3
		if ($value < 0x800)
25
		{
26 1
			return chr(0xC0 | ($value >> 6)) . chr(0x80 | ($value & 0x3F));
27
		}
28 2
		if ($value < 0x10000)
29
		{
30 1
			return chr(0xE0 | ($value >> 12))
31 1
			     . chr(0x80 | (($value >> 6) & 0x3F))
32 1
			     . chr(0x80 | ($value & 0x3F));
33
		}
34 1
		return chr(0xF0 | ($value >> 18))
35 1
		     . chr(0x80 | (($value >> 12) & 0x3F))
36 1
		     . chr(0x80 | (($value >> 6) & 0x3F))
37 1
		     . chr(0x80 | ($value & 0x3F));
38
	}
39
}