Completed
Push — master ( 102ef4...1ff5c6 )
by smiley
02:47
created

QROutputAbstract::__construct()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 6
nc 4
nop 1
1
<?php
2
/**
3
 * Class QROutputAbstract
4
 *
5
 * @filesource   QROutputAbstract.php
6
 * @created      09.12.2015
7
 * @package      chillerlan\QRCode\Output
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2015 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\QRCode\Output;
14
15
/**
16
 *
17
 */
18
abstract class QROutputAbstract implements QROutputInterface{
19
20
	/**
21
	 * @var string
22
	 */
23
	protected $optionsInterface;
24
25
	/**
26
	 * @var array
27
	 */
28
	protected $types;
29
30
	/**
31
	 * @var array
32
	 */
33
	protected $matrix;
34
35
	/**
36
	 * @var int
37
	 */
38
	protected $pixelCount;
39
40
	/**
41
	 * @var object
42
	 */
43
	protected $options;
44
45
	/**
46
	 * @var \chillerlan\QRCode\Output\QROutputOptionsAbstract $outputOptions
47
	 * @throws \chillerlan\QRCode\Output\QRCodeOutputException
48
	 */
49
	public function __construct(QROutputOptionsAbstract $outputOptions = null){
50
		$this->options = $outputOptions;
51
52
		if($this->optionsInterface && !$this->options instanceof $this->optionsInterface){
53
			$this->options = new $this->optionsInterface;
54
		}
55
56
		if(is_array($this->types) && !in_array($this->options->type, $this->types , true)){
57
			throw new QRCodeOutputException('Invalid output type!');
58
		}
59
60
	}
61
62
	/**
63
	 * @param array $matrix
64
	 *
65
	 * @return $this
66
	 * @throws \chillerlan\QRCode\Output\QRCodeOutputException
67
	 */
68
	public function setMatrix(array $matrix){
69
		$this->pixelCount = count($matrix);
70
71
		// specify valid range?
72
		if($this->pixelCount < 2
73
			|| !isset($matrix[$this->pixelCount - 1])
74
			|| $this->pixelCount !== count($matrix[$this->pixelCount - 1])
75
		){
76
			throw new QRCodeOutputException('Invalid matrix!');
77
		}
78
79
		$this->matrix = $matrix;
80
81
		return $this;
82
	}
83
84
}
85