Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rector [batch] #42

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: rector

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.0']
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.14.3",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18"
Expand Down
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
]);
};
6 changes: 3 additions & 3 deletions src/DnsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function existsMx(string $hostname): bool

restore_error_handler();

return count($result) > 0;
return (is_countable($result) ? count($result) : 0) > 0;
}

/**
Expand All @@ -55,7 +55,7 @@ public static function existsA(string $hostname): bool

restore_error_handler();

return count($result) > 0;
return (is_countable($result) ? count($result) : 0) > 0;
}

/**
Expand All @@ -69,7 +69,7 @@ public static function existsA(string $hostname): bool
*/
public static function acceptsEmails(string $hostnameOrEmail): bool
{
if (strpos($hostnameOrEmail, '@') !== false) {
if (str_contains($hostnameOrEmail, '@')) {
[, $hostnameOrEmail] = explode('@', $hostnameOrEmail, 2);
}
return self::existsMx($hostnameOrEmail) || self::existsA($hostnameOrEmail);
Expand Down
4 changes: 2 additions & 2 deletions src/IpHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function getIpVersion(string $ip, bool $validate = true): int
if ($ipStringLength < 2) {
throw new InvalidArgumentException("Unrecognized address $ip", 10);
}
$preIpVersion = strpos($ip, ':') === false ? self::IPV4 : self::IPV6;
$preIpVersion = !str_contains($ip, ':') ? self::IPV4 : self::IPV6;
if ($preIpVersion === self::IPV4 && $ipStringLength < 7) {
throw new InvalidArgumentException("Unrecognized address $ip", 11);
}
Expand Down Expand Up @@ -123,7 +123,7 @@ public static function inRange(string $subnet, string $range): bool
$binNet = self::ip2bin($net);
$masked = substr($binNet, 0, (int) $netMask);

return ($masked === '' || strpos($binIp, $masked) === 0) && $mask >= $netMask;
return ($masked === '' || str_starts_with($binIp, $masked)) && $mask >= $netMask;
}

/**
Expand Down