Skip to content

Commit

Permalink
add error codes repo
Browse files Browse the repository at this point in the history
  • Loading branch information
giansalex committed Jan 28, 2018
0 parents commit 5041e19
Show file tree
Hide file tree
Showing 11 changed files with 1,443 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php_cs.dist export-ignore
.travis.yml export-ignore
LICENSE export-ignore
phpunit.xml export-ignore
README.md export-ignore
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.idea/
/build/
/vendor/
/composer.lock
.DS_Store
.php_cs.cache
23 changes: 23 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

$config = PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'@PSR1' => true,
'@PSR2' => true,
'yoda_style' => false
]);
// special handling of fabbot.io service if it's using too old PHP CS Fixer version
try {
PhpCsFixer\FixerFactory::create()
->registerBuiltInFixers()
->registerCustomFixers($config->getCustomFixers())
->useRuleSet(new PhpCsFixer\RuleSet($config->getRules()));
} catch (PhpCsFixer\ConfigurationException\InvalidConfigurationException $e) {
$config->setRules([]);
} catch (UnexpectedValueException $e) {
$config->setRules([]);
} catch (InvalidArgumentException $e) {
$config->setRules([]);
}
return $config;
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: php

php:
- 5.6
- 7.0

before_script:
- composer self-update
- composer install --prefer-source --no-interaction

install:
- composer require php-coveralls/php-coveralls

script:
- mkdir -p build/logs
- vendor/bin/phpunit --configuration phpunit.xml --coverage-clover build/logs/clover.xml

after_success:
- travis_retry php vendor/bin/php-coveralls -v


21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Giancarlos Salas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# XCodes - Greenter

[![Travis-CI](https://img.shields.io/travis/giansalex/greenter-ws.svg?label=build&branch=master&style=flat-square)](https://travis-ci.org/giansalex/greenter-ws)
[![Coverage Status](https://img.shields.io/coveralls/giansalex/greenter-ws.svg?label=coveralls&style=flat-square&branch=master)](https://coveralls.io/github/giansalex/greenter-ws?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/64cabd82882a461dbf82bdeb6accbc13)](https://www.codacy.com/app/giansalex/greenter-ws?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=giansalex/greenter-ws&amp;utm_campaign=Badge_Grade)
Códigos de Error en Facturación Electrónica SUNAT.

# Install
Via Composer from [packagist.org](https://packagist.org/packages/greenter/xcodes).
```bash
composer require greenter/xcodes
```
31 changes: 31 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "greenter/xcodes",
"description": "Códigos de Error en Facturación Electrónica SUNAT - Perú",
"keywords": ["greenter", "error-codes", "sunat", "facturacion electronica"],
"license": "MIT",
"authors": [
{
"name": "Giancarlos Salas",
"email": "[email protected]"
}
],
"homepage": "https://github.com/giansalex/greenter-xcodes",
"type": "library",
"require": {
"php": ">=5.5.9",
"greenter/core": "dev-master"
},
"require-dev": {
"phpunit/phpunit": ">=4.8 < 6.0"
},
"autoload": {
"psr-4": {
"Greenter\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\Greenter\\": "tests/"
}
}
}
28 changes: 28 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="true">
<testsuites>
<testsuite name="Unit Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
</phpunit>
67 changes: 67 additions & 0 deletions src/Validator/XmlErrorCodeProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Greenter\Validator;

/**
* Class XmlErrorCodeProvider.
*/
class XmlErrorCodeProvider implements ErrorCodeProviderInterface
{
private $xmlErrorFile;

/**
* XmlErrorCodeProvider constructor.
*/
public function __construct()
{
$this->xmlErrorFile = __DIR__.'/../data/CodeErrors.xml';
}

/**
* Get all codes and messages.
*
* @return array
*/
public function getAll()
{
$xpath = $this->getXpath();
$nodes = $xpath->query('/errors/error');

$items = [];
foreach ($nodes as $node) {
/** @var $node \DOMElement */
$key = $node->getAttribute('code');
$items[$key] = $node->nodeValue;
}

return $items;
}

/**
* Get Error Message by code.
*
* @param string $code
*
* @return string
*/
public function getValue($code)
{
$xpath = $this->getXpath();
$nodes = $xpath->query("/errors/error[@code='$code']");

if ($nodes->length !== 1) {
return '';
}

return $nodes[0]->nodeValue;
}

private function getXpath()
{
$doc = new \DOMDocument();
$doc->load($this->xmlErrorFile);
$xpath = new \DOMXPath($doc);

return $xpath;
}
}
Loading

0 comments on commit 5041e19

Please sign in to comment.