Skip to content

Commit

Permalink
Merge pull request #6 from eclipxe13/maintenance-20240308
Browse files Browse the repository at this point in the history
Maintenance 2024-03-08 (version 2.0.2)
  • Loading branch information
eclipxe13 committed Mar 8, 2024
2 parents 4850606 + ef7ce5c commit 0e54747
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 70 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[docker-compose.yml]
indent_size = 4
46 changes: 24 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ on:
jobs:

phpcs:
name: Code style (phpcs)
name: Coding standard (phpcs)
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.3'
coverage: none
tools: composer:v2, cs2pr, phpcs
tools: cs2pr, phpcs
env:
fail-fast: true
- name: Code style (phpcs)
run: phpcs -q --report=checkstyle | cs2pr

php-cs-fixer:
name: Code style (php-cs-fixer)
name: Coding standard (php-cs-fixer)
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.3'
coverage: none
tools: composer:v2, cs2pr, php-cs-fixer
tools: cs2pr, php-cs-fixer
env:
fail-fast: true
- name: Code style (php-cs-fixer)
Expand All @@ -51,20 +51,20 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.3'
coverage: none
tools: composer:v2, phpstan
env:
fail-fast: true
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -79,51 +79,53 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.3'
coverage: none
tools: composer:v2, psalm
env:
fail-fast: true
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install project dependencies
run: composer upgrade --no-interaction --no-progress --prefer-dist
- name: Psalm version
run: psalm --version
- name: Psalm
run: psalm --no-progress

tests:
name: Tests on PHP ${{ matrix.php-versions }}
name: Tests on PHP ${{ matrix.php-version }}
runs-on: "ubuntu-latest"
strategy:
matrix:
php-versions: ['7.3', '7.4', '8.0', '8.1']
php-version: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: ${{ matrix.php-version }}
coverage: none
tools: composer:v2
env:
fail-fast: true
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand Down
10 changes: 5 additions & 5 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpcs" version="^3.6.2" installed="3.6.2" location="./tools/phpcs" copy="false"/>
<phar name="phpcbf" version="^3.6.2" installed="3.6.2" location="./tools/phpcbf" copy="false"/>
<phar name="php-cs-fixer" version="^3.7.0" installed="3.7.0" location="./tools/php-cs-fixer" copy="false"/>
<phar name="phpstan" version="^1.4.8" installed="1.4.8" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="^4.22.0" installed="4.22.0" location="./tools/psalm" copy="false"/>
<phar name="phpcs" version="^3.9.0" installed="3.9.0" location="./tools/phpcs" copy="false"/>
<phar name="phpcbf" version="^3.9.0" installed="3.9.0" location="./tools/phpcbf" copy="false"/>
<phar name="php-cs-fixer" version="^3.51.0" installed="3.51.0" location="./tools/php-cs-fixer" copy="false"/>
<phar name="phpstan" version="^1.10.60" installed="1.10.60" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="^5.22.2" installed="5.22.2" location="./tools/psalm" copy="false"/>
</phive>
9 changes: 6 additions & 3 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,32 @@
'whitespace_after_comma_in_array' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'function_typehint_space' => true,
'type_declaration_spaces' => true,
'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arrays', 'match']],
'no_blank_lines_after_phpdoc' => true,
'object_operator_without_whitespace' => true,
'binary_operator_spaces' => true,
'phpdoc_scalar' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_comma_in_singleline' => true,
'single_quote' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_unused_imports' => true,
'yoda_style' => ['equal' => true, 'identical' => true, 'less_and_greater' => null],
'standardize_not_equals' => true,
'concat_space' => ['spacing' => 'one'],
'linebreak_after_opening_tag' => true,
'fully_qualified_strict_types' => true,
// symfony:risky
'no_alias_functions' => true,
'self_accessor' => true,
// contrib
'not_operator_with_successor_space' => true,
'ordered_imports' => ['imports_order' => ['class', 'function', 'const']], // @PSR12 sort_algorithm: none
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->append([__FILE__])
->exclude(['tools', 'vendor', 'build'])
->exclude(['tools', 'vendor', 'build']),
)
;
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 - 2022 Carlos C Soto
Copyright (c) 2016 - 2024 Carlos C Soto https://eclipxe.com.mx/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Please, try to use the full potential of the language.
## Contributing

Contributions are welcome! Please read [CONTRIBUTING][] for details
and don't forget to take a look in the [TODO][] and [CHANGELOG][] files.
and don't forget to take a look the [TODO][] and [CHANGELOG][] files.

## Copyright and License

Expand All @@ -92,7 +92,7 @@ and licensed for use under the MIT License (MIT). Please see [LICENSE][] for mor
[badge-php-version]: https://img.shields.io/packagist/php-v/eclipxe/XmlResourceRetriever?style=flat-square
[badge-release]: https://img.shields.io/github/release/eclipxe13/XmlResourceRetriever?style=flat-square
[badge-license]: https://img.shields.io/github/license/eclipxe13/XmlResourceRetriever?style=flat-square
[badge-build]: https://img.shields.io/github/workflow/status/eclipxe13/XmlResourceRetriever/build/main?style=flat-square
[badge-build]: https://img.shields.io/github/actions/workflow/status/eclipxe13/XmlResourceRetriever/build.yml?branch=main&style=flat-square
[badge-quality]: https://img.shields.io/scrutinizer/g/eclipxe13/XmlResourceRetriever/main?style=flat-square
[badge-coverage]: https://img.shields.io/scrutinizer/coverage/g/eclipxe13/XmlResourceRetriever/main?style=flat-square
[badge-downloads]: https://img.shields.io/packagist/dt/eclipxe/XmlResourceRetriever?style=flat-square
18 changes: 17 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
# eclipxe/XmlResourceRetriever Changelog
# eclipxe/XmlResourceRetriever Changelog

