Skip to content

Commit 00fe9b2

Browse files
authored
Merge pull request #4 from eclipxe13/master
Version 3.0.0
2 parents db68502 + f39e062 commit 00fe9b2

19 files changed

+124
-67
lines changed

.gitattributes

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33

44
# Do not put this files on a distribution package (by .gitignore)
55
/vendor export-ignore
6-
/build export-ignore
76
/composer.lock export-ignore
87

98
# Do not put this files on a distribution package
10-
/docs/ export-ignore
9+
/build/ export-ignore
1110
/tests/ export-ignore
1211
/.gitattributes export-ignore
1312
/.gitignore export-ignore

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
# do not include this files on git
22
/vendor
3-
/build
43
/composer.lock
5-
.phpunit.result.cache

.phplint.yml

-11
This file was deleted.

.scrutinizer.yml

-6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@ filter:
66
build:
77
nodes:
88
analysis:
9-
environment:
10-
php:
11-
version: "7.3"
12-
project_setup:
13-
override: true
149
tests:
1510
override:
1611
- php-scrutinizer-run --enable-security-analysis
17-
- phpcs-run --standard=phpcs.xml.dist src/ tests/
1812
- command: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
1913
coverage:
2014
file: coverage.clover

.travis.yml

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
language: php
22

3-
# This triggers builds to run on the new TravisCI infrastructure.
4-
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
5-
sudo: false
6-
73
# php compatibility
84
php:
95
- "7.2"
106
- "7.3"
7+
- "7.4snapshot"
8+
9+
matrix:
10+
allow_failures:
11+
- php: "7.4snapshot"
12+
13+
env:
14+
global:
15+
- PHP_CS_FIXER_FUTURE_MODE=1
16+
- PHP_CS_FIXER_IGNORE_ENV=1
1117

1218
cache:
1319
- directories:
1420
- $HOME/.composer
1521

1622
before_script:
23+
- phpenv config-rm xdebug.ini || true
1724
- travis_retry composer install --no-interaction --prefer-dist
18-
- phpenv config-rm xdebug.ini
19-
- mkdir -p build
2025

2126
script:
22-
- vendor/bin/phplint
23-
- vendor/bin/php-cs-fixer fix --verbose
27+
- vendor/bin/php-cs-fixer fix --dry-run --verbose
2428
- vendor/bin/phpcbf --colors -sp src/ tests/
2529
- vendor/bin/phpunit --testdox --verbose
26-
- vendor/bin/phpstan.phar analyse --no-progress --level max src/ tests/
30+
- vendor/bin/phpstan analyse --no-progress --verbose --level max src/ tests/
2731

2832
notifications:
2933
email: false

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ By participating in this project and its community, you are expected to uphold t
99
## Team members
1010

