Skip to content

Commit

Permalink
build: use github actions instead travis, upd ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Gemorroj committed Feb 6, 2021
1 parent 23ff64e commit 7fc0176
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 122 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.php]
indent_size = 4
indent_style = space

[*.md]
trim_trailing_whitespace = false
93 changes: 93 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Continuous Integration

on:
- push
- pull_request

jobs:
tests:
strategy:
fail-fast: false
matrix:
include:
- operating-system: 'ubuntu-latest'
php-version: '7.3'
job-description: 'Ubuntu; PHP 7.3; latest-deps'

- operating-system: 'ubuntu-latest'
php-version: '7.3'
composer-flags: '--prefer-lowest'
job-description: 'Ubuntu; PHP 7.3; lowest-deps'

- operating-system: 'ubuntu-latest'
php-version: '7.4'
job-description: 'Ubuntu; PHP 7.4; latest-deps'

- operating-system: 'ubuntu-latest'
php-version: '7.4'
composer-flags: '--prefer-lowest'
job-description: 'Ubuntu; PHP 7.4; lowest-deps'

- operating-system: 'ubuntu-latest'
php-version: '8.0'
job-description: 'Ubuntu; PHP 8.0; latest-deps'

- operating-system: 'ubuntu-latest'
php-version: '8.0'
composer-flags: '--prefer-lowest'
job-description: 'Ubuntu; PHP 8.0; lowest-deps'

- operating-system: 'windows-latest'
php-version: '8.0'
job-description: 'Windows; PHP 8.0; latest-deps'

- operating-system: 'macos-latest'
php-version: '8.0'
job-description: 'MacOS; PHP 8.0; latest-deps'


name: ${{ matrix.job-description }}

runs-on: ${{ matrix.operating-system }}

steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-${{ matrix.composer-flags }}
restore-keys: |
composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-
composer-${{ runner.os }}-${{ matrix.php-version }}-
composer-${{ runner.os }}-
composer-
- name: Install dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
retry_wait_seconds: 30
command: |
composer update --optimize-autoloader --no-interaction --ansi --no-progress --prefer-dist ${{ matrix.composer-flags }}
composer info -D
- name: Tests
run: vendor/bin/phpunit --configuration phpunit.xml.dist
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
composer.phar
composer.lock
vendor/

phpunit.xml
.phpunit.result.cache

.php_cs
.php_cs.cache
5 changes: 4 additions & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ $finder = PhpCsFixer\Finder::create()

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'@PHP73Migration' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
Expand All @@ -15,12 +16,14 @@ return PhpCsFixer\Config::create()
'list_syntax' => ['syntax' => 'short'],
// 'mb_str_functions' => true,
'native_function_invocation' => true,
'native_constant_invocation' => true,
'no_null_property_initialization' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'phpdoc_order' => true,
'strict_comparison' => true,
'combine_nested_dirname' => true,
])
->setRiskyAllowed(true)
->setFinder($finder)
Expand Down
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "W3C CSS Validator service.",
"license": "LGPL-3.0",
"require": {
"php": "^7.3|^8.0",
"php": ">=7.3",
"ext-dom": "*"
},
"authors": [
Expand All @@ -13,8 +13,8 @@
}
],
"require-dev": {
"phpunit/phpunit": "^9.0",
"friendsofphp/php-cs-fixer": "^2.16"
"phpunit/phpunit": "^9.5",
"friendsofphp/php-cs-fixer": "^2.18"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.5/phpunit.xsd"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
bootstrap="vendor/autoload.php"
>
Expand Down
46 changes: 24 additions & 22 deletions src/CSSValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class CSSValidator
/**
* URI to the W3C validator.
*
* @var string
* @var string
*/
protected $validatorUri = 'http://jigsaw.w3.org/css-validator/validator';

/**
* Options
* Options.
*
* @var Options
*/
Expand Down Expand Up @@ -48,30 +48,30 @@ public function setValidatorUri(string $validatorUri): self
}

/**
* @param string $uri
* @param resource $context
*
* @throws Exception
* @return string
*/
protected function sendRequest(string $uri, $context = null): string
{
$data = \file_get_contents($uri, null, $context);
if ($data === false) {
if (false === $data) {
throw new Exception('Error send request');
}

return $data;
}

/**
* Validates a given URI
* Validates a given URI.
*
* Executes the validator using the current parameters and returns a Response
* object on success.
*
* @param string $uri The address to the page to validate ex: http://example.com/
*
* @throws Exception
*
* @return Response object Response if web service call successful
*/
public function validateUri(string $uri): Response
Expand All @@ -85,48 +85,50 @@ public function validateUri(string $uri): Response
'http' => [
'method' => 'GET',
'header' => 'User-Agent: CSSValidator',
]
],
]);

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

return $this->parseSOAP12Response($data);
}

/**
* Validates the local file
* Validates the local file.
*
* Requests validation on the local file, from an instance of the W3C validator.
* The file is posted to the W3C validator using multipart/form-data.
*
* @param string $file file to be validated.
* @param string $file file to be validated
*
* @throws Exception
*
* @return Response object Response if web service call successful
*/
public function validateFile(string $file): Response
{
if (\file_exists($file) !== true) {
if (true !== \file_exists($file)) {
throw new Exception('File not found');
}
if (\is_readable($file) !== true) {
if (true !== \is_readable($file)) {
throw new Exception('File not readable');
}

$data = \file_get_contents($file);
if ($data === false) {
if (false === $data) {
throw new Exception('Failed get file');
}

return $this->validateFragment($data);
}

/**
* Validate an html string
* Validate an html string.
*
* @param string $css Full css document fragment
*
* @throws Exception
*
* @return Response object Response if web service call successful
*/
public function validateFragment(string $css): Response
Expand All @@ -140,30 +142,30 @@ public function validateFragment(string $css): Response
'http' => [
'method' => 'GET',
'header' => 'User-Agent: CSSValidator',
]
],
]);

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

return $this->parseSOAP12Response($data);
}


/**
* Parse an XML response from the validator
* Parse an XML response from the validator.
*
* This function parses a SOAP 1.2 response xml string from the validator.
*
* @param string $xml The raw soap12 XML response from the validator.
* @param string $xml the raw soap12 XML response from the validator
*
* @throws Exception
*
* @return Response object Response if parsing soap12 response successfully,
*/
protected function parseSOAP12Response(string $xml): Response
{
$doc = new \DOMDocument('1.0', 'UTF-8');

if ($doc->loadXML($xml) === false) {
if (false === $doc->loadXML($xml)) {
throw new Exception('Failed load xml');
}

Expand All @@ -173,13 +175,13 @@ protected function parseSOAP12Response(string $xml): Response
foreach (['uri', 'checkedby', 'csslevel', 'date'] as $var) {
$element = $doc->getElementsByTagName($var);
if ($element->length) {
$response->{'set' . \ucfirst($var)}($element->item(0)->nodeValue);
$response->{'set'.\ucfirst($var)}($element->item(0)->nodeValue);
}
}

// Handle the bool element validity
$element = $doc->getElementsByTagName('validity');
if ($element->length && $element->item(0)->nodeValue === 'true') {
if ($element->length && 'true' === $element->item(0)->nodeValue) {
$response->setValidity(true);
} else {
$response->setValidity(false);
Expand Down
Loading

0 comments on commit 7fc0176

Please sign in to comment.