Skip to content
This repository was archived by the owner on Oct 12, 2024. It is now read-only.
Merged
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
175 changes: 175 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
name: "CI"

on:
pull_request:
push:
branches:
- 'master'

env:
fail-fast: true
TZ: "Europe/Paris"
REQUIRED_PHP_EXTENSIONS: "dom"

jobs:
composer-validate:
name: "Composer validate (${{ matrix.php-version }})"

runs-on: "ubuntu-latest"

strategy:
matrix:
php-version:
- '7.2'

steps:
-
name: "Checkout code"
uses: "actions/checkout@v2"

-
name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: composer:v2

-
name: "Validate composer.json"
run: "composer validate --strict --no-check-lock"

php-cs-fixer:
needs:
- "composer-validate"

name: "PHP-CS-Fixer (${{ matrix.php-version }})"

runs-on: "ubuntu-latest"

strategy:
matrix:
php-version:
- '7.2'

steps:
-
name: "Checkout code"
uses: "actions/checkout@v2"

-
name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
extensions: "${{ env.REQUIRED_PHP_EXTENSIONS }}"
php-version: "${{ matrix.php-version }}"
tools: composer:v2

-
name: "Composer install"
uses: "ramsey/composer-install@v1"
with:
composer-options: "--no-scripts"

-
name: "Run friendsofphp/php-cs-fixer"
run: "vendor/bin/php-cs-fixer fix --dry-run --diff --verbose"

phpstan:
needs:
- "composer-validate"

name: "PHPStan (${{ matrix.php-version }})"

runs-on: "ubuntu-latest"

strategy:
matrix:
php-version:
- '7.2'

steps:
-
name: "Checkout code"
uses: "actions/checkout@v2"

-
name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
extensions: "${{ env.REQUIRED_PHP_EXTENSIONS }}"
php-version: "${{ matrix.php-version }}"
tools: composer:v2

-
name: "Composer install"
uses: "ramsey/composer-install@v1"
with:
composer-options: "--no-scripts"

-
name: "Run phpstan/phpstan"
run: "vendor/bin/phpstan analyse --level=7 lib"

tests:
needs:
- "composer-validate"

name: "PHP ${{ matrix.php-version }} + ${{ matrix.dependency }}"

runs-on: ubuntu-latest

continue-on-error: ${{ matrix.allow-failures }}

strategy:
matrix:
php-version:
- '7.2'
- '7.3'
- '7.4'
dependency:
- 'lowest'
- 'highest'
with-examples: ['yes']
allow-failures: [false]
include:
- php-version: '7.2'
dependency: 'lowest'
with-examples: 'no'
allow-failures: false
coverage: xdebug
- php-version: '8.0'
dependency: 'highest'
with-examples: 'no'
allow-failures: true
coverage: xdebug

steps:
- name: "Checkout code"
uses: actions/checkout@v2.3.3

- name: "Install PHP with extensions"
uses: shivammathur/setup-php@2.7.0
with:
extensions: "${{ env.REQUIRED_PHP_EXTENSIONS }}"
php-version: ${{ matrix.php-version }}
tools: composer:v2

- name: "Add PHPUnit matcher"
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: "Remove friendsofphp/php-cs-fixer"
run: composer remove --dev friendsofphp/php-cs-fixer --no-update

- name: "Composer install"
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "${{ matrix.dependency }}"

- name: PHP Info
run: php --version

- name: "Run tests with PHPUnit"
run: vendor/bin/phpunit --verbose
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
vendor
docs/build
.phpunit.result.cache
.php_cs.cache
59 changes: 59 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([
__DIR__ . '/lib',
__DIR__ . '/tests',
])
->exclude([
'Attributes'
])
;

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'void_return' => true,
'binary_operator_spaces' => [ 'align_double_arrow' => false ],
'blank_line_before_statement' => [
'statements' => [
'break',
'continue',
'declare',
'default',
'die',
'do',
'exit',
'for',
'foreach',
'goto',
'if',
'include',
'include_once',
'require',
'require_once',
'return',
'switch',
'throw',
'try',
'while',
'yield',
],
],
'ordered_imports' => true,
'concat_space' => false,
'method_argument_space' => false,
'no_unused_imports' => true,
'ordered_imports' => true,
'php_unit_set_up_tear_down_visibility' => true,
'phpdoc_align' => [],
'phpdoc_indent' => false,
'phpdoc_separation' => true,
'no_superfluous_phpdoc_tags' => [
'allow_mixed' => true
],
'fully_qualified_strict_types' => true,
])
->setFinder($finder)
;
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
DOM
===

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

This library provides a wrapper for the PHP DOM library which makes your life
easier.
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"ext-dom": "*"
},
"require-dev": {
"phpunit/phpunit": "^8.0|^9.0"
"phpunit/phpunit": "^8.0|^9.0",
"phpstan/phpstan": "^0.12.83",
"friendsofphp/php-cs-fixer": "^2.18"
},
"autoload": {
"psr-4": {
Expand Down
34 changes: 21 additions & 13 deletions lib/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@

namespace PhpBench\Dom;

use DOMNode;
use DOMNodeList;
use RuntimeException;

/**
* Wrapper for the \DOMDocument class.
*/
class Document extends \DOMDocument implements XPathAware
{
/**
* @var XPath
* @var XPath|null
*/
private $xpath;

Expand All @@ -36,19 +40,20 @@ public function __construct($version = '1.0', $encoding = null)
*
* @param string $name
*
* @return Element
*/
public function createRoot($name)
public function createRoot($name): Element
{
return $this->appendChild(new Element($name));
$element = $this->appendChild(new Element($name));
assert($element instanceof Element);

return $element;
}

/**
* Return the XPath object bound to this document.
*
* @return XPath
*/
public function xpath()
public function xpath(): XPath
{
if ($this->xpath) {
return $this->xpath;
Expand All @@ -60,44 +65,47 @@ public function xpath()
}

/**
* {@inheritdoc}
* @return DOMNodeList<DOMNode>
*/
public function query($query, \DOMNode $context = null)
public function query($query, DOMNode $context = null): DOMNodeList
{
return $this->xpath()->query($query, $context);
}

/**
* {@inheritdoc}
*/
public function queryOne($query, \DOMNode $context = null)
public function queryOne($query, DOMNode $context = null)
{
return $this->xpath()->queryOne($query, $context);
}

/**
* {@inheritdoc}
*/
public function evaluate($expression, \DOMNode $context = null)
public function evaluate($expression, DOMNode $context = null)
{
return $this->xpath()->evaluate($expression, $context);
}

/**
* Return a formatted string representation of the document.
*
* @return string
*/
public function dump()
public function dump(): string
{
$this->formatOutput = true;
$result = $this->saveXml();
$this->formatOutput = false;

if (false === $result) {
throw new RuntimeException('Could not dump XML');
}

return $result;
}

public function duplicate()
public function duplicate(): Document
{
$dom = new self();
$firstChild = $dom->importNode($this->firstChild, true);
Expand Down
Loading