PdfFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Factories;
4
5
use Mpdf\Mpdf;
6
7
/**
8
 * PdfFactory
9
 *
10
 * factory to create instance of Mpdf
11
 *
12
 * @created 2016-07-07
13
 * @author Tomas Litera <[email protected]>
14
 */
15
class PdfFactory
16
{
17
	/** @var Pdf */
18
	public $pdf;
19
20
	/** @var defaults */
21
	private $encoding = 'utf-8';
22
	private $paperFormat = 'A4';
23
	private $fontSize = 0;
24
	private $font = '';
25
	private $marginLeft = 15;
26
	private $marginRight = 15;
27
	private $marginTop = 16;
28
	private $marginBottom = 16;
29
	private $debugMode = false;
30
31
	/** Constructor */
32
	public function __construct(array $configuration)
33
	{
34
		$this->encoding 	= $configuration['encoding'];
35
		$this->paperFormat 	= $configuration['paperFormat'];
36
		$this->fontSize 	= $configuration['fontSize'];
37
		$this->font 		= $configuration['font'];
38
		$this->marginLeft 	= $configuration['marginLeft'];
39
		$this->marginRight 	= $configuration['marginRight'];
40
		$this->marginTop 	= $configuration['marginTop'];
41
		$this->marginBottom = $configuration['marginBottom'];
42
		$this->debugMode	= $configuration['debugMode'];
43
	}
44
45
	/**
46
	 * Return new Mpdf with few settings
47
	 *
48
	 * @return	Mpdf;
0 ignored issues
show
Documentation introduced by
The doc-type Mpdf; could not be parsed: Expected "|" or "end of type", but got ";" at position 4. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
49
	 */
50
	public function create()
51
	{
52
		$this->pdf = new Mpdf([
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Mpdf\Mpdf(array($th..., $this->marginBottom)) of type object<Mpdf\Mpdf> is incompatible with the declared type object<App\Factories\Pdf> of property $pdf.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
53
			$this->encoding,
54
			$this->paperFormat,
55
			$this->fontSize,
56
			$this->font,
57
			$this->marginLeft,
58
			$this->marginRight,
59
			$this->marginTop,
60
			$this->marginBottom
61
			]
62
		);
63
64
		// debugging on demand
65
		if($this->debugMode){
66
			$this->pdf->debug = true;
67
		}
68
		$this->pdf->useOnlyCoreFonts = true;
69
		$this->pdf->SetDisplayMode('fullpage');
70
		$this->pdf->autoScriptToLang = false;
71
		$this->pdf->defaultfooterfontsize = 16;
72
		$this->pdf->defaultfooterfontstyle = 'B';
73
74
		return $this->pdf;
75
	}
76
77
	/**
78
	 * Set margins of PDF
79
	 */
80
	public function setMargins($left, $right, $top, $bottom)
81
	{
82
		$this->marginLeft 	= $left;
83
		$this->marginRight 	= $right;
84
		$this->marginTop 	= $top;
85
		$this->marginBottom = $bottom;
86
	}
87
88
	/**
89
	 * Set paper format of PDF
90
	 */
91
	public function setPaperFormat($paperFormat)
92
	{
93
		$this->paperFormat = $paperFormat;
94
	}
95
}
96