1111
* [Carlos C Soto](https://github.com/eclipxe13) - original author and maintainer
12-
* [GitHub constributors](https://github.com/phpcfdi/cfdi-expresiones/graphs/contributors)
12+
* [GitHub contributors](https://github.com/phpcfdi/cfdi-expresiones/graphs/contributors)
1313

1414
## Communication Channels
1515

@@ -75,8 +75,8 @@ If any of these do not pass, it will result in a complete build failure.
7575
Before you can run these, be sure to `composer install` or `composer update`.
7676

7777
```shell
78-
vendor/bin/parallel-lint src/ tests/
7978
vendor/bin/phpcs -sp src/ tests/
8079
vendor/bin/php-cs-fixer fix -v --dry-run
8180
vendor/bin/phpunit --coverage-text
81+
vendor/bin/phpstan analyse --level max src/ tests/
8282
```

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2019 Carlos C Soto
3+
Copyright (c) 2019 PHPCFDI
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ Ejemplo de expresión para RET 1.0:
4040
?&re=XAXX010101000&nr=12345678901234567890%tt=1234567890.123456&id=ad662d33-6934-459c-a128-BDf0393f0f44
4141
```
4242

43-
4443
## Instalación
4544

4645
Usa [composer](https://getcomposer.org/)
@@ -74,19 +73,21 @@ Esta librería se mantendrá compatible con al menos la versión con
7473
También utilizamos [Versionado Semántico 2.0.0](https://semver.org/lang/es/) por lo que puedes usar esta librería
7574
sin temor a romper tu aplicación.
7675

76+
### Cambiar de la versión 2.0.0 a la versión 3.0.0
77+
78+
La versión `3.0.0` agrega un método a la interfaz `ExpressionExtractorInterface` por lo que es necesario crear una
79+
versión mayor. Puedes actualizar con confianza si no creaste alguna clase que implemente `ExpressionExtractorInterface`.
7780

7881
## Contribuciones
7982

8083
Las contribuciones con bienvenidas. Por favor lee [CONTRIBUTING][] para más detalles
8184
y recuerda revisar el archivo de tareas pendientes [TODO][] y el [CHANGELOG][].
8285

83-
8486
## Copyright and License
8587

86-
The phpcfdi/cfdi-expresiones library is copyright © [Carlos C Soto](http://eclipxe.com.mx/)
88+
The phpcfdi/cfdi-expresiones library is copyright © [PhpCfdi](https://www.phpcfdi.com/)
8789
and licensed for use under the MIT License (MIT). Please see [LICENSE][] for more information.
8890

89-
9091
[contributing]: https://github.com/phpcfdi/cfdi-expresiones/blob/master/CONTRIBUTING.md
9192
[changelog]: https://github.com/phpcfdi/cfdi-expresiones/blob/master/docs/CHANGELOG.md
9293
[todo]: https://github.com/phpcfdi/cfdi-expresiones/blob/master/docs/TODO.md
@@ -99,9 +100,9 @@ and licensed for use under the MIT License (MIT). Please see [LICENSE][] for mor
99100
[coverage]: https://scrutinizer-ci.com/g/phpcfdi/cfdi-expresiones/code-structure/master/code-coverage
100101
[downloads]: https://packagist.org/packages/phpcfdi/cfdi-expresiones
101102

102-
[badge-source]: http://img.shields.io/badge/source-phpcfdi/cfdi--expresiones-blue.svg?style=flat-square
103+
[badge-source]: https://img.shields.io/badge/source-phpcfdi/cfdi--expresiones-blue.svg?style=flat-square
103104
[badge-release]: https://img.shields.io/github/release/phpcfdi/cfdi-expresiones.svg?style=flat-square
104-
[badge-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
105+
[badge-license]: https://img.shields.io/github/license/phpcfdi/cfdi-expresiones.svg?style=flat-square
105106
[badge-build]: https://img.shields.io/travis/phpcfdi/cfdi-expresiones/master.svg?style=flat-square
106107
[badge-quality]: https://img.shields.io/scrutinizer/g/phpcfdi/cfdi-expresiones/master.svg?style=flat-square
107108
[badge-coverage]: https://img.shields.io/scrutinizer/coverage/g/phpcfdi/cfdi-expresiones/master.svg?style=flat-square

build/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

composer.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
"ext-dom": "*"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "^8.0",
31-
"overtrue/phplint": "^1.0",
30+
"phpunit/phpunit": "^8.4",
3231
"squizlabs/php_codesniffer": "^3.0",
3332
"friendsofphp/php-cs-fixer": "^2.4",
3433
"phpstan/phpstan-shim": "^0.11"
@@ -54,10 +53,9 @@
5453
"vendor/bin/phpcbf --colors -sp src/ tests/"
5554
],
5655
"dev:test": [
57-
"vendor/bin/phplint",
56+
"@dev:check-style",
5857
"vendor/bin/phpunit --testdox --verbose --stop-on-failure",
59-
"find . -type f -name .phpunit.result.cache -delete",
60-
"vendor/bin/phpstan analyse --verbose --level max src/ tests/"
58+
"vendor/bin/phpstan analyse --verbose --no-progress --level max src/ tests/"
6159
],
6260
"dev:coverage": [
6361
"@php -dzend_extension=xdebug.so vendor/bin/phpunit --coverage-text --coverage-html build/coverage/html/"
@@ -67,7 +65,7 @@
6765
"dev:build": "DEV: run dev:fix-style dev:tests and dev:docs, run before pull request",
6866
"dev:check-style": "DEV: search for code style errors using php-cs-fixer and phpcs",
6967
"dev:fix-style": "DEV: fix code style errors using php-cs-fixer and phpcbf",
70-
"dev:test": "DEV: run phplint, phpunit and phpstan",
68+
"dev:test": "DEV: run dev:check-style, phpunit and phpstan",
7169
"dev:coverage": "DEV: run phpunit with xdebug and storage coverage in build/coverage/html/"
7270
}
7371
}

docs/CHANGELOG.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# CHANGELOG
22

3+
Notice: This library follows [SEMVER 2.0.0](https://semver.org/spec/v2.0.0.html) convention.
4+
5+
## Version 3.0.0 2019-10-24
6+
7+
You should not have any trouble upgrading to from version `2.0.0` to `3.0.0` unless you are creating a concrete
8+
class that implements `ExpressionExtractorInterface`.
9+
10+
- [BC] Change interface of `ExpressionExtractorInterface` to add a new method `obtain(DOMDocument $document): array`
11+
that returns the extracted values, this change remove this responsability from `extract` method.
12+
- [BC] Change `DiscoverExtractor::format()`, second argument must be `string`, was `mixed`.
13+
- Update continuous integration and development environment, mayor changes:
14+
- Travis build on PHP version `7.4snapshot`.
15+
- Scrutinizer decides which PHP version to run.
16+
- Remove `overtrue/phplint`.
17+
318
## Version 2.0.0 2019-03-28
419

520
- Allows to create an expression with format fixes from specific types
@@ -11,7 +26,6 @@
1126
- `Retenciones10` uses `RET10`
1227
- Rename `ExpressionExtractor` to `DiscoverExtractor`, it makes more sense
1328

14-
1529
## Version 1.0.0 2019-03-27
1630

1731
- Create this package as is a common use between other packages

docs/TODO.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# phpcfdi/cfdi-expresiones To Do List
22

3-
- Poner el copyright correcto en cuanto esté el sitio de PhpCfdi
3+
- 2019-10-24: Nada pendiente aún.

phpunit.xml.dist

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.0/phpunit.xsd"
3-
bootstrap="./tests/bootstrap.php" colors="true" verbose="true" cacheTokens="false">
2+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.4/phpunit.xsd"
3+
bootstrap="./tests/bootstrap.php" colors="true" verbose="true" cacheResultFile="build/phpunit.result.cache">
44
<testsuites>
55
<testsuite name="Default">
66
<directory>./tests/</directory>

src/DiscoverExtractor.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ public function __construct(ExpressionExtractorInterface ...$expressions)
2323
$this->expressions = $expressions;
2424
}
2525

26-
/**
27-
* @return ExpressionExtractorInterface[];
28-
*/
26+
/** @return ExpressionExtractorInterface[] */
2927
public function defaultExtractors(): array
3028
{
3129
return [
@@ -80,13 +78,19 @@ public function uniqueName(): string
8078
return 'discover';
8179
}
8280

81+
public function obtain(DOMDocument $document): array
82+
{
83+
$discovered = $this->getFirstMatch($document);
84+
return $discovered->obtain($document);
85+
}
86+
8387
public function extract(DOMDocument $document): string
8488
{
8589
$discovered = $this->getFirstMatch($document);
8690
return $discovered->extract($document);
8791
}
8892

89-
public function format(array $values, $type = ''): string
93+
public function format(array $values, string $type = ''): string
9094
{
9195
$extractor = $this->findByUniqueName($type);
9296
if (null === $extractor) {

src/ExpressionExtractorInterface.php

+25
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,35 @@
88

99
interface ExpressionExtractorInterface
1010
{
11+
/**
12+
* Extractor (implementor) unique name
13+
*
14+
* @return string
15+
*/
1116
public function uniqueName(): string;
1217

18+
/**
19+
* Check that the XML document matches with the extractor
20+
*
21+
* @param DOMDocument $document
22+
* @return bool
23+
*/
1324
public function matches(DOMDocument $document): bool;
1425

26+
/**
27+
* Obtain the relevant values from the given XML Document
28+
*
29+
* @param DOMDocument $document
30+
* @return array
31+
*/
32+
public function obtain(DOMDocument $document): array;
33+
34+
/**
35+
* Format an expression based on given XML document
36+
*
37+
* @param DOMDocument $document
38+
* @return string
39+
*/
1540
public function extract(DOMDocument $document): string;
1641

1742
/**

src/Extractors/Comprobante32.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function matches(DOMDocument $document): bool
3030
return $this->matchDetector->matches($document);
3131
}
3232

33-
public function extract(DOMDocument $document): string
33+
public function obtain(DOMDocument $document): array
3434
{
3535
if (! $this->matches($document)) {
3636
throw new UnmatchedDocumentException('The document is not a CFDI 3.2');
@@ -42,12 +42,17 @@ public function extract(DOMDocument $document): string
4242
$rfcReceptor = $helper->getAttribute('cfdi:Comprobante', 'cfdi:Receptor', 'rfc');
4343
$total = $helper->getAttribute('cfdi:Comprobante', 'total');
4444

45-
return $this->format([
45+
return [
4646
're' => $rfcEmisor,
4747
'rr' => $rfcReceptor,
4848
'tt' => $total,
4949
'id' => $uuid,
50-
]);
50+
];
51+
}
52+
53+
public function extract(DOMDocument $document): string
54+
{
55+
return $this->format($this->obtain($document));
5156
}
5257

5358
public function format(array $values): string

src/Extractors/Comprobante33.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function matches(DOMDocument $document): bool
3030
return $this->matchDetector->matches($document);
3131
}
3232

33-
public function extract(DOMDocument $document): string
33+
public function obtain(DOMDocument $document): array
3434
{
3535
if (! $this->matches($document)) {
3636
throw new UnmatchedDocumentException('The document is not a CFDI 3.3');
@@ -43,13 +43,18 @@ public function extract(DOMDocument $document): string
4343
$total = $helper->getAttribute('cfdi:Comprobante', 'Total');
4444
$sello = substr($helper->getAttribute('cfdi:Comprobante', 'Sello'), -8);
4545

46-
return $this->format([
46+
return [
4747
'id' => $uuid,
4848
're' => $rfcEmisor,
4949
'rr' => $rfcReceptor,
5050
'tt' => $total,
51-
'fe' => substr($sello, -8),
52-
]);
51+
'fe' => $sello,
52+
];
53+
}
54+
55+
public function extract(DOMDocument $document): string
56+
{
57+
return $this->format($this->obtain($document));
5358
}
5459

5560
public function format(array $values): string

src/Extractors/Retenciones10.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function matches(DOMDocument $document): bool
3636
return $this->matchDetector->matches($document);
3737
}
3838

39-
public function extract(DOMDocument $document): string
39+
public function obtain(DOMDocument $document): array
4040
{
4141
if (! $this->matches($document)) {
4242
throw new UnmatchedDocumentException('The document is not a RET 1.0');
@@ -81,12 +81,17 @@ public function extract(DOMDocument $document): string
8181
$helper->getAttribute('retenciones:Retenciones', 'retenciones:Totales', 'montoTotOperacion')
8282
);
8383

84-
return $this->format([
84+
return [
8585
're' => $rfcEmisor,
8686
$rfcReceptorKey => $rfcReceptor,
8787
'tt' => $this->formatTotal($total),
8888
'id' => $uuid,
89-
]);
89+
];
90+
}
91+
92+
public function extract(DOMDocument $document): string
93+
{
94+
return $this->format($this->obtain($document));
9095
}
9196

9297
public function format(array $values): string

0 commit comments

Comments
 (0)