Skip to content

Commit

Permalink
Merge pull request #2 from mesour/mn-funding
Browse files Browse the repository at this point in the history
Added FUNDING.yml
  • Loading branch information
mesour committed Sep 8, 2020
2 parents dd38329 + 2f25705 commit acd6dd1
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 47 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: mesour
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
language: php

php:
- 7.0
- 7.1
- hhvm
- 7.2
- 7.3
- 7.4
- 8.0

matrix:
allow_failures:
- php: hhvm
- php: 8.0

install:
- composer install --no-interaction --prefer-source
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
"homepage": "http://mesour.com"
}],
"require": {
"php": ">=7.0"
"php": ">=7.1"
},
"require-dev": {
"tracy/tracy": "~2.3.0",
"slevomat/coding-standard": "^1.0",
"consistence/coding-standard": "^0.10",
"phpstan/phpstan": "^0.7.0",
"slevomat/coding-standard": "^6.4",
"consistence/coding-standard": "^3.10",
"phpstan/phpstan": "^0.12.42",
"nette/robot-loader": "^2.4",
"nette/tester": "^1.7"
"nette/tester": "^2.3",
"jakub-onderka/php-parallel-lint": "^1.0"
},
"autoload": {
"classmap": ["src/"]
Expand Down
8 changes: 7 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ parameters:

excludes_analyse:
- %rootDir%/../../../tests/bootstrap.php
- %rootDir%/../../../tests/environment.php
- %rootDir%/../../../tests/environment.php

ignoreErrors:
- '#Parameter \#1 \$var of function count expects array\|Countable, array<int, string>\|string given\.#'
- '#Parameter \#2 \$str of function explode expects string, array<int, string>\|string given\.#'
- '#Parameter \#1 \$arr1 of function array_merge expects array, array<int, string>\|string given\.#'
- '#Parameter \#2 \.\.\.\$args of function array_merge expects array, array<int, string>\|string given\.#'
6 changes: 6 additions & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@

<!-- because of $formControl->addCondition() -->
<exclude name="PEAR.WhiteSpace.ObjectOperatorIndent.Incorrect"/>

<exclude name="SlevomatCodingStandard.PHP.DisallowReference.DisallowedAssigningByReference"/>
<exclude name="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators.DisallowedPostIncrementOperator"/>
<exclude name="SlevomatCodingStandard.ControlStructures.RequireYodaComparison.RequiredYodaComparison"/>
<exclude name="SlevomatCodingStandard.ControlStructures.NewWithoutParentheses.UselessParentheses"/>
<exclude name="SlevomatCodingStandard.Functions.TrailingCommaInCall.MissingTrailingComma"/>
</rule>
<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml">
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword"/>
Expand Down
66 changes: 39 additions & 27 deletions src/Mesour/IpAddresses/IpAddressNormalizer.php
Original file line number Diff line number Diff line change
@@ -1,62 +1,74 @@
<?php

declare(strict_types = 1);

namespace Mesour\IpAddresses;

/**
* @author Matouš Němec <mesour.com>
*/
/** @author Matouš Němec <mesour.com> */
abstract class IpAddressNormalizer
{

final public static function normalizeIpV6($address): string
final public static function normalizeIpV6(string $address): string
{
if (strpos($address, '::') !== false) {
$part = explode('::', $address);
$part[0] = explode(':', $part[0]);
$part[1] = explode(':', $part[1]);
if (\strpos($address, '::') !== false) {
$part = \explode('::', $address);
$part[0] = \explode(':', $part[0]);
$part[1] = \explode(':', $part[1]);
$missing = [];
for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) {
array_push($missing, '0000');

for ($i = 0; $i < 8 - (\count($part[0]) + \count($part[1])); $i++) {
\array_push($missing, '0000');
}
$missing = array_merge($part[0], $missing);
$part = array_merge($missing, $part[1]);

$missing = \array_merge($part[0], $missing);
$part = \array_merge($missing, $part[1]);
} else {
$part = explode(':', $address);
$part = \explode(':', $address);
}

foreach ($part as &$p) {
while (strlen($p) < 4) {
while (\strlen($p) < 4) {
$p = '0' . $p;
}
}

unset($p);

$result = implode(':', $part);
if (strlen($result) == 39) {
$result = \implode(':', $part);

if (\strlen($result) === 39) {
return $result;
}

throw new \UnexpectedValueException('Ip address is not valid.');
}

final public static function compressIpV6($ip): string
final public static function compressIpV6(string $ip): string
{
if (substr($ip, 0, 4) === '0000') {
$ip = substr_replace($ip, ':0', 0, 4);
if (\substr($ip, 0, 4) === '0000') {
$ip = \substr_replace($ip, ':0', 0, 4);
}
$ip = str_replace(':0000', ':0', $ip);
$ip = preg_replace('/:0{1,3}(?=\w)/', ':', $ip);

$ip = \str_replace(':0000', ':0', $ip);
$ip = \preg_replace('/:0{1,3}(?=\w)/', ':', $ip);
$z = ':0:0:0:0:0:0:0:';
while (strpos($ip, '::') === false && strlen($z) >= 5) {
$pos = strpos($ip, $z);

while (\strpos($ip, '::') === false && \strlen($z) >= 5) {
$pos = \strpos($ip, $z);

if ($pos !== false) {
$ip = substr_replace($ip, '::', $pos, strlen($z));
$ip = \substr_replace($ip, '::', $pos, \strlen($z));

break;
}
$z = substr($z, 0, strlen($z) - 2);

$z = \substr($z, 0, \strlen($z) - 2);
}
if (substr($ip, 1, 1) !== ':') {
return ltrim($ip, ':');

if (\substr($ip, 1, 1) !== ':') {
return \ltrim($ip, ':');
}

return $ip;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Mesour/IpAddresses/IpAddressValidator.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<?php

declare(strict_types = 1);

namespace Mesour\IpAddresses;

/**
* @author Matouš Němec <mesour.com>
*/
/** @author Matouš Němec <mesour.com> */
abstract class IpAddressValidator
{

final public static function isIpAddress(string $ipAddress): bool
{
return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP);
return (bool) \filter_var($ipAddress, \FILTER_VALIDATE_IP);
}

final public static function isIpV4(string $ipAddress): bool
{
return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
return (bool) \filter_var($ipAddress, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4);
}

final public static function isIpV6(string $ipAddress): bool
{
return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
return (bool) \filter_var($ipAddress, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6);
}

}
2 changes: 2 additions & 0 deletions tests/Mesour/IpAddressesTests/BaseTestCase.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

namespace Mesour\IpAddressesTests;

use Tester\TestCase;
Expand Down
6 changes: 4 additions & 2 deletions tests/Mesour/IpAddressesTests/IpAddressNormalizerTest.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

namespace Mesour\IpAddressesTests;

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

public function testCompress()
public function testCompress(): void
{
Assert::same(
'2001:db8::ff00:42:8329',
Expand All @@ -34,7 +36,7 @@ class IpAddressNormalizerTest extends BaseTestCase
);
}

public function testNormalize()
public function testNormalize(): void
{
Assert::same(
'2001:0db8:0000:0000:0000:ff00:0042:8329',
Expand Down
3 changes: 0 additions & 3 deletions tests/php.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
date.timezone = "Europe/Prague";

extension = json.so
extension = tokenizer.so

0 comments on commit acd6dd1

Please sign in to comment.