These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace ByTIC\DocumentGenerator\PdfLetters\Fields; |
||
4 | |||
5 | use ByTIC\DocumentGenerator\PdfLetters\Fields\Types\AbstractType; |
||
6 | use ByTIC\DocumentGenerator\PdfLetters\PdfLetterTrait; |
||
7 | use Nip\Records\Traits\AbstractTrait\RecordTrait as Record; |
||
8 | use \ByTIC\Models\SmartProperties\RecordsTraits\HasTypes\RecordTrait as HasTypeRecordTrait; |
||
9 | use setasign\Fpdi\Fpdi; |
||
10 | |||
11 | /** |
||
12 | * Class FieldTrait |
||
13 | * @package ByTIC\DocumentGenerator\PdfLetters\Fields |
||
14 | * |
||
15 | * @property string $id_letter |
||
16 | * @property string $field |
||
17 | * @property string $size |
||
18 | * @property string $color |
||
19 | * @property string $align |
||
20 | * @property string $x |
||
21 | * @property string $y |
||
22 | * |
||
23 | * @method FieldsTrait getManager() |
||
24 | * @method AbstractType getType() |
||
25 | */ |
||
26 | trait FieldTrait |
||
27 | { |
||
28 | use HasTypeRecordTrait; |
||
29 | |||
30 | /** |
||
31 | * @return string |
||
32 | */ |
||
33 | public function getName() |
||
34 | { |
||
35 | return translator()->translate($this->field); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @return mixed |
||
40 | */ |
||
41 | public function getTypeValue() |
||
42 | { |
||
43 | return $this->getManager()->getFieldTypeFromMergeTag($this->field); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param PdfLetterTrait $letter |
||
48 | */ |
||
49 | public function populateFromLetter($letter) |
||
50 | { |
||
51 | $this->id_letter = $letter->id; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param Fpdi $pdf |
||
56 | * @param Record $model |
||
57 | */ |
||
58 | public function addToPdf($pdf, $model) |
||
59 | { |
||
60 | $this->getType()->addToPdf($pdf, $model); |
||
0 ignored issues
–
show
|
|||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @param Record $model |
||
65 | * @return string |
||
66 | */ |
||
67 | 1 | public function getValue($model) |
|
68 | { |
||
69 | 1 | if ($model->id > 0) { |
|
70 | $valueType = $this->getType()->getValue($model); |
||
71 | |||
72 | return $valueType; |
||
73 | } |
||
74 | |||
75 | 1 | return '<<'.$this->field.'>>'; |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * @return PdfLetterTrait |
||
80 | */ |
||
81 | abstract public function getPdfLetter(); |
||
82 | |||
83 | /** |
||
84 | * @return bool |
||
85 | */ |
||
86 | public function hasColor() |
||
87 | { |
||
88 | return substr_count($this->color, ',') == 2; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @return array|null |
||
93 | */ |
||
94 | public function getColorArray() |
||
95 | { |
||
96 | if ($this->hasColor()) { |
||
97 | list ($red, $green, $blue) = explode(',', $this->color); |
||
98 | if ($red && $green && $blue) { |
||
99 | return [intval($red), intval($green), intval($blue)]; |
||
100 | } |
||
101 | } |
||
102 | |||
103 | return null; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @param Fpdi $pdf |
||
108 | */ |
||
109 | protected function pdfPrepareFont($pdf) |
||
110 | { |
||
111 | $pdf->SetFont('freesans', '', $this->size, '', true); |
||
0 ignored issues
–
show
The call to
Fpdi::SetFont() has too many arguments starting with '' .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
112 | } |
||
113 | } |
||
114 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.