Issues (13)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/PaymentSlipFpdf.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Swiss Payment Slip FPDF
4
 *
5
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
6
 * @copyright 2012-2015 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/SwissPaymentSlipFpdf
11
 */
12
13
namespace SwissPaymentSlip\SwissPaymentSlipFpdf;
14
15
use SwissPaymentSlip\SwissPaymentSlipPdf\PaymentSlipPdf;
16
use fpdf\FPDF;
17
18
/**
19
 * Create Swiss payment slips (ESR/ES) as PDFs with FPDF
20
 *
21
 * Responsible for generating standard Swiss payment Slips as PDFs using FPDF as engine.
22
 * Layout done by utilizing PaymentSlip and
23
 * data organisation through PaymentSlipData.
24
 *
25
 * @link https://github.com/ravage84/SwissPaymentSlipPdf/ SwissPaymentSlipPdf
26
 * @link https://github.com/ravage84/SwissPaymentSlip/ SwissPaymentSlip
27
 */
28
class PaymentSlipFpdf extends PaymentSlipPdf
29
{
30
    /**
31
     * A caching table for hex to RGB conversions
32
     *
33
     * @var array
34
     */
35
    protected $rgbColors = array();
36
37
    /**
38
     * The PDF engine object to generate the PDF output with
39
     *
40
     * @var null|FPDF The PDF engine object
41
     */
42
    protected $pdfEngine = null;
43
44
    /**
45
     * The last set font family, prevents the PDF engine to re-set the same values over and over
46
     *
47
     * @var string;
48
     */
49
    protected $lastFontFamily = '';
50
51
    /**
52
     * The last set font size, prevents the PDF engine to re-set the same values over and over
53
     *
54
     * @var int|double;
55
     */
56
    protected $lastFontSize = '';
57
58
    /**
59
     * The last set font color, prevents the PDF engine to re-set the same values over and over
60
     *
61
     * @var string;
62
     */
63
    protected $lastFontColor = '';
64
65
    /**
66
     * {@inheritDoc}
67
     */
68
    protected function displayImage($background)
69
    {
70
        // TODO check if slipBackground is a color or a path to a file
71
72
        $this->pdfEngine->Image(
73
            $background,
74
            $this->paymentSlip->getSlipPosX(),
75
            $this->paymentSlip->getSlipPosY(),
76
            $this->paymentSlip->getSlipWidth(),
77
            $this->paymentSlip->getSlipHeight(),
78
            strtoupper(substr($background, -3, 3))
79
        );
80
81
        return $this;
82
    }
83
84
    /**
85
     * {@inheritDoc}
86
     */
87
    protected function setFont($fontFamily, $fontSize, $fontColor)
88
    {
89
        if ($fontColor) {
90
            if ($this->lastFontColor != $fontColor) {
91
                $this->lastFontColor = $fontColor;
92
93
                $rgbArray = $this->convertColor2Rgb($fontColor);
94
                $this->pdfEngine->SetTextColor($rgbArray['red'], $rgbArray['green'], $rgbArray['blue']);
95
            }
96
        }
97
        if ($this->lastFontFamily != $fontFamily || $this->lastFontSize != $fontSize) {
98
            $this->lastFontFamily = $fontFamily;
99
            $this->lastFontSize = $fontSize;
0 ignored issues
show
Documentation Bug introduced by
It seems like $fontSize of type integer or double is incompatible with the declared type string of property $lastFontSize.

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...
100
101
            $this->pdfEngine->SetFont($fontFamily, '', $fontSize);
102
        }
103
104
        return $this;
105
    }
106
107
    /**
108
     * {@inheritDoc}
109
     */
110
    protected function setBackground($background)
111
    {
112
        // TODO check if it's a path to a file
113
        // TODO else it should be a color
114
        $rgbArray = $this->convertColor2Rgb($background);
115
        $this->pdfEngine->SetFillColor($rgbArray['red'], $rgbArray['green'], $rgbArray['blue']);
116
117
        return $this;
118
    }
119
120
    /**
121
     * {@inheritDoc}
122
     */
123
    protected function setPosition($posX, $posY)
124
    {
125
        $this->pdfEngine->SetXY($posX, $posY);
126
127
        return $this;
128
    }
129
130
    /**
131
     * {@inheritDoc}
132
     */
133
    protected function createCell($width, $height, $line, $textAlign, $fill)
134
    {
135
        $this->pdfEngine->Cell($width, $height, $line, 0, 0, $textAlign, $fill);
136
137
        return $this;
138
    }
139
140
    /**
141
     * {@inheritDoc}
142
     */
143
    protected function convertColor2Rgb($color)
144
    {
145
        if (isset($this->rgbColors[$color])) {
146
            return $this->rgbColors[$color];
147
        }
148
        $this->rgbColors[$color] = $this->hex2RGB($color);
149
        return $this->rgbColors[$color];
150
    }
151
152
    /**
153
     * Convert hexadecimal color code into an associative array or string of RGB values
154
     *
155
     * @param string $hexStr The hexadecimal color code (3 or 6 characters long)
156
     * @param bool $returnAsString Whether to return as a string or array.
157
     * @param string $separator The separator for the RGB value string, defaults to ",".
158
     * @return array|string|false The RGB values as an associative array or a string.
159
     * False if an invalid color code was given.
160
     *
161
     * @copyright 2010 hafees at msn dot com
162
     * @link http://www.php.net/manual/en/function.hexdec.php#99478
163
     * @todo Throw an exception if an invalid hex color code was given
164
     */
165
    protected function hex2RGB($hexStr, $returnAsString = false, $separator = ',')
166
    {
167
        $hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // Gets a proper hex string
168
        $rgbArray = array();
169
        if (strlen($hexStr) == 6) {
170
            // If a proper hex code, convert using bitwise operation. No overhead... faster
171
            $colorVal = hexdec($hexStr);
172
            $rgbArray['red'] = 0xFF & ($colorVal >> 0x10);
173
            $rgbArray['green'] = 0xFF & ($colorVal >> 0x8);
174
            $rgbArray['blue'] = 0xFF & $colorVal;
175
        } elseif (strlen($hexStr) == 3) {
176
            // If shorthand notation, need some string manipulations
177
            $rgbArray['red'] = hexdec(str_repeat(substr($hexStr, 0, 1), 2));
178
            $rgbArray['green'] = hexdec(str_repeat(substr($hexStr, 1, 1), 2));
179
            $rgbArray['blue'] = hexdec(str_repeat(substr($hexStr, 2, 1), 2));
180
        } else {
181
            return false; //Invalid hex color code
182
        }
183
184
        // Returns the RGB values either as string or as associative array
185
        return $returnAsString ? implode($separator, $rgbArray) : $rgbArray;
186
    }
187
}
188