Skip to content

Commit be9d413

Browse files
committed
build: php 8, github actions
1 parent 5646599 commit be9d413

13 files changed

Lines changed: 255 additions & 146 deletions

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.php]
13+
indent_size = 4
14+
indent_style = space
15+
16+
[*.md]
17+
trim_trailing_whitespace = false

.github/workflows/ci.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Continuous Integration
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
tests:
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
include:
13+
- operating-system: 'ubuntu-latest'
14+
php-version: '7.3'
15+
job-description: 'Ubuntu; PHP 7.3; latest-deps'
16+
17+
- operating-system: 'ubuntu-latest'
18+
php-version: '7.3'
19+
composer-flags: '--prefer-lowest'
20+
job-description: 'Ubuntu; PHP 7.3; lowest-deps'
21+
22+
- operating-system: 'ubuntu-latest'
23+
php-version: '7.4'
24+
job-description: 'Ubuntu; PHP 7.4; latest-deps'
25+
26+
- operating-system: 'ubuntu-latest'
27+
php-version: '7.4'
28+
composer-flags: '--prefer-lowest'
29+
job-description: 'Ubuntu; PHP 7.4; lowest-deps'
30+
31+
- operating-system: 'ubuntu-latest'
32+
php-version: '8.0'
33+
job-description: 'Ubuntu; PHP 8.0; latest-deps'
34+
35+
- operating-system: 'ubuntu-latest'
36+
php-version: '8.0'
37+
composer-flags: '--prefer-lowest'
38+
job-description: 'Ubuntu; PHP 8.0; lowest-deps'
39+
40+
- operating-system: 'windows-latest'
41+
php-version: '8.0'
42+
job-description: 'Windows; PHP 8.0; latest-deps'
43+
44+
- operating-system: 'macos-latest'
45+
php-version: '8.0'
46+
job-description: 'MacOS; PHP 8.0; latest-deps'
47+
48+
49+
name: ${{ matrix.job-description }}
50+
51+
runs-on: ${{ matrix.operating-system }}
52+
53+
steps:
54+
- name: Set git to use LF
55+
run: |
56+
git config --global core.autocrlf false
57+
git config --global core.eol lf
58+
59+
- name: Checkout code
60+
uses: actions/checkout@v2
61+
62+
- name: Setup PHP
63+
uses: shivammathur/setup-php@v2
64+
with:
65+
php-version: ${{ matrix.php-version }}
66+
67+
- name: Get Composer cache directory
68+
id: composer-cache
69+
run: echo "::set-output name=dir::$(composer config cache-dir)"
70+
71+
- name: Cache dependencies
72+
uses: actions/cache@v2
73+
with:
74+
path: ${{ steps.composer-cache.outputs.dir }}
75+
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-${{ matrix.composer-flags }}
76+
restore-keys: |
77+
composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-
78+
composer-${{ runner.os }}-${{ matrix.php-version }}-
79+
composer-${{ runner.os }}-
80+
composer-
81+
82+
- name: Install dependencies
83+
uses: nick-invision/retry@v2
84+
with:
85+
timeout_minutes: 5
86+
max_attempts: 5
87+
retry_wait_seconds: 30
88+
command: |
89+
composer update --optimize-autoloader --no-interaction --ansi --no-progress --prefer-dist ${{ matrix.composer-flags }}
90+
composer info -D
91+
92+
- name: Tests
93+
run: vendor/bin/phpunit --configuration phpunit.xml.dist

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
composer.phar
33
composer.lock
44
vendor/
5+
56
phpunit.xml
7+
.phpunit.result.cache
68

79
.php_cs
810
.php_cs.cache

.php_cs.dist

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ $finder = PhpCsFixer\Finder::create()
66

77
return PhpCsFixer\Config::create()
88
->setRules([
9-
'@PSR2' => true,
9+
'@Symfony' => true,
10+
'@PHP73Migration' => true,
1011
'array_syntax' => ['syntax' => 'short'],
1112
'combine_consecutive_issets' => true,
1213
'combine_consecutive_unsets' => true,
@@ -15,12 +16,14 @@ return PhpCsFixer\Config::create()
1516
'list_syntax' => ['syntax' => 'short'],
1617
// 'mb_str_functions' => true,
1718
'native_function_invocation' => true,
19+
'native_constant_invocation' => true,
1820
'no_null_property_initialization' => true,
1921
'no_useless_else' => true,
2022
'no_useless_return' => true,
2123
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
2224
'phpdoc_order' => true,
2325
'strict_comparison' => true,
26+
'combine_nested_dirname' => true,
2427
])
2528
->setRiskyAllowed(true)
2629
->setFinder($finder)

