PaymentSlip::setAttributes()   F
last analyzed

Complexity

Conditions 21
Paths > 20000

Size

Total Lines 65
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 34
CRAP Score 24.0487

Importance

Changes 0
Metric Value
cc 21
eloc 41
c 0
b 0
f 0
nc 59049
nop 11
dl 0
loc 65
rs 0
ccs 34
cts 42
cp 0.8095
crap 24.0487

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * Swiss Payment Slip
4
 *
5
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
6
 * @copyright 2012-2016 Some nice Swiss guys
7
 * @author Marc Würth [email protected]
8
 * @author Manuel Reinhard <[email protected]>
9
 * @author Peter Siska <[email protected]>
10
 * @link https://github.com/ravage84/SwissPaymentSlip/
11
 */
12
13
namespace SwissPaymentSlip\SwissPaymentSlip;
14
15
use InvalidArgumentException;
16
17
/**
18
 * Swiss Payment Slip
19
 *
20
 * A base class to describe the common look and field placement/display
21
 * of the various types of Swiss payment slips.
22
 *
23
 * The data of the fields is organized by its sister class PaymentSlipData.
24
 *
25
 * @link https://www.postfinance.ch/en/cust/download/bizdoc.html Various documents for Post business customers
26
 * @uses PaymentSlipData To store the slip data.
27
 *
28
 * @todo Include EUR framed slip image (701) --> back side!
29
 * @todo Include EUR boxed slip image (701) --> back side!
30
 * @todo Include CHF boxed slip image (609, ESR+)
31
 * @todo Implement cash on delivery (Nachnahme)
32
 * @todo Include cash on delivery (Nachnahme) slip image
33
 * @todo Create constants for the attribute keys
34
 * @todo Create constants for left, right and center text alignment (L, R, C)
35
 * @todo Create central cell placement and formatting code (lines as array, attributes)...
36
 * @todo Consider extracting the attributes as separate class
37
 */
