Skip to content

Commit 8e5cc47

Browse files
authored
Merge pull request #13 from mesour/mn-php-8
Mn php 8
2 parents c980132 + 26eda50 commit 8e5cc47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+491
-784
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: PHP Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
8+
jobs:
9+
test:
10+
name: Run Tests
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
php-version: [8.0, 8.1, 8.2]
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: ${{ matrix.php-version }}
23+
24+
- run: composer install
25+
- run: vendor/bin/parallel-lint src tests
26+
- run: vendor/bin/phpcs src tests --standard=ruleset.xml -d memory_limit=512M
27+
- run: vendor/bin/phpstan analyse -c phpstan.neon src tests
28+
- run: vendor/bin/phpunit tests

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/vendor
33
/composer.lock
44
/examples/log
5-
/tests/log
5+
!.gitkeep
66
/tests/tmp
77
/tests/environment.php
88
/tests/Mesour/DnsCheckerTests/output

.travis.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

Makefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
_: list
2+
3+
# Config
4+
5+
PHPCS_CONFIG=ruleset.xml
6+
PHPSTAN_CONFIG=phpstan.neon
7+
8+
# QA
9+
10+
qa: ## Check code quality - coding style and static analysis
11+
make lint && make cs && make phpstan && make phpunit
12+
13+
cs: ## Check PHP files coding style
14+
$(PRE_PHP) "vendor/bin/phpcs" src tests --standard=$(PHPCS_CONFIG) --parallel=$(LOGICAL_CORES) -d memory_limit=512M $(ARGS)
15+
16+
csf: ## Fix PHP files coding style
17+
$(PRE_PHP) "vendor/bin/phpcbf" src tests --standard=$(PHPCS_CONFIG) --parallel=$(LOGICAL_CORES) -d memory_limit=512M $(ARGS)
18+
19+
lint: ## Validate syntax of PHP files
20+
$(PRE_PHP) vendor/bin/parallel-lint src tests --blame -j $(LOGICAL_CORES)
21+
22+
phpstan: ## Analyse code with PHPStan
23+
$(PRE_PHP) "vendor/bin/phpstan" analyse src tests -c $(PHPSTAN_CONFIG) --memory-limit=512M $(ARGS)
24+
25+
phpunit: ## Analyse code with PHPStan
26+
$(PRE_PHP) "vendor/bin/phpunit" tests
27+
28+
# Utilities
29+
30+
.SILENT: $(shell grep -h -E '^[a-zA-Z_-]+:.*?$$' $(MAKEFILE_LIST) | sort -u | awk 'BEGIN {FS = ":.*?"}; {printf "%s ", $$1}')
31+
32+
LIST_PAD=20
33+
list:
34+
awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n\nTargets:\n"}'
35+
grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort -u | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-$(LIST_PAD)s\033[0m %s\n", $$1, $$2}'
36+
37+
PRE_PHP=XDEBUG_MODE=off
38+
39+
LOGICAL_CORES=$(shell nproc || sysctl -n hw.logicalcpu || wmic cpu get NumberOfLogicalProcessors || echo 4)

composer.json

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,34 @@
88
"homepage": "http://mesour.com"
99
}],
1010
"require": {
11-
"php": ">=7.1",
11+
"php": ">=8.0",
1212
"mesour/ip-addresses": "^0.2.0"
1313
},
1414
"require-dev": {
15-
"tracy/tracy": "~2.3.0",
16-
"slevomat/coding-standard": "^6.4",
17-
"consistence/coding-standard": "^3.10",
18-
"phpstan/phpstan": "^0.12.42",
19-
"nette/tester": "^2.3",
20-
"nette/bootstrap": "^2.4",
21-
"nette/robot-loader": "^2.4",
22-
"jakub-onderka/php-parallel-lint": "^1.0"
15+
"tracy/tracy": "^2.9.0",
16+
"orisai/coding-standard": "^3.7",
17+
"phpstan/phpstan": "^1.10.0",
18+
"phpstan/phpstan-deprecation-rules": "^1.1.0",
19+
"grifart/phpstan-oneline": "^0.4.2",
20+
"phpstan/phpstan-strict-rules": "^1.5",
21+
"phpunit/phpunit": "^8.5",
22+
"php-parallel-lint/php-parallel-lint": "^1.3.0",
23+
"nette/di": "^3.1"
2324
},
2425
"suggest": {
25-
"nette/bootstrap": "to use class DnsCheckerExtension"
26+
"nette/di": "to use class DnsCheckerExtension"
2627
},
28+
"config": {
29+
"sort-packages": true,
30+
"allow-plugins": {
31+
"dealerdirect/phpcodesniffer-composer-installer": false,
32+
"phpstan/extension-installer": true
33+
}
34+
},
2735
"autoload": {
28-
"classmap": ["src/"]
36+
"psr-4": {
37+
"Mesour\\": "src/Mesour",
38+
"Mesour\\DnsCheckerTests\\": "tests/Mesour/DnsCheckerTests"
39+
}
2940
}
3041
}

