Skip to content

Commit acd6dd1

Browse files
authored
Merge pull request #2 from mesour/mn-funding
Added FUNDING.yml
2 parents dd38329 + 2f25705 commit acd6dd1

File tree

10 files changed

+76
-47
lines changed

10 files changed

+76
-47
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: mesour

.travis.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
language: php
22

33
php:
4-
- 7.0
54
- 7.1
6-
- hhvm
5+
- 7.2
6+
- 7.3
7+
- 7.4
8+
- 8.0
79

810
matrix:
911
allow_failures:
10-
- php: hhvm
12+
- php: 8.0
1113

1214
install:
1315
- composer install --no-interaction --prefer-source

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
"homepage": "http://mesour.com"
99
}],
1010
"require": {
11-
"php": ">=7.0"
11+
"php": ">=7.1"
1212
},
1313
"require-dev": {
1414
"tracy/tracy": "~2.3.0",
15-
"slevomat/coding-standard": "^1.0",
16-
"consistence/coding-standard": "^0.10",
17-
"phpstan/phpstan": "^0.7.0",
15+
"slevomat/coding-standard": "^6.4",
16+
"consistence/coding-standard": "^3.10",
17+
"phpstan/phpstan": "^0.12.42",
1818
"nette/robot-loader": "^2.4",
19-
"nette/tester": "^1.7"
19+
"nette/tester": "^2.3",
20+
"jakub-onderka/php-parallel-lint": "^1.0"
2021
},
2122
"autoload": {
2223
"classmap": ["src/"]

phpstan.neon

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@ parameters:
55

66
excludes_analyse:
77
- %rootDir%/../../../tests/bootstrap.php
8-
- %rootDir%/../../../tests/environment.php
8+
- %rootDir%/../../../tests/environment.php
9+
10+
ignoreErrors:
11+
- '#Parameter \#1 \$var of function count expects array\|Countable, array<int, string>\|string given\.#'
12+
- '#Parameter \#2 \$str of function explode expects string, array<int, string>\|string given\.#'
13+
- '#Parameter \#1 \$arr1 of function array_merge expects array, array<int, string>\|string given\.#'
14+
- '#Parameter \#2 \.\.\.\$args of function array_merge expects array, array<int, string>\|string given\.#'

ruleset.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
<!-- because of $formControl->addCondition() -->
2424
<exclude name="PEAR.WhiteSpace.ObjectOperatorIndent.Incorrect"/>
25+
26+
<exclude name="SlevomatCodingStandard.PHP.DisallowReference.DisallowedAssigningByReference"/>
27+
<exclude name="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators.DisallowedPostIncrementOperator"/>
28+
<exclude name="SlevomatCodingStandard.ControlStructures.RequireYodaComparison.RequiredYodaComparison"/>
29+
<exclude name="SlevomatCodingStandard.ControlStructures.NewWithoutParentheses.UselessParentheses"/>
30+
<exclude name="SlevomatCodingStandard.Functions.TrailingCommaInCall.MissingTrailingComma"/>
2531
</rule>
2632
<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml">
2733
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword"/>

src/Mesour/IpAddresses/IpAddressNormalizer.php

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,74 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
namespace Mesour\IpAddresses;
46

5-
/**
6-
* @author Matouš Němec <mesour.com>
7-
*/
7+
/** @author Matouš Němec <mesour.com> */
88
abstract class IpAddressNormalizer
99
{
1010

11-
final public static function normalizeIpV6($address): string
11+
final public static function normalizeIpV6(string $address): string
1212
{
13-
if (strpos($address, '::') !== false) {
14-
$part = explode('::', $address);
15-
$part[0] = explode(':', $part[0]);
16-
$part[1] = explode(':', $part[1]);
13+
if (\strpos($address, '::') !== false) {
14+
$part = \explode('::', $address);
15+
$part[0] = \explode(':', $part[0]);
16+
$part[1] = \explode(':', $part[1]);
1717
$missing = [];
18-
for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) {
19-
array_push($missing, '0000');
18+
19+
for ($i = 0; $i < 8 - (\count($part[0]) + \count($part[1])); $i++) {
20+
\array_push($missing, '0000');
2021
}
21-
$missing = array_merge($part[0], $missing);
22-
$part = array_merge($missing, $part[1]);
22+
23+
$missing = \array_merge($part[0], $missing);
24+
$part = \array_merge($missing, $part[1]);
2325
} else {
24-
$part = explode(':', $address);
26+
$part = \explode(':', $address);
2527
}
2628

2729
foreach ($part as &$p) {
28-
while (strlen($p) < 4) {
30+
while (\strlen($p) < 4) {
2931
$p = '0' . $p;
3032
}
3133
}
34+
3235
unset($p);
3336

34-
$result = implode(':', $part);
35-
if (strlen($result) == 39) {
37+
$result = \implode(':', $part);
38+
39+
if (\strlen($result) === 39) {
3640
return $result;
3741
}
42+
3843
throw new \UnexpectedValueException('Ip address is not valid.');
3944
}
4045

41-
final public static function compressIpV6($ip): string
46+
final public static function compressIpV6(string $ip): string
4247
{
43-
if (substr($ip, 0, 4) === '0000') {
44-
$ip = substr_replace($ip, ':0', 0, 4);
48+
if (\substr($ip, 0, 4) === '0000') {
49+
$ip = \substr_replace($ip, ':0', 0, 4);
4550
}
46-
$ip = str_replace(':0000', ':0', $ip);
47-
$ip = preg_replace('/:0{1,3}(?=\w)/', ':', $ip);
51+
52+
$ip = \str_replace(':0000', ':0', $ip);
53+
$ip = \preg_replace('/:0{1,3}(?=\w)/', ':', $ip);
4854
$z = ':0:0:0:0:0:0:0:';
49-
while (strpos($ip, '::') === false && strlen($z) >= 5) {
50-
$pos = strpos($ip, $z);
55+
56+
while (\strpos($ip, '::') === false && \strlen($z) >= 5) {
57+
$pos = \strpos($ip, $z);
58+
5159
if ($pos !== false) {
52-
$ip = substr_replace($ip, '::', $pos, strlen($z));
60+
$ip = \substr_replace($ip, '::', $pos, \strlen($z));
61+
5362
break;
5463
}
55-
$z = substr($z, 0, strlen($z) - 2);
64+
65+
$z = \substr($z, 0, \strlen($z) - 2);
5666
}
57-
if (substr($ip, 1, 1) !== ':') {
58-
return ltrim($ip, ':');
67+
68+
if (\substr($ip, 1, 1) !== ':') {
69+
return \ltrim($ip, ':');
5970
}
71+
6072
return $ip;
6173
}
6274

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
namespace Mesour\IpAddresses;
46

5-
/**
6-
* @author Matouš Němec <mesour.com>
7-
*/
7+
/** @author Matouš Němec <mesour.com> */
88
abstract class IpAddressValidator
99
{
1010

1111
final public static function isIpAddress(string $ipAddress): bool
1212
{
13-
return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP);
13+
return (bool) \filter_var($ipAddress, \FILTER_VALIDATE_IP);
1414
}
1515

1616
final public static function isIpV4(string $ipAddress): bool
1717
{
18-
return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
18+
return (bool) \filter_var($ipAddress, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4);
1919
}
2020

2121
final public static function isIpV6(string $ipAddress): bool
2222
{
23-
return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
23+
return (bool) \filter_var($ipAddress, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6);
2424
}
2525

2626
}

tests/Mesour/IpAddressesTests/BaseTestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
namespace Mesour\IpAddressesTests;
46

57
use Tester\TestCase;

tests/Mesour/IpAddressesTests/IpAddressNormalizerTest.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
namespace Mesour\IpAddressesTests;
46

57
use Mesour\IpAddresses\IpAddressNormalizer;
@@ -11,7 +13,7 @@ require_once __DIR__ . '/BaseTestCase.php';
1113
class IpAddressNormalizerTest extends BaseTestCase
1214
{
1315

14-
public function testCompress()
16+
public function testCompress(): void
1517
{
1618
Assert::same(
1719
'2001:db8::ff00:42:8329',
@@ -34,7 +36,7 @@ class IpAddressNormalizerTest extends BaseTestCase
3436
);
3537
}
3638

37-
public function testNormalize()
39+
public function testNormalize(): void
3840
{
3941
Assert::same(
4042
'2001:0db8:0000:0000:0000:ff00:0042:8329',

tests/php.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
date.timezone = "Europe/Prague";
2-
3-
extension = json.so
4-
extension = tokenizer.so

0 commit comments

Comments
 (0)