38
abstract class PaymentSlip
39
{
40
    /**
41
     * The payment slip value object, which contains the payment slip data
42
     *
43
     * @var PaymentSlipData
44
     */
45
    protected $paymentSlipData = null;
46
47
    /**
48
     * Starting X position of the slip in mm
49
     *
50
     * @var int|float
51
     */
52
    protected $slipPosX = 0;
53
54
    /**
55
     * Starting Y position of the slip in mm
56
     *
57
     * @var int|float
58
     */
59
    protected $slipPosY = 191;
60
61
    /**
62
     * The height of the slip
63
     *
64
     * @var int|float
65
     */
66
    protected $slipHeight = 106; // default height of an orange slip
67
68
    /**
69
     * The width of the slip
70
     *
71
     * @var int|float
72
     */
73
    protected $slipWidth = 210; // default width of an orange slip
74
75
    /**
76
     * Background of the slip
77
     *
78
     * Can be either 'transparent', a color or an image
79
     *
80
     * @var null|string
81
     */
82
    protected $slipBackground = null;
83
84
    /**
85
     * The default font family
86
     *
87
     * @var string
88
     */
89
    protected $defaultFontFamily = 'Helvetica';
90
91
    /**
92
     * The default font size
93
     *
94
     * @var string
95
     */
96
    protected $defaultFontSize = '10';
97
98
    /**
99
     * The default font color
100
     *
101
     * @var string
102
     */
103
    protected $defaultFontColor = '#000';
104
105
    /**
106
     * The default line height
107
     *
108
     * @var int
109
     */
110
    protected $defaultLineHeight = 4;
111
112
    /**
113
     * The default text alignment
114
     *
115
     * @var string
116
     */
117
    protected $defaultTextAlign = 'L';
118
119
    /**
120
     * Determines whether the background should be displayed
121
     *
122
     * @var bool
123
     */
124
    protected $displayBackground = true;
125
126
    /**
127
     * Determines whether the bank details should be displayed
128
     *
129
     * @var bool
130
     */
131
    protected $displayBank = true;
132
133
    /**
134
     * Determines whether the recipient details should be displayed
135
     *
136
     * @var bool
137
     */
138
    protected $displayRecipient = true;
139
140
    /**
141
     * Determines whether the account should be displayed
142
     *
143
     * @var bool
144
     */
145
    protected $displayAccount = true;
146
147
    /**
148
     * Determines whether the amount should be displayed
149
     *
150
     * @var bool
151
     */
152
    protected $displayAmount = true;
153
154
    /**
155
     * Determines whether the payer details should be displayed
156
     *
157
     * @var bool
158
     */
159
    protected $displayPayer = true;
160
161
    /**
162
     * Attributes of the left bank element
163
     *
164
     * @var array
165
     */
166
    protected $bankLeftAttr = [];
167
168
    /**
169
     * Attributes of the right bank element
170
     *
171
     * @var array
172
     */
173
    protected $bankRightAttr = [];
174
175
    /**
176
     * Attributes of the left recipient element
177
     *
178
     * @var array
179
     */
180
    protected $recipientLeftAttr = [];
181
182
    /**
183
     * Attributes of the right recipient element
184
     *
185
     * @var array
186
     */
187
    protected $recipientRightAttr = [];
188
189
    /**
190
     * Attributes of the left account element
191
     *
192
     * @var array
193
     */
194
    protected $accountLeftAttr = [];
195
196
    /**
197
     * Attributes of the right account element
198
     *
199
     * @var array
200
     */
201
    protected $accountRightAttr = [];
202
203
    /**
204
     * Attributes of the left francs amount element
205
     *
206
     * @var array
207
     */
208
    protected $amountFrancsLeftAttr = [];
209
210
    /**
211
     * Attributes of the right francs amount element
212
     *
213
     * @var array
214
     */
215
    protected $amountFrancsRightAttr = [];
216
217
    /**
218
     * Attributes of the left cents amount element
219
     *
220
     * @var array
221
     */
222
    protected $amountCentsLeftAttr = [];
223
224
    /**
225
     * Attributes of the right cents amount element
226
     *
227
     * @var array
228
     */
229
    protected $amountCentsRightAttr = [];
230
231
    /**
232
     * Attributes of the left payer element
233
     *
234
     * @var array
235
     */
236
    protected $payerLeftAttr = [];
237
238
    /**
239
     * Attributes of the right payer element
240
     *
241
     * @var array
242
     */
243
    protected $payerRightAttr = [];
244
245
    /**
246
     * Create a new payment slip
247
     *
248
     * @param PaymentSlipData $paymentSlipData The payment slip data.
249
     * @param float|null $slipPosX The optional X position of the slip.
250
     * @param float|null $slipPosY The optional Y position of the slip.
251
     */
252 1
    public function __construct(PaymentSlipData $paymentSlipData, $slipPosX = null, $slipPosY = null)
253
    {
254 1
        $this->paymentSlipData = $paymentSlipData;
255
256 1
        if (!is_null($slipPosX)) {
257 1
            $this->setSlipPosX($slipPosX);
258
        }
259 1
        if (!is_null($slipPosY)) {
260 1
            $this->setSlipPosY($slipPosY);
261
        }
262
263 1
        $this->setDefaults();
264 1
    }
265
266
    /**
267
     * Sets the common default attributes of the elements
268
     *
269
     * @return $this The current instance for a fluent interface.
270
     */
271 13
    protected function setDefaults()
272
    {
273 13
        $this->setBankLeftAttr(3, 8, 50, 4);
274 13
        $this->setBankRightAttr(66, 8, 50, 4);
275 13
        $this->setRecipientLeftAttr(3, 23, 50, 4);
276 13
        $this->setRecipientRightAttr(66, 23, 50, 4);
277 13
        $this->setAccountLeftAttr(27, 43, 30, 4);
278 13
        $this->setAccountRightAttr(90, 43, 30, 4);
279 13
        $this->setAmountFrancsLeftAttr(5, 50.5, 35, 4);
280 13
        $this->setAmountFrancsRightAttr(66, 50.5, 35, 4);
281 13
        $this->setAmountCentsLeftAttr(50, 50.5, 6, 4);
282 13
        $this->setAmountCentsRightAttr(111, 50.5, 6, 4);
283 13
        $this->setPayerLeftAttr(3, 65, 50, 4);
284 13
        $this->setPayerRightAttr(125, 48, 50, 4);
285
286 13
        return $this;
287
    }
288
289
    /**
290
     * Get the slip data object of the slip
291
     *
292
     * @return PaymentSlipData The data object of the slip.
293
     */
294 1
    public function getPaymentSlipData()
295
    {
296 1
        return $this->paymentSlipData;
297
    }
298
299
    /**
300
     * Set the starting X & Y position of the slip
301
     *
302
     * @param float $slipPosX The starting X position of the slip.
303
     * @param float $slipPosY The starting Y position of the slip
304
     * @return $this The current instance for a fluent interface.
305
     */
306 3
    public function setSlipPosition($slipPosX, $slipPosY)
307
    {
308 3
        $this->setSlipPosX($slipPosX);
309 2
        $this->setSlipPosY($slipPosY);
310
311 1
        return $this;
312
    }
313
314
    /**
315
     * Set the starting X position of the slip
316
     *
317
     * @param float $slipPosX The starting X position of the slip.
318
     * @return $this The current instance for a fluent interface.
319
     */
320 1
    protected function setSlipPosX($slipPosX)
321
    {
322 1
        $this->isIntOrFloat($slipPosX, 'slipPosX');
323 1
        $this->slipPosX = $slipPosX;
324
325 1
        return $this;
326
    }
327
328
    /**
329
     * Set the starting Y position of the slip
330
     *
331
     * @param float $slipPosY The starting Y position of the slip.
332
     * @return $this The current instance for a fluent interface.
333
     */
334 1
    protected function setSlipPosY($slipPosY)
335
    {
336 1
        $this->isIntOrFloat($slipPosY, '$slipPosY');
337 1
        $this->slipPosY = $slipPosY;
338
339 1
        return $this;
340
    }
341
342
    /**
343
     * Set the height & width of the slip
344
     *
345
     * @param float $slipWidth The width of the slip
346
     * @param float $slipHeight The height of the slip
347
     * @return $this The current instance for a fluent interface.
348
     */
349 3
    public function setSlipSize($slipWidth, $slipHeight)
350
    {
351 3
        $this->setSlipHeight($slipHeight);
352 2
        $this->setSlipWidth($slipWidth);
353
354 1
        return $this;
355
    }
356
357
    /**
358
     * Set the width of the slip
359
     *
360
     * @param float $slipWidth The width of the slip
361
     * @return $this The current instance for a fluent interface.
362
     */
363 1
    protected function setSlipWidth($slipWidth)
364
    {
365 1
        $this->isIntOrFloat($slipWidth, 'slipWidth');
366 1
        $this->slipWidth = $slipWidth;
367
368 1
        return $this;
369
    }
370
371
    /**
372
     * Set the height of the slip
373
     *
374
     * @param float $slipHeight The height of the slip
375
     * @return $this The current instance for a fluent interface.
376
     */
377 1
    protected function setSlipHeight($slipHeight)
378
    {
379 1
        $this->isIntOrFloat($slipHeight, 'slipHeight');
380 1
        $this->slipHeight = $slipHeight;
381
382 1
        return $this;
383
    }
384
385
    /**
386
     * Set the background of the slip
387
     *
388
     * Can be either 'transparent', a color or an image
389
     *
390
     * @param string $slipBackground The background of the slip.
391
     * @return $this The current instance for a fluent interface.
392
     *
393
     * @todo Implement sanity checks on parameter (filename or color)
394
     */
395 1
    public function setSlipBackground($slipBackground)
396
    {
397 1
        $this->slipBackground = $slipBackground;
398
399 1
        return $this;
400
    }
401
402
    /**
403
     * Set the attributes for a given payment slip element
404
     *
405
     * @param array $element The element (attributes) to set.
406
     * @param float|null $posX The X position.
407
     * @param float|null $posY The Y Position.
408
     * @param float|null $width The width.
409
     * @param float|null $height The height.
410
     * @param string|null $background The background.
411
     * @param string|null $fontFamily The font family.
412
     * @param float|null $fontSize The font size.
413
     * @param string|null $fontColor The font color.
414
     * @param float|null $lineHeight The line height.
415
     * @param string|null $textAlign The text alignment.
416
     * @return $this The current instance for a fluent interface.
417
     */
418 15
    protected function setAttributes(
419
        &$element,
420
        $posX = null,
421
        $posY = null,
422
        $width = null,
423
        $height = null,
424
        $background = null,
425
        $fontFamily = null,
426
        $fontSize = null,
427
        $fontColor = null,
428
        $lineHeight = null,
429
        $textAlign = null
430
    ) {
431 15
        if ($posX) {
432 15
            $element['PosX'] = $posX;
433
        } elseif (!isset($element['PosX'])) {
434
            $element['PosX'] = 0;
435
        }
436 15
        if ($posY) {
437 15
            $element['PosY'] = $posY;
438
        } elseif (!isset($element['PosY'])) {
439
            $element['PosY'] = 0;
440
        }
441 15
        if ($width) {
442 15
            $element['Width'] = $width;
443
        } elseif (!isset($element['Width'])) {
444
            $element['Width'] = 0;
445
        }
446 15
        if ($height) {
447 15
            $element['Height'] = $height;
448
        } elseif (!isset($element['Height'])) {
449
            $element['Height'] = 0;
450
        }
451 15
        if (!empty($background)) {
452 15
            $element['Background'] = $background;
453 15
        } elseif (!isset($element['Background'])) {
454 15
            $element['Background'] = 'transparent';
455
        }
456 15
        if (!empty($fontFamily)) {
457 15
            $element['FontFamily'] = $fontFamily;
458 15
        } elseif (!isset($element['FontFamily'])) {
459 15
            $element['FontFamily'] = $this->defaultFontFamily;
460
        }
461 15
        if ($fontSize) {
462 15
            $element['FontSize'] = $fontSize;
463 15
        } elseif (!isset($element['FontSize'])) {
464 15
            $element['FontSize'] = $this->defaultFontSize;
465
        }
466 15
        if (!empty($fontColor)) {
467 15
            $element['FontColor'] = $fontColor;
468 15
        } elseif (!isset($element['FontColor'])) {
469 15
            $element['FontColor'] = $this->defaultFontColor;
470
        }
471 15
        if ($lineHeight) {
472 15
            $element['LineHeight'] = $lineHeight;
473 15
        } elseif (!isset($element['LineHeight'])) {
474 15
            $element['LineHeight'] = $this->defaultLineHeight;
475
        }
476 15
        if (!empty($textAlign)) {
477 15
            $element['TextAlign'] = $textAlign;
478 15
        } elseif (!isset($element['TextAlign'])) {
479 15
            $element['TextAlign'] = $this->defaultTextAlign;
480
        }
481
482 15
        return $this;
483
    }
484
485
    /**
486
     * Set the left bank attributes
487
     *
488
     * @param float|null $posX The X position.
489
     * @param float|null $posY The Y Position.
490
     * @param float|null $width The width.
491
     * @param float|null $height The height.
492
     * @param string|null $background The background.
493
     * @param string|null $fontFamily The font family.
494
     * @param float|null $fontSize The font size.
495
     * @param string|null $fontColor The font color.
496
     * @param float|null $lineHeight The line height.
497
     * @param string|null $textAlign The text alignment.
498
     * @return $this The current instance for a fluent interface.
499
     */
500 1
    public function setBankLeftAttr(
501
        $posX = null,
502
        $posY = null,
503
        $width = null,
504
        $height = null,
505
        $background = null,
506
        $fontFamily = null,
507
        $fontSize = null,
508
        $fontColor = null,
509
        $lineHeight = null,
510
        $textAlign = null
511
    ) {
512 1
        $this->setAttributes(
513 1
            $this->bankLeftAttr,
514 1
            $posX,
515 1
            $posY,
516 1
            $width,
517 1
            $height,
518 1
            $background,
519 1
            $fontFamily,
520 1
            $fontSize,
521 1
            $fontColor,
522 1
            $lineHeight,
523 1
            $textAlign
524
        );
525
526 1
        return $this;
527
    }
528
529
    /**
530
     * Set the right bank attributes
531
     *
532
     * @param float|null $posX The X position.
533
     * @param float|null $posY The Y Position.
534
     * @param float|null $width The width.
535
     * @param float|null $height The height.
536
     * @param string|null $background The background.
537
     * @param string|null $fontFamily The font family.
538
     * @param float|null $fontSize The font size.
539
     * @param string|null $fontColor The font color.
540
     * @param float|null $lineHeight The line height.
541
     * @param string|null $textAlign The text alignment.
542
     * @return $this The current instance for a fluent interface.
543
     */
544 1
    public function setBankRightAttr(
545
        $posX = null,
546
        $posY = null,
547
        $width = null,
548
        $height = null,
549
        $background = null,
550
        $fontFamily = null,
551
        $fontSize = null,
552
        $fontColor = null,
553
        $lineHeight = null,
554
        $textAlign = null
555
    ) {
556 1
        $this->setAttributes(
557 1
            $this->bankRightAttr,
558 1
            $posX,
559 1
            $posY,
560 1
            $width,
561 1
            $height,
562 1
            $background,
563 1
            $fontFamily,
564 1
            $fontSize,
565 1
            $fontColor,
566 1
            $lineHeight,
567 1
            $textAlign
568
        );
569
570 1
        return $this;
571
    }
572
573
    /**
574
     * Set the left recipient attributes
575
     *
576
     * @param float|null $posX The X position.
577
     * @param float|null $posY The Y Position.
578
     * @param float|null $width The width.
579
     * @param float|null $height The height.
580
     * @param string|null $background The background.
581
     * @param string|null $fontFamily The font family.
582
     * @param float|null $fontSize The font size.
583
     * @param string|null $fontColor The font color.
584
     * @param float|null $lineHeight The line height.
585
     * @param string|null $textAlign The text alignment.
586
     * @return $this The current instance for a fluent interface.
587
     */
588 1
    public function setRecipientLeftAttr(
589
        $posX = null,
590
        $posY = null,
591
        $width = null,
592
        $height = null,
593
        $background = null,
594
        $fontFamily = null,
595
        $fontSize = null,
596
        $fontColor = null,
597
        $lineHeight = null,
598
        $textAlign = null
599
    ) {
600 1
        $this->setAttributes(
601 1
            $this->recipientLeftAttr,
602 1
            $posX,
603 1
            $posY,
604 1
            $width,
605 1
            $height,
606 1
            $background,
607 1
            $fontFamily,
608 1
            $fontSize,
609 1
            $fontColor,
610 1
            $lineHeight,
611 1
            $textAlign
612
        );
613
614 1
        return $this;
615
    }
616
617
    /**
618
     * Set the right recipient attributes
619
     *
620
     * @param float|null $posX The X position.
621
     * @param float|null $posY The Y Position.
622
     * @param float|null $width The width.
623
     * @param float|null $height The height.
624
     * @param string|null $background The background.
625
     * @param string|null $fontFamily The font family.
626
     * @param float|null $fontSize The font size.
627
     * @param string|null $fontColor The font color.
628
     * @param float|null $lineHeight The line height.
629
     * @param string|null $textAlign The text alignment.
630
     * @return $this The current instance for a fluent interface.
631
     */
632 1
    public function setRecipientRightAttr(
633
        $posX = null,
634
        $posY = null,
635
        $width = null,
636
        $height = null,
637
        $background = null,
638
        $fontFamily = null,
639
        $fontSize = null,
640
        $fontColor = null,
641
        $lineHeight = null,
642
        $textAlign = null
643
    ) {
644 1
        $this->setAttributes(
645 1
            $this->recipientRightAttr,
646 1
            $posX,
647 1
            $posY,
648 1
            $width,
649 1
            $height,
650 1
            $background,
651 1
            $fontFamily,
652 1
            $fontSize,
653 1
            $fontColor,
654 1
            $lineHeight,
655 1
            $textAlign
656
        );
657
658 1
        return $this;
659
    }
660
661
    /**
662
     * Set the left account attributes
663
     *
664
     * @param float|null $posX The X position.
665
     * @param float|null $posY The Y Position.
666
     * @param float|null $width The width.
667
     * @param float|null $height The height.
668
     * @param string|null $background The background.
669
     * @param string|null $fontFamily The font family.
670
     * @param float|null $fontSize The font size.
671
     * @param string|null $fontColor The font color.
672
     * @param float|null $lineHeight The line height.
673
     * @param string|null $textAlign The text alignment.
674
     * @return $this The current instance for a fluent interface.
675
     */
676 1
    public function setAccountLeftAttr(
677
        $posX = null,
678
        $posY = null,
679
        $width = null,
680
        $height = null,
681
        $background = null,
682
        $fontFamily = null,
683
        $fontSize = null,
684
        $fontColor = null,
685
        $lineHeight = null,
686
        $textAlign = null
687
    ) {
688 1
        $this->setAttributes(
689 1
            $this->accountLeftAttr,
690 1
            $posX,
691 1
            $posY,
692 1
            $width,
693 1
            $height,
694 1
            $background,
695 1
            $fontFamily,
696 1
            $fontSize,
697 1
            $fontColor,
698 1
            $lineHeight,
699 1
            $textAlign
700
        );
701
702 1
        return $this;
703
    }
704
705
    /**
706
     * Set the right account attributes
707
     *
708
     * @param float|null $posX The X position.
709
     * @param float|null $posY The Y Position.
710
     * @param float|null $width The width.
711
     * @param float|null $height The height.
712
     * @param string|null $background The background.
713
     * @param string|null $fontFamily The font family.
714
     * @param float|null $fontSize The font size.
715
     * @param string|null $fontColor The font color.
716
     * @param float|null $lineHeight The line height.
717
     * @param string|null $textAlign The text alignment.
718
     * @return $this The current instance for a fluent interface.
719
     */
720 1
    public function setAccountRightAttr(
721
        $posX = null,
722
        $posY = null,
723
        $width = null,
724
        $height = null,
725
        $background = null,
726
        $fontFamily = null,
727
        $fontSize = null,
728
        $fontColor = null,
729
        $lineHeight = null,
730
        $textAlign = null
731
    ) {
732 1
        $this->setAttributes(
733 1
            $this->accountRightAttr,
734 1
            $posX,
735 1
            $posY,
736 1
            $width,
737 1
            $height,
738 1
            $background,
739 1
            $fontFamily,
740 1
            $fontSize,
741 1
            $fontColor,
742 1
            $lineHeight,
743 1
            $textAlign
744
        );
745
746 1
        return $this;
747
    }
748
749
    /**
750
     * Set the left francs amount attributes
751
     *
752
     * @param float|null $posX The X position.
753
     * @param float|null $posY The Y Position.
754
     * @param float|null $width The width.
755
     * @param float|null $height The height.
756
     * @param string|null $background The background.
757
     * @param string|null $fontFamily The font family.
758
     * @param float|null $fontSize The font size.
759
     * @param string|null $fontColor The font color.
760
     * @param float|null $lineHeight The line height.
761
     * @param string|null $textAlign The text alignment.
762
     * @return $this The current instance for a fluent interface.
763
     */
764 1
    public function setAmountFrancsLeftAttr(
765
        $posX = null,
766
        $posY = null,
767
        $width = null,
768
        $height = null,
769
        $background = null,
770
        $fontFamily = null,
771
        $fontSize = null,
772
        $fontColor = null,
773
        $lineHeight = null,
774
        $textAlign = null
775
    ) {
776 1
        if ($textAlign === null) {
777 1
            $textAlign = 'R';
778
        }
779
780 1
        $this->setAttributes(
781 1
            $this->amountFrancsLeftAttr,
782 1
            $posX,
783 1
            $posY,
784 1
            $width,
785 1
            $height,
786 1
            $background,
787 1
            $fontFamily,
788 1
            $fontSize,
789 1
            $fontColor,
790 1
            $lineHeight,
791 1
            $textAlign
792
        );
793
794 1
        return $this;
795
    }
796
797
    /**
798
     * Set the right francs amount attributes
799
     *
800
     * @param float|null $posX The X position.
801
     * @param float|null $posY The Y Position.
802
     * @param float|null $width The width.
803
     * @param float|null $height The height.
804
     * @param string|null $background The background.
805
     * @param string|null $fontFamily The font family.
806
     * @param float|null $fontSize The font size.
807
     * @param string|null $fontColor The font color.
808
     * @param float|null $lineHeight The line height.
809
     * @param string|null $textAlign The text alignment.
810
     * @return $this The current instance for a fluent interface.
811
     */
812 1
    public function setAmountFrancsRightAttr(
813
        $posX = null,
814
        $posY = null,
815
        $width = null,
816
        $height = null,
817
        $background = null,
818
        $fontFamily = null,
819
        $fontSize = null,
820
        $fontColor = null,
821
        $lineHeight = null,
822
        $textAlign = null
823
    ) {
824 1
        if ($textAlign === null) {
825 1
            $textAlign = 'R';
826
        }
827
828 1
        $this->setAttributes(
829 1
            $this->amountFrancsRightAttr,
830 1
            $posX,
831 1
            $posY,
832 1
            $width,
833 1
            $height,
834 1
            $background,
835 1
            $fontFamily,
836 1
            $fontSize,
837 1
            $fontColor,
838 1
            $lineHeight,
839 1
            $textAlign
840
        );
841
842 1
        return $this;
843
    }
844
845
    /**
846
     * Set the left cents amount attributes
847
     *
848
     * @param float|null $posX The X position.
849
     * @param float|null $posY The Y Position.
850
     * @param float|null $width The width.
851
     * @param float|null $height The height.
852
     * @param string|null $background The background.
853
     * @param string|null $fontFamily The font family.
854
     * @param float|null $fontSize The font size.
855
     * @param string|null $fontColor The font color.
856
     * @param float|null $lineHeight The line height.
857
     * @param string|null $textAlign The text alignment.
858
     * @return $this The current instance for a fluent interface.
859
     */
860 1
    public function setAmountCentsLeftAttr(
861
        $posX = null,
862
        $posY = null,
863
        $width = null,
864
        $height = null,
865
        $background = null,
866
        $fontFamily = null,
867
        $fontSize = null,
868
        $fontColor = null,
869
        $lineHeight = null,
870
        $textAlign = null
871
    ) {
872 1
        $this->setAttributes(
873 1
            $this->amountCentsLeftAttr,
874 1
            $posX,
875 1
            $posY,
876 1
            $width,
877 1
            $height,
878 1
            $background,
879 1
            $fontFamily,
880 1
            $fontSize,
881 1
            $fontColor,
882 1
            $lineHeight,
883 1
            $textAlign
884
        );
885
886 1
        return $this;
887
    }
888
889
    /**
890
     * Set the right cents amount attributes
891
     *
892
     * @param float|null $posX The X position.
893
     * @param float|null $posY The Y Position.
894
     * @param float|null $width The width.
895
     * @param float|null $height The height.
896
     * @param string|null $background The background.
897
     * @param string|null $fontFamily The font family.
898
     * @param float|null $fontSize The font size.
899
     * @param string|null $fontColor The font color.
900
     * @param float|null $lineHeight The line height.
901
     * @param string|null $textAlign The text alignment.
902
     * @return $this The current instance for a fluent interface.
903
     */
904 1
    public function setAmountCentsRightAttr(
905
        $posX = null,
906
        $posY = null,
907
        $width = null,
908
        $height = null,
909
        $background = null,
910
        $fontFamily = null,
911
        $fontSize = null,
912
        $fontColor = null,
913
        $lineHeight = null,
914
        $textAlign = null
915
    ) {
916 1
        $this->setAttributes(
917 1
            $this->amountCentsRightAttr,
918 1
            $posX,
919 1
            $posY,
920 1
            $width,
921 1
            $height,
922 1
            $background,
923 1
            $fontFamily,
924 1
            $fontSize,
925 1
            $fontColor,
926 1
            $lineHeight,
927 1
            $textAlign
928
        );
929
930 1
        return $this;
931
    }
932
933
    /**
934
     * Set the left payer attributes
935
     *
936
     * @param float|null $posX The X position.
937
     * @param float|null $posY The Y Position.
938
     * @param float|null $width The width.
939
     * @param float|null $height The height.
940
     * @param string|null $background The background.
941
     * @param string|null $fontFamily The font family.
942
     * @param float|null $fontSize The font size.
943
     * @param string|null $fontColor The font color.
944
     * @param float|null $lineHeight The line height.
945
     * @param string|null $textAlign The text alignment.
946
     * @return $this The current instance for a fluent interface.
947
     */
948 1
    public function setPayerLeftAttr(
949
        $posX = null,
950
        $posY = null,
951
        $width = null,
952
        $height = null,
953
        $background = null,
954
        $fontFamily = null,
955
        $fontSize = null,
956
        $fontColor = null,
957
        $lineHeight = null,
958
        $textAlign = null
959
    ) {
960 1
        $this->setAttributes(
961 1
            $this->payerLeftAttr,
962 1
            $posX,
963 1
            $posY,
964 1
            $width,
965 1
            $height,
966 1
            $background,
967 1
            $fontFamily,
968 1
            $fontSize,
969 1
            $fontColor,
970 1
            $lineHeight,
971 1
            $textAlign
972
        );
973
974 1
        return $this;
975
    }
976
977
    /**
978
     * Set the right payer attributes
979
     *
980
     * @param float|null $posX The X position.
981
     * @param float|null $posY The Y Position.
982
     * @param float|null $width The width.
983
     * @param float|null $height The height.
984
     * @param string|null $background The background.
985
     * @param string|null $fontFamily The font family.
986
     * @param float|null $fontSize The font size.
987
     * @param string|null $fontColor The font color.
988
     * @param float|null $lineHeight The line height.
989
     * @param string|null $textAlign The text alignment.
990
     * @return $this The current instance for a fluent interface.
991
     */
992 1
    public function setPayerRightAttr(
993
        $posX = null,
994
        $posY = null,
995
        $width = null,
996
        $height = null,
997
        $background = null,
998
        $fontFamily = null,
999
        $fontSize = null,
1000
        $fontColor = null,
1001
        $lineHeight = null,
1002
        $textAlign = null
1003
    ) {
1004 1
        $this->setAttributes(
1005 1
            $this->payerRightAttr,
1006 1
            $posX,
1007 1
            $posY,
1008 1
            $width,
1009 1
            $height,
1010 1
            $background,
1011 1
            $fontFamily,
1012 1
            $fontSize,
1013 1
            $fontColor,
1014 1
            $lineHeight,
1015 1
            $textAlign
1016
        );
1017
1018 1
        return $this;
1019
    }
1020
1021
    /**
1022
     * Get the attributes of the left account element
1023
     *
1024
     * @return array The attributes of the left account element.
1025
     */
1026 1
    public function getAccountLeftAttr()
1027
    {
1028 1
        return $this->accountLeftAttr;
1029
    }
1030
1031
    /**
1032
     * Get the attributes of the right account element
1033
     *
1034
     * @return array The attributes of the right account element.
1035
     */
1036 1
    public function getAccountRightAttr()
1037
    {
1038 1
        return $this->accountRightAttr;
1039
    }
1040
1041
    /**
1042
     * Get the attributes of the right cents amount element
1043
     *
1044
     * @return array The attributes of the right cents amount element.
1045
     */
1046 1
    public function getAmountCentsRightAttr()
1047
    {
1048 1
        return $this->amountCentsRightAttr;
1049
    }
1050
1051
    /**
1052
     * Get the attributes of the left cents amount element
1053
     *
1054
     * @return array The attributes of the left cents amount element.
1055
     */
1056 1
    public function getAmountCentsLeftAttr()
1057
    {
1058 1
        return $this->amountCentsLeftAttr;
1059
    }
1060
1061
    /**
1062
     * Get the attributes of the left francs amount element
1063
     *
1064
     * @return array The attributes of the left francs amount element.
1065
     */
1066 1
    public function getAmountFrancsLeftAttr()
1067
    {
1068 1
        return $this->amountFrancsLeftAttr;
1069
    }
1070
1071
    /**
1072
     * Get the attributes of the right francs amount element
1073
     *
1074
     * @return array The attributes of the right francs amount element.
1075
     */
1076 1
    public function getAmountFrancsRightAttr()
1077
    {
1078 1
        return $this->amountFrancsRightAttr;
1079
    }
1080
1081
    /**
1082
     * Get the attributes of the left bank element
1083
     *
1084
     * @return array The attributes of the left bank element.
1085
     */
1086 1
    public function getBankLeftAttr()
1087
    {
1088 1
        return $this->bankLeftAttr;
1089
    }
1090
1091
    /**
1092
     * Get the attributes of the right bank element
1093
     *
1094
     * @return array The attributes of the right bank element.
1095
     */
1096 1
    public function getBankRightAttr()
1097
    {
1098 1
        return $this->bankRightAttr;
1099
    }
1100
1101
    /**
1102
     * Get the attributes of the right recipient element
1103
     *
1104
     * @return array The attributes of the right recipient element.
1105
     */
1106 1
    public function getRecipientRightAttr()
1107
    {
1108 1
        return $this->recipientRightAttr;
1109
    }
1110
1111
    /**
1112
     * Get the attributes of the left recipient element
1113
     *
1114
     * @return array The attributes of the left recipient element.
1115
     */
1116 1
    public function getRecipientLeftAttr()
1117
    {
1118 1
        return $this->recipientLeftAttr;
1119
    }
1120
1121
    /**
1122
     * Get the attributes of the right payer element
1123
     *
1124
     * @return array The attributes of the right payer element.
1125
     */
1126 1
    public function getPayerRightAttr()
1127
    {
1128 1
        return $this->payerRightAttr;
1129
    }
1130
1131
    /**
1132
     * Get the attributes of the left payer element
1133
     *
1134
     * @return array The attributes of the left payer element.
1135
     */
1136 1
    public function getPayerLeftAttr()
1137
    {
1138 1
        return $this->payerLeftAttr;
1139
    }
1140
1141
    /**
1142
     * Get the background of the slip
1143
     *
1144
     * Can be either 'transparent', a color or an image
1145
     *
1146
     * @return null|string The slip background.
1147
     */
1148 1
    public function getSlipBackground()
1149
    {
1150 1
        return $this->slipBackground;
1151
    }
1152
1153
    /**
1154
     * Get the starting X position of the slip
1155
     *
1156
     * @return int|float The starting X position of the slip.
1157
     */
1158 1
    public function getSlipPosX()
1159
    {
1160 1
        return $this->slipPosX;
1161
    }
1162
1163
    /**
1164
     * Get the starting Y position of the slip
1165
     *
1166
     * @return int|float The starting Y position of the slip.
1167
     */
1168 1
    public function getSlipPosY()
1169
    {
1170 1
        return $this->slipPosY;
1171
    }
1172
1173
    /**
1174
     * Get the width of the slip
1175
     *
1176
     * @return int|float The width of the slip.
1177
     */
1178 1
    public function getSlipWidth()
1179
    {
1180 1
        return $this->slipWidth;
1181
    }
1182
1183
    /**
1184
     * Get the height of the slip
1185
     *
1186
     * @return int|float The height of the slip.
1187
     */
1188 1
    public function getSlipHeight()
1189
    {
1190 1
        return $this->slipHeight;
1191
    }
1192
1193
    /**
1194
     * Set whether or not to display the background
1195
     *
1196
     * @param bool $displayBackground True if yes, false if no.
1197
     * @return $this The current instance for a fluent interface..
1198
     */
1199 2
    public function setDisplayBackground($displayBackground = true)
1200
    {
1201 2
        $this->isBool($displayBackground, 'displayBackground');
1202 1
        $this->displayBackground = $displayBackground;
1203
1204 1
        return $this;
1205
    }
1206
1207
    /**
1208
     * Get whether or not to display the background
1209
     *
1210
     * @return bool True if yes, false if no.
1211
     */
1212 1
    public function getDisplayBackground()
1213
    {
1214 1
        return $this->displayBackground;
1215
    }
1216
1217
    /**
1218
     * Set whether or not to display the account
1219
     *
1220
     * @param bool $displayAccount True if yes, false if no.
1221
     * @return $this The current instance for a fluent interface..
1222
     */
1223 2
    public function setDisplayAccount($displayAccount = true)
1224
    {
1225 2
        $this->isBool($displayAccount, 'displayAccount');
1226 1
        $this->displayAccount = $displayAccount;
1227
1228 1
        return $this;
1229
    }
1230
1231
    /**
1232
     * Get whether or not to display the account
1233
     *
1234
     * @return bool True if yes, false if no.
1235
     */
1236 1
    public function getDisplayAccount()
1237
    {
1238 1
        if ($this->getPaymentSlipData()->getWithAccountNumber() !== true) {
1239 1
            return false;
1240
        }
1241 1
        return $this->displayAccount;
1242
    }
1243
1244
    /**
1245
     * Set whether or not to display the amount
1246
     *
1247
     * @param bool $displayAmount True if yes, false if no
1248
     * @return $this The current instance for a fluent interface.
1249
     */
1250 2
    public function setDisplayAmount($displayAmount = true)
1251
    {
1252 2
        $this->isBool($displayAmount, 'displayAmount');
1253 1
        $this->displayAmount = $displayAmount;
1254
1255 1
        return $this;
1256
    }
1257
1258
    /**
1259
     * Get whether or not to display the amount
1260
     *
1261
     * @return bool True if yes, false if no.
1262
     */
1263 1
    public function getDisplayAmount()
1264
    {
1265 1
        if ($this->getPaymentSlipData()->getWithAmount() !== true) {
1266 1
            return false;
1267
        }
1268 1
        return $this->displayAmount;
1269
    }
1270
1271
    /**
1272
     * Set whether or not to display the bank
1273
     *
1274
     * @param bool $displayBank True if yes, false if no
1275
     * @return $this The current instance for a fluent interface.
1276
     */
1277 2
    public function setDisplayBank($displayBank = true)
1278
    {
1279 2
        $this->isBool($displayBank, 'displayBank');
1280 1
        $this->displayBank = $displayBank;
1281
1282 1
        return $this;
1283
    }
1284
1285
    /**
1286
     * Get whether or not to display the bank
1287
     *
1288
     * @return bool True if yes, false if no.
1289
     */
1290 1
    public function getDisplayBank()
1291
    {
1292 1
        if ($this->getPaymentSlipData()->getWithBank() !== true) {
1293 1
            return false;
1294
        }
1295 1
        return $this->displayBank;
1296
    }
1297
1298
    /**
1299
     * Set whether or not to display the payer
1300
     *
1301
     * @param bool $displayPayer True if yes, false if no
1302
     * @return $this The current instance for a fluent interface.
1303
     */
1304 2
    public function setDisplayPayer($displayPayer = true)
1305
    {
1306 2
        $this->isBool($displayPayer, 'displayPayer');
1307 1
        $this->displayPayer = $displayPayer;
1308
1309 1
        return $this;
1310
    }
1311
1312
    /**
1313
     * Get whether or not to display the payer
1314
     *
1315
     * @return bool True if yes, false if no.
1316
     */
1317 1
    public function getDisplayPayer()
1318
    {
1319 1
        if ($this->getPaymentSlipData()->getWithPayer() !== true) {
1320 1
            return false;
1321
        }
1322 1
        return $this->displayPayer;
1323
    }
1324
1325
    /**
1326
     * Set whether or not to display the recipient
1327
     *
1328
     * @param bool $displayRecipient True if yes, false if no
1329
     * @return $this The current instance for a fluent interface.
1330
     */
1331 2
    public function setDisplayRecipient($displayRecipient = true)
1332
    {
1333 2
        $this->isBool($displayRecipient, 'displayRecipient');
1334 1
        $this->displayRecipient = $displayRecipient;
1335
1336 1
        return $this;
1337
    }
1338
1339
    /**
1340
     * Get whether or not to display the recipient
1341
     *
1342
     * @return bool True if yes, false if no.
1343
     */
1344 1
    public function getDisplayRecipient()
1345
    {
1346 1
        if ($this->getPaymentSlipData()->getWithRecipient() !== true) {
1347 1
            return false;
1348
        }
1349 1
        return $this->displayRecipient;
1350
    }
1351
1352
    /**
1353
     * Get all elements of the slip
1354
     *
1355
     * @return array All elements with their lines and attributes.
1356
     */
1357 3
    public function getAllElements()
1358
    {
1359 3
        $paymentSlipData = $this->paymentSlipData;
1360
1361 3
        $elements = [];
1362
        // Place left bank lines
1363 3
        if ($this->getDisplayBank()) {
1364
            $lines = [
1365 1
                $paymentSlipData->getBankName(),
1366 1
                $paymentSlipData->getBankCity()
1367
            ];
1368 1
            $elements['bankLeft'] = [
1369 1
                'lines' => $lines,
1370 1
                'attributes' => $this->getBankLeftAttr()
1371
            ];
1372
1373
            // Place right bank lines
1374
            // Reuse lines from above
1375 1
            $elements['bankRight'] = [
1376 1
                'lines' => $lines,
1377 1
                'attributes' => $this->getBankRightAttr()
1378
            ];
1379
        }
1380
1381
        // Place left recipient lines
1382 3
        if ($this->getDisplayRecipient()) {
1383
            $lines = [
1384 1
                $paymentSlipData->getRecipientLine1(),
1385 1
                $paymentSlipData->getRecipientLine2(),
1386 1
                $paymentSlipData->getRecipientLine3(),
1387 1
                $paymentSlipData->getRecipientLine4()
1388
            ];
1389 1
            $elements['recipientLeft'] = [
1390 1
                'lines' => $lines,
1391 1
                'attributes' => $this->getRecipientLeftAttr()
1392
            ];
1393
1394
            // Place right recipient lines
1395
            // Reuse lines from above
1396 1
            $elements['recipientRight'] = [
1397 1
                'lines' => $lines,
1398 1
                'attributes' => $this->getRecipientRightAttr()
1399
            ];
1400
        }
1401
1402
        // Place left account number
1403 3
        if ($this->getDisplayAccount()) {
1404 1
            $lines = [$paymentSlipData->getAccountNumber()];
1405 1
            $elements['accountLeft'] = [
1406 1
                'lines' => $lines,
1407 1
                'attributes' => $this->getAccountLeftAttr()
1408
            ];
1409
1410
            // Place right account number
1411
            // Reuse lines from above
1412 1
            $elements['accountRight'] = [
1413 1
                'lines' => $lines,
1414 1
                'attributes' => $this->getAccountRightAttr()
1415
            ];
1416
        }
1417
1418
        // Place left amount in francs
1419 3
        if ($this->getDisplayAmount()) {
1420 1
            $lines = [$paymentSlipData->getAmountFrancs()];
1421 1
            $elements['amountFrancsLeft'] = [
1422 1
                'lines' => $lines,
1423 1
                'attributes' => $this->getAmountFrancsLeftAttr()
1424
            ];
1425
1426
            // Place right amount in francs
1427
            // Reuse lines from above
1428 1
            $elements['amountFrancsRight'] = [
1429 1
                'lines' => $lines,
1430 1
                'attributes' => $this->getAmountFrancsRightAttr()
1431
            ];
1432
1433
            // Place left amount in cents
1434 1
            $lines = [$paymentSlipData->getAmountCents()];
1435 1
            $elements['amountCentsLeft'] = [
1436 1
                'lines' => $lines,
1437 1
                'attributes' => $this->getAmountCentsLeftAttr()
1438
            ];
1439
1440
            // Place right amount in cents
1441
            // Reuse lines from above
1442 1
            $elements['amountCentsRight'] = [
1443 1
                'lines' => $lines,
1444 1
                'attributes' => $this->getAmountCentsRightAttr()
1445
            ];
1446
        }
1447
1448
        // Place left payer lines
1449 3
        if ($this->getDisplayPayer()) {
1450
            $lines = [
1451 1
                $paymentSlipData->getPayerLine1(),
1452 1
                $paymentSlipData->getPayerLine2(),
1453 1
                $paymentSlipData->getPayerLine3(),
1454 1
                $paymentSlipData->getPayerLine4()
1455
            ];
1456 1
            $elements['payerLeft'] = [
1457 1
                'lines' => $lines,
1458 1
                'attributes' => $this->getPayerLeftAttr()
1459
            ];
1460
1461
            // Place right payer lines
1462
            // Reuse lines from above
1463 1
            $elements['payerRight'] = [
1464 1
                'lines' => $lines,
1465 1
                'attributes' => $this->getPayerRightAttr()
1466
            ];
1467
        }
1468
1469 3
        return $elements;
1470
    }
1471
1472
    /**
1473
     * Verify that a given parameter is an integer or a float
1474
     *
1475
     * @param mixed $parameter The given parameter to validate.
1476
     * @param string $varName The name of the variable.
1477
     * @return true If the parameter is either  an integer or a float.
1478
     * @throws InvalidArgumentException If the parameter is neither an integer nor a float.
1479
     */
1480 4
    protected function isIntOrFloat($parameter, $varName)
1481
    {
1482 4
        if ((!is_int($parameter) && !is_float($parameter))) {
1483 4
            throw new InvalidArgumentException(
1484 4
                sprintf(
1485 4
                    '$%s is neither an integer nor a float.',
1486 4
                    $varName
1487
                )
1488
            );
1489
        }
1490 2
    }
1491
1492
    /**
1493
     * Verify that a given parameter is boolean
1494
     *
1495
     * @param mixed $parameter The given parameter to validate.
1496
     * @param string $varName The name of the variable.
1497
     * @return true If the parameter is a boolean.
1498
     * @throws InvalidArgumentException If the parameter is not a boolean.
1499
     */
1500 20
    protected function isBool($parameter, $varName)
1501
    {
1502 20
        if (!is_bool($parameter)) {
1503 10
            throw new InvalidArgumentException(
1504 10
                sprintf(
1505 10
                    '$%s is not a boolean.',
1506 10
                    $varName
1507
                )
1508
            );
1509
        }
1510 10
        return true;
1511
    }
1512
}
1513