Skip to content

Commit b11f590

Browse files
committed
Added PHPStan Check
1 parent 70ab3ee commit b11f590

24 files changed

+262
-190
lines changed

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
"phpunit/phpunit": "^4.8.36 || ^7.0",
2323
"phpdocumentor/phpdocumentor":"2.*",
2424
"phpmd/phpmd": "2.*",
25-
"sebastian/phpcpd": "2.*",
26-
"phploc/phploc": "2.*",
27-
"squizlabs/php_codesniffer": "2.*"
25+
"phpstan/phpstan": "^0.12.88"
2826
},
2927
"autoload": {
3028
"psr-4": {

phpstan.neon.dist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
parameters:
2+
level: 6
3+
bootstrapFiles:
4+
- tests/bootstrap.php
5+
paths:
6+
- src
7+
- tests
8+
reportUnmatchedIgnoredErrors: false
9+
ignoreErrors:
10+
11+
## Remove after remove ArrayObject
12+
treatPhpDocTypesAsCertain: false

src/Common/Autoloader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Autoloader
3030
*
3131
* @return void
3232
*/
33-
public static function register()
33+
public static function register(): void
3434
{
3535
spl_autoload_register([new self(), 'autoload']);
3636
}
@@ -40,7 +40,7 @@ public static function register()
4040
*
4141
* @param string $class
4242
*/
43-
public static function autoload($class)
43+
public static function autoload(string $class): void
4444
{
4545
$prefixLength = strlen(self::NAMESPACE_PREFIX);
4646
if (0 === strncmp(self::NAMESPACE_PREFIX, $class, $prefixLength)) {

src/Common/Drawing.php

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
namespace PhpOffice\Common;
1919

20-
/**
21-
* \PhpOffice\Common\Drawing
22-
*/
2320
class Drawing
2421
{
2522
public const DPI_96 = 96;
@@ -29,9 +26,9 @@ class Drawing
2926
*
3027
* @param int $pValue Value in pixels
3128
*
32-
* @return int
29+
* @return float
3330
*/
34-
public static function pixelsToEmu($pValue = 0)
31+
public static function pixelsToEmu(int $pValue = 0): float
3532
{
3633
return round($pValue * 9525);
3734
}
@@ -41,9 +38,9 @@ public static function pixelsToEmu($pValue = 0)
4138
*
4239
* @param int $pValue Value in EMU
4340
*
44-
* @return int
41+
* @return float
4542
*/
46-
public static function emuToPixels($pValue = 0)
43+
public static function emuToPixels(int $pValue = 0): float
4744
{
4845
if ($pValue == 0) {
4946
return 0;
@@ -59,7 +56,7 @@ public static function emuToPixels($pValue = 0)
5956
*
6057
* @return float
6158
*/
62-
public static function pixelsToPoints($pValue = 0)
59+
public static function pixelsToPoints(int $pValue = 0): float
6360
{
6461
return $pValue * 0.67777777;
6562
}
@@ -71,7 +68,7 @@ public static function pixelsToPoints($pValue = 0)
7168
*
7269
* @return float
7370
*/
74-
public static function pointsToCentimeters($pValue = 0)
71+
public static function pointsToCentimeters(int $pValue = 0): float
7572
{
7673
if ($pValue == 0) {
7774
return 0;
@@ -87,7 +84,7 @@ public static function pointsToCentimeters($pValue = 0)
8784
*
8885
* @return float
8986
*/
90-
public static function pointsToPixels($pValue = 0)
87+
public static function pointsToPixels(int $pValue = 0): float
9188
{
9289
if ($pValue == 0) {
9390
return 0;
@@ -103,7 +100,7 @@ public static function pointsToPixels($pValue = 0)
103100
*
104101
* @return float
105102
*/
106-
public static function pixelsToCentimeters($pValue = 0)
103+
public static function pixelsToCentimeters(int $pValue = 0): float
107104
{
108105
//return $pValue * 0.028;
109106
return ($pValue / self::DPI_96) * 2.54;
@@ -116,7 +113,7 @@ public static function pixelsToCentimeters($pValue = 0)
116113
*
117114
* @return float
118115
*/
119-
public static function centimetersToPixels($pValue = 0)
116+
public static function centimetersToPixels(int $pValue = 0): float
120117
{
121118
if ($pValue == 0) {
122119
return 0;
@@ -132,7 +129,7 @@ public static function centimetersToPixels($pValue = 0)
132129
*
133130
* @return int
134131
*/
135-
public static function degreesToAngle($pValue = 0)
132+
public static function degreesToAngle(int $pValue = 0): int
136133
{
137134
return (int) round($pValue * 60000);
138135
}
@@ -142,9 +139,9 @@ public static function degreesToAngle($pValue = 0)
142139
*
143140
* @param int $pValue Angle
144141
*
145-
* @return int
142+
* @return float
146143
*/
147-
public static function angleToDegrees($pValue = 0)
144+
public static function angleToDegrees(int $pValue = 0): float
148145
{
149146
if ($pValue == 0) {
150147
return 0;
@@ -160,7 +157,7 @@ public static function angleToDegrees($pValue = 0)
160157
*
161158
* @return float
162159
*/
163-
public static function centimetersToTwips($pValue = 0)
160+
public static function centimetersToTwips(int $pValue = 0): float
164161
{
165162
if ($pValue == 0) {
166163
return 0;
@@ -176,7 +173,7 @@ public static function centimetersToTwips($pValue = 0)
176173
*
177174
* @return float
178175
*/
179-
public static function twipsToCentimeters($pValue = 0)
176+
public static function twipsToCentimeters(int $pValue = 0): float
180177
{
181178
if ($pValue == 0) {
182179
return 0;
@@ -190,9 +187,9 @@ public static function twipsToCentimeters($pValue = 0)
190187
*
191188
* @param int $pValue
192189
*
193-
* @return float
190+
* @return int
194191
*/
195-
public static function inchesToTwips($pValue = 0)
192+
public static function inchesToTwips(int $pValue = 0): int
196193
{
197194
if ($pValue == 0) {
198195
return 0;
@@ -208,7 +205,7 @@ public static function inchesToTwips($pValue = 0)
208205
*
209206
* @return float
210207
*/
211-
public static function twipsToInches($pValue = 0)
208+
public static function twipsToInches(int $pValue = 0): float
212209
{
213210
if ($pValue == 0) {
214211
return 0;
@@ -224,7 +221,7 @@ public static function twipsToInches($pValue = 0)
224221
*
225222
* @return float
226223
*/
227-
public static function twipsToPixels($pValue = 0)
224+
public static function twipsToPixels(int $pValue = 0): float
228225
{
229226
if ($pValue == 0) {
230227
return 0;
@@ -238,9 +235,9 @@ public static function twipsToPixels($pValue = 0)
238235
*
239236
* @param string $pValue HTML Color in hexadecimal
240237
*
241-
* @return array|false Value in RGB
238+
* @return array<int, int>|null Value in RGB
242239
*/
243-
public static function htmlToRGB($pValue)
240+
public static function htmlToRGB(string $pValue): ?array
244241
{
245242
if ($pValue[0] == '#') {
246243
$pValue = substr($pValue, 1);
@@ -251,7 +248,7 @@ public static function htmlToRGB($pValue)
251248
} elseif (strlen($pValue) == 3) {
252249
list($colorR, $colorG, $colorB) = [$pValue[0] . $pValue[0], $pValue[1] . $pValue[1], $pValue[2] . $pValue[2]];
253250
} else {
254-
return false;
251+
return null;
255252
}
256253

257254
$colorR = hexdec($colorR);

src/Common/File.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public static function fileExists($pFilename)
5959
*
6060
* @param string $pFilename Filename
6161
*
62-
* @return string
62+
* @return string|null
6363
*/
64-
public static function fileGetContents($pFilename)
64+
public static function fileGetContents(string $pFilename): ?string
6565
{
6666
if (!self::fileExists($pFilename)) {
67-
return false;
67+
return null;
6868
}
6969
if (strtolower(substr($pFilename, 0, 3)) == 'zip') {
7070
// Open ZIP file and verify if the file exists
@@ -79,7 +79,7 @@ public static function fileGetContents($pFilename)
7979
return $returnValue;
8080
}
8181

82-
return false;
82+
return null;
8383
}
8484
// Regular file contents
8585
return file_get_contents($pFilename);
@@ -92,13 +92,13 @@ public static function fileGetContents($pFilename)
9292
*
9393
* @return string
9494
*/
95-
public static function realpath($pFilename)
95+
public static function realpath(string $pFilename): string
9696
{
9797
// Try using realpath()
9898
$returnValue = realpath($pFilename);
9999

100100
// Found something?
101-
if ($returnValue == '' || is_null($returnValue)) {
101+
if (empty($returnValue)) {
102102
$pathArray = explode('/', $pFilename);
103103
while (in_array('..', $pathArray) && $pathArray[0] != '..') {
104104
$numPathArray = count($pathArray);

src/Common/Font.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class Font
2727
*
2828
* @param int $fontSizeInPoints Font size (in points)
2929
*
30-
* @return int Font size (in pixels)
30+
* @return float Font size (in pixels)
3131
*/
32-
public static function fontSizeToPixels($fontSizeInPoints = 12)
32+
public static function fontSizeToPixels(int $fontSizeInPoints = 12): float
3333
{
3434
return (16 / 12) * $fontSizeInPoints;
3535
}
@@ -41,7 +41,7 @@ public static function fontSizeToPixels($fontSizeInPoints = 12)
4141
*
4242
* @return int Size (in pixels)
4343
*/
44-
public static function inchSizeToPixels($sizeInInch = 1)
44+
public static function inchSizeToPixels(int $sizeInInch = 1): int
4545
{
4646
return $sizeInInch * 96;
4747
}
@@ -51,9 +51,9 @@ public static function inchSizeToPixels($sizeInInch = 1)
5151
*
5252
* @param int $sizeInCm Font size (in centimeters)
5353
*
54-
* @return int Size (in pixels)
54+
* @return float Size (in pixels)
5555
*/
56-
public static function centimeterSizeToPixels($sizeInCm = 1)
56+
public static function centimeterSizeToPixels(int $sizeInCm = 1): float
5757
{
5858
return $sizeInCm * 37.795275591;
5959
}
@@ -65,7 +65,7 @@ public static function centimeterSizeToPixels($sizeInCm = 1)
6565
*
6666
* @return float
6767
*/
68-
public static function centimeterSizeToTwips($sizeInCm = 1)
68+
public static function centimeterSizeToTwips(int $sizeInCm = 1): float
6969
{
7070
return $sizeInCm / 2.54 * 1440;
7171
}
@@ -75,9 +75,9 @@ public static function centimeterSizeToTwips($sizeInCm = 1)
7575
*
7676
* @param int $sizeInInch
7777
*
78-
* @return float
78+
* @return int
7979
*/
80-
public static function inchSizeToTwips($sizeInInch = 1)
80+
public static function inchSizeToTwips(int $sizeInInch = 1): int
8181
{
8282
return $sizeInInch * 1440;
8383
}
@@ -89,7 +89,7 @@ public static function inchSizeToTwips($sizeInInch = 1)
8989
*
9090
* @return float
9191
*/
92-
public static function pixelSizeToTwips($sizeInPixel = 1)
92+
public static function pixelSizeToTwips(int $sizeInPixel = 1): float
9393
{
9494
return $sizeInPixel / 96 * 1440;
9595
}
@@ -99,9 +99,9 @@ public static function pixelSizeToTwips($sizeInPixel = 1)
9999
*
100100
* @param int $sizeInPoint Size in point
101101
*
102-
* @return int Size (in twips)
102+
* @return float Size (in twips)
103103
*/
104-
public static function pointSizeToTwips($sizeInPoint = 1)
104+
public static function pointSizeToTwips(int $sizeInPoint = 1): float
105105
{
106106
return $sizeInPoint / 72 * 1440;
107107
}

0 commit comments

Comments
 (0)