.travis.yml

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

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
[![Build Status](https://secure.travis-ci.org/Gemorroj/HTMLValidator.png?branch=master)](https://travis-ci.org/Gemorroj/HTMLValidator)
44

5+
6+
### Not working now
7+
todo: https://validator.w3.org/docs/api.html
8+
9+
510
### Requirements:
611

7-
- PHP >= 7.1.3
12+
- PHP >= 7.3
813

914
### Installation:
1015
```bash

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "W3C HTML Validator service.",
55
"license": "LGPL-3.0",
66
"require": {
7-
"php": "^7.1.3",
7+
"php": ">=7.3",
88
"ext-dom": "*"
99
},
1010
"authors": [
@@ -13,8 +13,8 @@
1313
}
1414
],
1515
"require-dev": {
16-
"phpunit/phpunit": "^7.5",
17-
"friendsofphp/php-cs-fixer": "^2.16"
16+
"phpunit/phpunit": "^9.5",
17+
"friendsofphp/php-cs-fixer": "^2.18"
1818
},
1919
"autoload": {
2020
"psr-4": {

phpunit.xml.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.5/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.5/phpunit.xsd"
5+
beStrictAboutTestsThatDoNotTestAnything="false"
56
colors="true"
67
bootstrap="vendor/autoload.php"
78
>

src/HTMLValidator.php

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,31 @@ public function setValidatorUri(string $validatorUri): self
4545
return $this;
4646
}
4747

48-
4948
/**
50-
* @param string $uri
5149
* @param resource $context
50+
*
5251
* @throws Exception
53-
* @return string
5452
*/
5553
protected function sendRequest(string $uri, $context = null): string
5654
{
5755
$data = \file_get_contents($uri, null, $context);
58-
if ($data === false) {
56+
if (false === $data) {
5957
throw new Exception('Error send request');
6058
}
6159

6260
return $data;
6361
}
64-
62+
6563
/**
66-
* Validates a given URI
64+
* Validates a given URI.
6765
*
6866
* Executes the validator using the current parameters and returns a Response
6967
* object on success.
7068
*
7169
* @param string $uri The address to the page to validate ex: http://example.com/
7270
*
7371
* @throws Exception
72+
*
7473
* @return Response object HTMLValidator\Response
7574
*/
7675
public function validateUri(string $uri): Response
@@ -84,47 +83,49 @@ public function validateUri(string $uri): Response
8483
'http' => [
8584
'method' => 'GET',
8685
'header' => 'User-Agent: HTMLValidator',
87-
]
86+
],
8887
]);
8988

90-
$data = $this->sendRequest($this->validatorUri . '?' . $query, $context);
89+
$data = $this->sendRequest($this->validatorUri.'?'.$query, $context);
9190

9291
return $this->parseSOAP12Response($data);
9392
}
94-
93+
9594
/**
96-
* Validates the local file
95+
* Validates the local file.
9796
*
9897
* Requests validation on the local file, from an instance of the W3C validator.
9998
*
100-
* @param string $file file to be validated.
99+
* @param string $file file to be validated
101100
*
102101
* @throws Exception
102+
*
103103
* @return Response object HTMLValidator\Response
104104
*/
105105
public function validateFile(string $file): Response
106106
{
107-
if (\file_exists($file) !== true) {
107+
if (true !== \file_exists($file)) {
108108
throw new Exception('File not found');
109109
}
110-
if (\is_readable($file) !== true) {
110+
if (true !== \is_readable($file)) {
111111
throw new Exception('File not readable');
112112
}
113113

114114
$data = \file_get_contents($file);
115-
if ($data === false) {
115+
if (false === $data) {
116116
throw new Exception('Failed get file');
117117
}
118118

119119
return $this->validateFragment($data);
120120
}
121-
121+
122122
/**
123-
* Validate an html string
123+
* Validate an html string.
124124
*
125125
* @param string $html full html document fragment
126126
*
127127
* @throws Exception
128+
*
128129
* @return Response object HTMLValidator\Response
129130
*/
130131
public function validateFragment(string $html): Response
@@ -139,30 +140,30 @@ public function validateFragment(string $html): Response
139140
'method' => 'POST',
140141
'header' => "Content-Type: application/x-www-form-urlencoded\r\nUser-Agent: HTMLValidator",
141142
'content' => $query,
142-
]
143+
],
143144
]);
144145

145146
$data = $this->sendRequest($this->validatorUri, $context);
146147

147148
return $this->parseSOAP12Response($data);
148149
}
149-
150+
150151
/**
151-
* Parse an XML response from the validator
152+
* Parse an XML response from the validator.
152153
*
153154
* This function parses a SOAP 1.2 response xml string from the validator.
154155
*
155-
* @param string $xml The raw soap12 XML response from the validator.
156+
* @param string $xml the raw soap12 XML response from the validator
156157
*
157158
* @throws Exception
158-
* @return Response object HTMLValidator\Response
159159
*
160+
* @return Response object HTMLValidator\Response
160161
*/
161162
protected function parseSOAP12Response(string $xml): Response
162163
{
163164
$doc = new \DOMDocument('1.0', 'UTF-8');
164165

165-
if ($doc->loadXML($xml) === false) {
166+
if (false === $doc->loadXML($xml)) {
166167
throw new Exception('Failed load xml');
167168
}
168169

@@ -172,13 +173,13 @@ protected function parseSOAP12Response(string $xml): Response
172173
foreach (['uri', 'checkedby', 'doctype', 'charset'] as $var) {
173174
$element = $doc->getElementsByTagName($var);
174175
if ($element->length) {
175-
$response->{'set' . \ucfirst($var)}($element->item(0)->nodeValue);
176+
$response->{'set'.\ucfirst($var)}($element->item(0)->nodeValue);
176177
}
177178
}
178179

179180
// Handle the bool element validity
180181
$element = $doc->getElementsByTagName('validity');
181-
if ($element->length && $element->item(0)->nodeValue === 'true') {
182+
if ($element->length && 'true' === $element->item(0)->nodeValue) {
182183
$response->setValidity(true);
183184
} else {
184185
$response->setValidity(false);

0 commit comments

Comments
 (0)