Skip to content

Commit a40ba55

Browse files
committed
Version 1.0.3
2 parents 0570c70 + befd8b4 commit a40ba55

File tree

6 files changed

+62
-15
lines changed

6 files changed

+62
-15
lines changed

.travis.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ language: php
44
php:
55
- 7.0
66
- 7.1
7-
- nightly
8-
9-
matrix:
10-
allow_failures:
11-
- php: nightly
127

138
# This triggers builds to run on the new TravisCI infrastructure.
149
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/

docs/CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
1+
# Version 1.0.3 2017-10-09
2+
- Fix a bug to read the RFC when a certificate does not contain the pattern RFC / CURP but only RFC in the
3+
subject x500UniqueIdentifier field
4+
5+
6+
# Version 1.0.2 2017-09-28 - Thanks phpstan!
7+
- After using `phpstan/phpstan` change the execution plan on `CadenaOrigen`.
8+
The function previous function `throwLibXmlErrorOrMessage(string $message)` always
9+
throw an exception but it was not clear in the flow of `build` method.
10+
Now it returns a \RuntimeException and that is thrown. So it is easy for an analysis tool
11+
to know that the flow has been stopped.
12+
- Also fix case of calls `XSLTProcessor::importStylesheet` and `XSLTProcessor::transformToXml`
13+
- Check with `isset` that `LibXMLError::$message` exists, phpstan was failing for this.
14+
15+
16+
# Version 1.0.1 2017-09-27
17+
- Remove Travis CI PHP nightly builds, it fail with require-dev dependencies.
18+
19+
120
# Version 1.0.0 2017-09-27
221
- Initial release

src/CfdiUtils/CadenaOrigen.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function build(string $cfdiContent, string $xsltLocation = ''): string
4747
// load the cfdi document
4848
$cfdi = new DOMDocument();
4949
if (! $cfdi->loadXML($cfdiContent)) {
50-
$this->throwLibXmlErrorOrMessage('Error while loading the cfdi content');
50+
throw $this->createLibXmlErrorOrMessage('Error while loading the cfdi content');
5151
}
5252

5353
// if not set, obtain default location from document version
@@ -61,18 +61,18 @@ public function build(string $cfdiContent, string $xsltLocation = ''): string
6161

6262
$xsl = new DOMDocument();
6363
if (! $xsl->load($xsltLocation)) {
64-
$this->throwLibXmlErrorOrMessage('Error while loading the Xslt location');
64+
throw $this->createLibXmlErrorOrMessage('Error while loading the Xslt location');
6565
}
6666

6767
$xslt = new XSLTProcessor();
68-
if (! $xslt->importStyleSheet($xsl)) {
69-
$this->throwLibXmlErrorOrMessage('Error while importing the style sheet from the Xslt location');
68+
if (! $xslt->importStylesheet($xsl)) {
69+
throw $this->createLibXmlErrorOrMessage('Error while importing the style sheet from the Xslt location');
7070
}
7171

7272
// this error silenced call is intentional, avoid transformation errors except when return false
73-
$transform = @$xslt->transformToXML($cfdi);
73+
$transform = @$xslt->transformToXml($cfdi);
7474
if (false === $transform || null === $transform) {
75-
$this->throwLibXmlErrorOrMessage('Error while transforming the xslt content');
75+
throw $this->createLibXmlErrorOrMessage('Error while transforming the xslt content');
7676
}
7777

7878
return $transform;
@@ -82,12 +82,12 @@ public function build(string $cfdiContent, string $xsltLocation = ''): string
8282
}
8383
}
8484

85-
private function throwLibXmlErrorOrMessage(string $message)
85+
private function createLibXmlErrorOrMessage(string $message): \Exception
8686
{
8787
$error = libxml_get_last_error();
88-
if ($error instanceof LibXMLError) {
88+
if (($error instanceof LibXMLError) && isset($error->message)) {
8989
$message = $message . ': ' . $error->message;
9090
}
91-
throw new \RuntimeException($message);
91+
return new \RuntimeException($message);
9292
}
9393
}

src/CfdiUtils/Certificado.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(string $filename)
5252
}
5353

5454
// set all the values
55-
$this->rfc = strstr($data['subject']['x500UniqueIdentifier'], ' ', true);
55+
$this->rfc = strstr($data['subject']['x500UniqueIdentifier'] . ' ', ' ', true);
5656
$this->name = $data['subject']['name'];
5757
$this->serial = $this->serialHexToAscii($data['serialNumberHex']);
5858
$this->validFrom = $data['validFrom_time_t'];

tests/CfdiUtilsTests/CertificadoTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,11 @@ public function testBelongsToWithEmptyFile()
154154

155155
$certificate->belongsTo($pemKeyFile);
156156
}
157+
158+
public function testCanReadRfcFromCertificateWhenX500UniqueIdentifierOnlyContainsRfcAndNoCurp()
159+
{
160+
$certificateFile = $this->utilAsset('certs/00001000000301246267.cer');
161+
$certificate = new Certificado($certificateFile);
162+
$this->assertEquals('SOMG790807J57', $certificate->getRfc());
163+
}
157164
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIEYTCCA0mgAwIBAgIUMDAwMDEwMDAwMDAzMDEyNDYyNjcwDQYJKoZIhvcNAQEF
3+
BQAwggGKMTgwNgYDVQQDDC9BLkMuIGRlbCBTZXJ2aWNpbyBkZSBBZG1pbmlzdHJh
4+
Y2nDs24gVHJpYnV0YXJpYTEvMC0GA1UECgwmU2VydmljaW8gZGUgQWRtaW5pc3Ry
5+
YWNpw7NuIFRyaWJ1dGFyaWExODA2BgNVBAsML0FkbWluaXN0cmFjacOzbiBkZSBT
6+
ZWd1cmlkYWQgZGUgbGEgSW5mb3JtYWNpw7NuMR8wHQYJKoZIhvcNAQkBFhBhY29k
7+
c0BzYXQuZ29iLm14MSYwJAYDVQQJDB1Bdi4gSGlkYWxnbyA3NywgQ29sLiBHdWVy
8+
cmVybzEOMAwGA1UEEQwFMDYzMDAxCzAJBgNVBAYTAk1YMRkwFwYDVQQIDBBEaXN0
9+
cml0byBGZWRlcmFsMRQwEgYDVQQHDAtDdWF1aHTDqW1vYzEVMBMGA1UELRMMU0FU
10+
OTcwNzAxTk4zMTUwMwYJKoZIhvcNAQkCDCZSZXNwb25zYWJsZTogQ2xhdWRpYSBD
11+
b3ZhcnJ1YmlhcyBPY2hvYTAeFw0xMzExMDcxNTQ1MDFaF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