phpstan.neon

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
parameters:
2-
autoload_directories:
3-
- %rootDir%/../../../src
4-
- %rootDir%/../../../tests
5-
6-
excludes_analyse:
2+
level: 9
3+
excludePaths:
74
- %rootDir%/../../../tests/bootstrap.php
8-
- %rootDir%/../../../tests/environment.php
5+
6+
checkBenevolentUnionTypes: true
7+
checkMissingCallableSignature: true
8+
checkInternalClassCaseSensitivity: true
9+
checkTooWideReturnTypesInProtectedAndPublicMethods: true
910

1011
ignoreErrors:
1112
- '#Parameter \#[0-9]+ \$[a-zA-Z0-9]+ of method Mesour\\DnsChecker\\DnsRecord::__construct\(\) expects (int|string), int\|string given\.#'
1213
- '#Property .+ \((int|string)\) does not accept int\|string\.#'
1314
- '#Parameter \#[0-9]+ \$[a-zA-Z0-9]+ of class [a-zA-Z0-9\\]+ constructor expects (int|string), int\|string given\.#'
14-
- '#Method Mesour\\DnsChecker\\DnsRecordSet(.+) has .+ typehint specified\.#'
1515

1616
checkGenericClassInNonGenericObjectType: false
1717
checkMissingIterableValueType: false

ruleset.xml

Lines changed: 9 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,17 @@
11
<?xml version="1.0"?>
2-
<ruleset name="Mesour Coding Standard">
3-
<rule ref="vendor/consistence/coding-standard/Consistence/ruleset.xml">
4-
<!-- because of exceptions.php -->
5-
<exclude name="Squiz.Classes.ClassFileName.NoMatch"/>
6-
<exclude name="PSR1.Classes.ClassDeclaration.MultipleClasses"/>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">
3+
<!-- Show only relevant part of path -->
4+
<arg name="basepath" value="./"/>
75

8-
<!-- because of "@param int" over "@param integer" -->
9-
<exclude name="Squiz.Commenting.FunctionComment.IncorrectParamVarName"/>
6+
<!-- Configure cache -->
7+
<arg name="cache" value="./tests/tmp/cache.dat"/>
108

11-
<!-- because of functions without visibility in interfaces -->
12-
<exclude name="Squiz.Scope.MethodScope.Missing"/>
9+
<!-- Import coding-standard -->
10+
<rule ref="./vendor/orisai/coding-standard/src/ruleset-8.1.xml"/>
1311

14-
<!-- because of ") {" when arguments are on multiple lines -->
15-
<exclude name="Generic.Functions.OpeningFunctionBraceBsdAllman.BraceOnSameLine"/>
16-
17-
<!-- because of *.phpt -->
18-
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/>
19-
20-
<!-- because of ::class -->
21-
<exclude name="Squiz.Classes.SelfMemberReference.NotUsed"/>
22-
23-
<!-- because of $formControl->addCondition() -->
24-
<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"/>
31-
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation.NonFullyQualifiedClassName"/>
32-
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLineDocComment.MultiLineDocComment"/>
33-
<exclude name="SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment.OneLinePropertyComment"/>
34-
<exclude name="SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter"/>
35-
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint"/>
36-
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint"/>
37-
<exclude name="SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax.DisallowedArrayTypeHintSyntax"/>
38-
<exclude name="SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator.DisallowedShortTernaryOperator"/>
39-
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
40-
41-
<!-- todo: this can be fixed for PHP 7.4+ -->
42-
<exclude name="SlevomatCodingStandard.Numbers.RequireNumericLiteralSeparator.RequiredNumericLiteralSeparator"/>
12+
<rule ref="SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing">
13+
<exclude name="SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing"/>
4314
</rule>
44-
<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml">
45-
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword"/>
46-
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions"/>
47-
<exclude name="SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces"/>
48-
49-
<!-- because of exceptions.php -->
50-
<exclude name="SlevomatCodingStandard.Files.TypeNameMatchesFileName"/>
5115