Notice: This library follows [SEMVER 2.0.0](https://semver.org/spec/v2.0.0.html) convention.

## Version 2.0.2 2022-03-08

- Improve code and fix issues from psalm avoiding falsy comparisons.
- Update license year to 2024 and add owner URL.
- Fix build bagde.
- Update coding standards.
- For GitHub workflow:
- Run jobs using PHP 8.3.
- Add PHP 8.2 and PHP 8.3 to test matrix.
- Remove composer tool installation where is not required.
- Update GitHub actions to version 4.
- Replace GitHub directive `::set-output` with `$GITHUB_OUTPUT`.
- Rename php-version matrix variable name (singular).
- Display PSalm version before run.
- Update development tools.

## Unreleased 2022-03-08

- Fix build because PHPStan needs type specification on `DOMNodeList`.
Expand Down
3 changes: 2 additions & 1 deletion docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

The following changes produces a BC break. Requires a new major version.

- Add return type `void` on `DownloaderInterface::downloadTo`.
- Add `DownloaderInterface::downloadTo` return type `void`.
- Remove `'void_return' => false,` rule in `php-cs-fixer` configuration file.
55 changes: 26 additions & 29 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
name="Personal"
>
<description>Personal coding standard.</description>
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Personal">
<description>Personal coding standard.</description>

<arg name="tab-width" value="4"/>
<arg name="encoding" value="utf-8"/>
<arg name="report-width" value="auto"/>
<arg name="extensions" value="php"/>
<arg name="cache" value="build/phpcs.cache"/>
<arg name="tab-width" value="4"/>
<arg name="encoding" value="utf-8"/>
<arg name="report-width" value="auto"/>
<arg name="extensions" value="php"/>
<arg name="cache" value="build/phpcs.cache"/>

<file>src/</file>
<file>tests/</file>
<file>src/</file>
<file>tests/</file>

<rule ref="PSR12"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
<rule ref="Generic.Formatting.SpaceAfterNot"/>
<rule ref="Generic.Functions.CallTimePassByReference"/>
<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Squiz.PHP.DisallowSizeFunctionsInLoops"/>
<rule ref="Squiz.Scope.MemberVarScope"/>
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.OperatorSpacing"/>
<rule ref="Zend.Files.ClosingTag"/>
<rule ref="PSR12"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
<rule ref="Generic.Formatting.SpaceAfterNot"/>
<rule ref="Generic.Functions.CallTimePassByReference"/>
<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Squiz.PHP.DisallowSizeFunctionsInLoops"/>
<rule ref="Squiz.Scope.MemberVarScope"/>
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.OperatorSpacing"/>
<rule ref="Zend.Files.ClosingTag"/>
</ruleset>
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
cacheResultFile="build/phpunit.result.cache"
Expand Down
7 changes: 5 additions & 2 deletions src/AbstractXmlRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected function checkIsValidDownloadedFile(string $source, string $localpath)
throw new RuntimeException("The source $source is not an xml file because it is empty");
}
// check content is xml
$mimetype = (new finfo())->file($localpath, FILEINFO_MIME_TYPE) ?: '';
$mimetype = strval((new finfo())->file($localpath, FILEINFO_MIME_TYPE));
if ('application/xml' !== $mimetype && 'text/' !== substr($mimetype, 0, 5)) {
unlink($localpath);
throw new RuntimeException("The source $source ($mimetype) is not an xml file");
Expand All @@ -137,7 +137,10 @@ private function relativeToAbsoluteUrl(string $url, string $currentUrl): string
if (false !== $this->urlParts($url)) {
return $url;
}
$currentParts = $this->urlParts($currentUrl) ?: [];
$currentParts = $this->urlParts($currentUrl);
if (false === $currentParts) {

Check notice on line 141 in src/AbstractXmlRetriever.php

View check run for this annotation

Scrutinizer / Inspection

src/AbstractXmlRetriever.php#L141

The condition ``false === $currentParts`` is always ``true``.
$currentParts = [];
}
$currentParts['port'] = $currentParts['port'] ?? '';
$currentParts['port'] = ('' !== $currentParts['port']) ? ':' . $currentParts['port'] : '';
return implode('', [
Expand Down
7 changes: 4 additions & 3 deletions tests/public/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# About public resources

This folder is used to perform tests, is the public root folder for PHP intetnal web server.

```shell
php -S 127.0.0.1:8999 -t tests/public/
```

As I was unable to create complex structures for XSD and XSLT files-
I had taken from Mexico SAT Goverment:
As I was unable to create complex structures for XSD and XSLT files I had taken from Mexico SAT Government:

- http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd
- http://www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_3/cadenaoriginal_3_3.xslt
Expand All @@ -29,4 +30,4 @@ wget -O - -q sat-urls.txt http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd
echo http://www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_3/cadenaoriginal_3_3.xslt >> sat-urls.txt
wget -O - -q sat-urls.txt http://www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_3/cadenaoriginal_3_3.xslt \
| grep -o -P 'http://www.sat.gob.mx/\S*?xslt' >> sat-urls.txt
```
```

0 comments on commit 0e54747

Please sign in to comment.