Skip to content
This repository was archived by the owner on Oct 12, 2024. It is now read-only.

Commit 91dd937

Browse files
authored
Merge pull request #2 from phpbench/update
Update
2 parents a126b32 + 67e55b7 commit 91dd937

File tree

13 files changed

+336
-79
lines changed

13 files changed

+336
-79
lines changed

.github/workflows/ci.yaml

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
name: "CI"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- 'master'
8+
9+
env:
10+
fail-fast: true
11+
TZ: "Europe/Paris"
12+
REQUIRED_PHP_EXTENSIONS: "dom"
13+
14+
jobs:
15+
composer-validate:
16+
name: "Composer validate (${{ matrix.php-version }})"
17+
18+
runs-on: "ubuntu-latest"
19+
20+
strategy:
21+
matrix:
22+
php-version:
23+
- '7.2'
24+
25+
steps:
26+
-
27+
name: "Checkout code"
28+
uses: "actions/checkout@v2"
29+
30+
-
31+
name: "Install PHP"
32+
uses: "shivammathur/setup-php@v2"
33+
with:
34+
coverage: "none"
35+
php-version: "${{ matrix.php-version }}"
36+
tools: composer:v2
37+
38+
-
39+
name: "Validate composer.json"
40+
run: "composer validate --strict --no-check-lock"
41+
42+
php-cs-fixer:
43+
needs:
44+
- "composer-validate"
45+
46+
name: "PHP-CS-Fixer (${{ matrix.php-version }})"
47+
48+
runs-on: "ubuntu-latest"
49+
50+
strategy:
51+
matrix:
52+
php-version:
53+
- '7.2'
54+
55+
steps:
56+
-
57+
name: "Checkout code"
58+
uses: "actions/checkout@v2"
59+
60+
-
61+
name: "Install PHP"
62+
uses: "shivammathur/setup-php@v2"
63+
with:
64+
coverage: "none"
65+
extensions: "${{ env.REQUIRED_PHP_EXTENSIONS }}"
66+
php-version: "${{ matrix.php-version }}"
67+
tools: composer:v2
68+
69+
-
70+
name: "Composer install"
71+
uses: "ramsey/composer-install@v1"
72+
with:
73+
composer-options: "--no-scripts"
74+
75+
-
76+
name: "Run friendsofphp/php-cs-fixer"
77+
run: "vendor/bin/php-cs-fixer fix --dry-run --diff --verbose"
78+
79+
phpstan:
80+
needs:
81+
- "composer-validate"
82+
83+
name: "PHPStan (${{ matrix.php-version }})"
84+
85+
runs-on: "ubuntu-latest"
86+
87+
strategy:
88+
matrix:
89+
php-version:
90+
- '7.2'
91+
92+
steps:
93+
-
94+
name: "Checkout code"
95+
uses: "actions/checkout@v2"
96+
97+
-
98+
name: "Install PHP"
99+
uses: "shivammathur/setup-php@v2"
100+
with:
101+
coverage: "none"
102+
extensions: "${{ env.REQUIRED_PHP_EXTENSIONS }}"
103+
php-version: "${{ matrix.php-version }}"
104+
tools: composer:v2
105+
106+
-
107+
name: "Composer install"
108+
uses: "ramsey/composer-install@v1"
109+
with:
110+
composer-options: "--no-scripts"
111+
112+
-
113+
name: "Run phpstan/phpstan"
114+
run: "vendor/bin/phpstan analyse --level=7 lib"
115+
116+
tests:
117+
needs:
118+
- "composer-validate"
119+
120+
name: "PHP ${{ matrix.php-version }} + ${{ matrix.dependency }}"
121+
122+
runs-on: ubuntu-latest
123+
124+
continue-on-error: ${{ matrix.allow-failures }}
125+
126+
strategy:
127+
matrix:
128+
php-version:
129+
- '7.2'
130+
- '7.3'
131+
- '7.4'
132+
dependency:
133+
- 'lowest'
134+
- 'highest'
135+
with-examples: ['yes']
136+
allow-failures: [false]
137+
include:
138+
- php-version: '7.2'
139+
dependency: 'lowest'
140+
with-examples: 'no'
141+
allow-failures: false
142+
coverage: xdebug
143+
- php-version: '8.0'
144+
dependency: 'highest'
145+
with-examples: 'no'
146+
allow-failures: true
147+
coverage: xdebug
148+
149+
steps:
150+
- name: "Checkout code"
151+
uses: actions/checkout@v2.3.3
152+
153+
- name: "Install PHP with extensions"
154+
uses: shivammathur/setup-php@2.7.0
155+
with:
156+
extensions: "${{ env.REQUIRED_PHP_EXTENSIONS }}"
157+
php-version: ${{ matrix.php-version }}
158+
tools: composer:v2
159+
160+
- name: "Add PHPUnit matcher"
161+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
162+
163+
- name: "Remove friendsofphp/php-cs-fixer"
164+
run: composer remove --dev friendsofphp/php-cs-fixer --no-update
165+
166+
- name: "Composer install"
167+
uses: "ramsey/composer-install@v1"
168+
with:
169+
dependency-versions: "${{ matrix.dependency }}"
170+
171+
- name: PHP Info
172+
run: php --version
173+
174+
- name: "Run tests with PHPUnit"
175+
run: vendor/bin/phpunit --verbose

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
composer.lock
22
vendor
3-
docs/build
3+
.phpunit.result.cache
4+
.php_cs.cache