52-
<!-- because of \DateTime, \Iterator etc. -->
53-
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName"/>
54-
55-
<!-- because of @method annotations -->
56-
<exclude name="SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse"/>
57-
</rule>
58-
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
59-
<properties>
60-
<property name="searchAnnotations" type="boolean" value="true"/>
61-
</properties>
62-
</rule>
63-
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
64-
<properties>
65-
<property name="allowFullyQualifiedExceptions" type="boolean" value="true"/>
66-
</properties>
67-
</rule>
68-
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
69-
<properties>
70-
<property name="spacing" value="1"/>
71-
</properties>
72-
</rule>
73-
<exclude-pattern>tests/environment.php</exclude-pattern>
7416
<exclude-pattern>tests/bootstrap.php</exclude-pattern>
7517
</ruleset>

src/Mesour/DnsChecker/Records/A6Record.php renamed to src/Mesour/DnsChecker/A6Record.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
<?php
2-
3-
declare(strict_types = 1);
1+
<?php declare(strict_types = 1);
42

53
namespace Mesour\DnsChecker;
64

7-
/**
8-
* @author Matouš Němec <mesour.com>
9-
*/
105
class A6Record extends DnsRecord
116
{
127

13-
/** @var int */
14-
private $masklen;
8+
private int $masklen;
159

16-
/** @var string */
17-
private $ipV6;
10+
private string $ipV6;
1811

19-
/** @var int|string */
20-
private $chain;
12+
private int|string $chain;
2113

2214
/**
23-
* @param string[]|int[] $record
15+
* @param array<string>|array<int> $record
2416
*/
2517
public function __construct(array $record)
2618
{
@@ -43,10 +35,7 @@ public function getIpV6(): string
4335
return $this->ipV6;
4436
}
4537

46-
/**
47-
* @return int|string
48-
*/
49-
public function getChain()
38+
public function getChain(): int|string
5039
{
5140
return $this->chain;
5241
}

src/Mesour/DnsChecker/Records/AaaaDnsRecord.php renamed to src/Mesour/DnsChecker/AaaaDnsRecord.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
<?php
2-
3-
declare(strict_types = 1);
1+
<?php declare(strict_types = 1);
42

53
namespace Mesour\DnsChecker;
64

75
use Mesour\IpAddresses\IpAddressNormalizer;
86

9-
/**
10-
* @author Matouš Němec <mesour.com>
11-
*/
127
class AaaaDnsRecord extends DnsRecord
138
{
149

15-
public function __construct(string $type, string $name, string $content, int $ttl = 1800)
10+
public function __construct(string $type, string $name, string $content, int $ttl = 1_800)
1611
{
1712
parent::__construct($type, $name, IpAddressNormalizer::compressIpV6($content), $ttl);
1813
}

src/Mesour/DnsChecker/Records/CaaRecord.php renamed to src/Mesour/DnsChecker/CaaRecord.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
<?php
2-
3-
declare(strict_types = 1);
1+
<?php declare(strict_types = 1);
42

53
namespace Mesour\DnsChecker;
64

7-
/**
8-
* @author Matouš Němec <mesour.com>
9-
*/
105
class CaaRecord extends DnsRecord
116
{
127

13-
/** @var int */
14-
private $flags;
8+
private int $flags;
159

16-
/** @var string */
17-
private $tag;
10+
private string $tag;
1811

19-
/** @var string */
20-
private $value;
12+
private string $value;
2113

2214
/**
23-
* @param string[]|int[] $record
15+
* @param array<string>|array<int> $record
2416
*/
2517
public function __construct(array $record)
2618
{

0 commit comments

Comments
 (0)