.php_cs.dist

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in([
5+
__DIR__ . '/lib',
6+
__DIR__ . '/tests',
7+
])
8+
->exclude([
9+
'Attributes'
10+
])
11+
;
12+
13+
return PhpCsFixer\Config::create()
14+
->setRiskyAllowed(true)
15+
->setRules([
16+
'@PSR2' => true,
17+
'void_return' => true,
18+
'binary_operator_spaces' => [ 'align_double_arrow' => false ],
19+
'blank_line_before_statement' => [
20+
'statements' => [
21+
'break',
22+
'continue',
23+
'declare',
24+
'default',
25+
'die',
26+
'do',
27+
'exit',
28+
'for',
29+
'foreach',
30+
'goto',
31+
'if',
32+
'include',
33+
'include_once',
34+
'require',
35+
'require_once',
36+
'return',
37+
'switch',
38+
'throw',
39+
'try',
40+
'while',
41+
'yield',
42+
],
43+
],
44+
'ordered_imports' => true,
45+
'concat_space' => false,
46+
'method_argument_space' => false,
47+
'no_unused_imports' => true,
48+
'ordered_imports' => true,
49+
'php_unit_set_up_tear_down_visibility' => true,
50+
'phpdoc_align' => [],
51+
'phpdoc_indent' => false,
52+
'phpdoc_separation' => true,
53+
'no_superfluous_phpdoc_tags' => [
54+
'allow_mixed' => true
55+
],
56+
'fully_qualified_strict_types' => true,
57+
])
58+
->setFinder($finder)
59+
;

.travis.yml

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

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
DOM
22
===
33

4-
[![Build Status](https://travis-ci.org/phpbench/dom.svg?branch=master)](https://travis-ci.org/phpbench/dom)
5-
[![StyleCI](https://styleci.io/repos/46851513/shield)](https://styleci.io/repos/46851513)
4+
[![CI](https://github.com/phpbench/dom/actions/workflows/ci.yaml/badge.svg)](https://github.com/phpbench/dom/actions/workflows/ci.yaml)
65

76
This library provides a wrapper for the PHP DOM library which makes your life
87
easier.

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"ext-dom": "*"
1414
},
1515
"require-dev": {
16-
"phpunit/phpunit": "^8.0|^9.0"
16+
"phpunit/phpunit": "^8.0|^9.0",
17+
"phpstan/phpstan": "^0.12.83",
18+
"friendsofphp/php-cs-fixer": "^2.18"
1719
},
1820
"autoload": {
1921
"psr-4": {

lib/Document.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212
namespace PhpBench\Dom;
1313

14+
use DOMNode;
15+
use DOMNodeList;
16+
use RuntimeException;
17+
1418
/**
1519
* Wrapper for the \DOMDocument class.
1620
*/
1721
class Document extends \DOMDocument implements XPathAware
1822
{
1923
/**
20-
* @var XPath
24+
* @var XPath|null
2125
*/
2226
private $xpath;
2327

@@ -36,19 +40,20 @@ public function __construct($version = '1.0', $encoding = null)
3640
*
3741
* @param string $name
3842
*
39-
* @return Element
4043
*/
41-
public function createRoot($name)
44+
public function createRoot($name): Element
4245
{
43-
return $this->appendChild(new Element($name));
46+
$element = $this->appendChild(new Element($name));
47+
assert($element instanceof Element);
48+
49+
return $element;
4450
}
4551

4652
/**
4753
* Return the XPath object bound to this document.
4854
*
49-
* @return XPath
5055
*/
51-
public function xpath()
56+
public function xpath(): XPath
5257
{
5358
if ($this->xpath) {
5459
return $this->xpath;
@@ -60,44 +65,47 @@ public function xpath()
6065
}
6166

6267
/**
63-
* {@inheritdoc}
68+
* @return DOMNodeList<DOMNode>
6469
*/
65-
public function query($query, \DOMNode $context = null)
70+
public function query($query, DOMNode $context = null): DOMNodeList
6671
{
6772
return $this->xpath()->query($query, $context);
6873
}
6974

7075
/**
7176
* {@inheritdoc}
7277
*/
73-
public function queryOne($query, \DOMNode $context = null)
78+
public function queryOne($query, DOMNode $context = null)
7479
{
7580
return $this->xpath()->queryOne($query, $context);
7681
}
7782

7883
/**
7984
* {@inheritdoc}
8085
*/
81-
public function evaluate($expression, \DOMNode $context = null)
86+
public function evaluate($expression, DOMNode $context = null)
8287
{
8388
return $this->xpath()->evaluate($expression, $context);
8489
}
8590

8691
/**
8792
* Return a formatted string representation of the document.
8893
*
89-
* @return string
9094
*/
91-
public function dump()
95+
public function dump(): string
9296
{
9397
$this->formatOutput = true;
9498
$result = $this->saveXml();
9599
$this->formatOutput = false;
96100

101+
if (false === $result) {
102+
throw new RuntimeException('Could not dump XML');
103+
}
104+
97105
return $result;
98106
}
99107

100-
public function duplicate()
108+
public function duplicate(): Document
101109
{
102110
$dom = new self();
103111
$firstChild = $dom->importNode($this->firstChild, true);

0 commit comments

Comments
 (0)