Skip to content

Commit 16c29e1

Browse files
committed
# v1.0.0 - 2021-08-25
1 parent b6e6647 commit 16c29e1

13 files changed

+505
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
/.idea

.styleci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
preset: laravel

README.md

+177-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,177 @@
1-
# ChileanRutPHP
2-
ChileanRutPHP
1+
# ChileanRut
2+
3+
[![Latest Version on Packagist][ico-version]][link-packagist]
4+
[![Total Downloads][ico-downloads]][link-downloads]
5+
[![Build Status][ico-travis]][link-travis]
6+
[![StyleCI][ico-styleci]][link-styleci]
7+
8+
A Chilean Rut script to handle ruts. Take a look at [contributing.md](contributing.md) to see a to do list.
9+
10+
## Installation
11+
12+
Via Composer
13+
14+
``` bash
15+
$ composer require innovaweb/chileanrut
16+
```
17+
18+
## Usage
19+
20+
### Format Function
21+
Format the rut according to the assigned parameters, if withDotted is true it will always return with a hyphen, return string value
22+
23+
| Params | Type | Description |
24+
| --- | --- | --- |
25+
| $rut | string | rut with any of these formats 11.111.111-1, 11111111-1, 111111111 |
26+
| $withDotted | bool | return rut with dots format, default true |
27+
| $withHyphen | bool | return rut with hyphen format. default true |
28+
```php
29+
Rut::format('123123123'); // return 12.312.312-3
30+
Rut::format('123123123', false); // return 12312312-3
31+
Rut::format('123123123', false, false); // return 123123123 (it is best to use the unformat function)
32+
```
33+
34+
### Unformat Function
35+
Clean the rut of spaces, dots and hyphens, return string value
36+
37+
| Params | Type | Description |
38+
| --- | --- | --- |
39+
| $rut | string | rut with any of these formats 11.111.111-1, 11111111-1, 111111111 |
40+
41+
```php
42+
Rut::unformat('12.312.312-3'); // return 123123123
43+
```
44+
45+
### Validate Function
46+
Check if the code is valid with the validation algorithm, return boolean value
47+
48+
| Params | Type | Description |
49+
| --- | --- | --- |
50+
| $rut | string | rut with any of these formats 11.111.111-1, 11111111-1, 111111111 |
51+
52+
```php
53+
Rut::validate('12.312.312-3'); // return true
54+
```
55+
56+
### Calculate Dv Function
57+
Calculates the check digit from a sequential rut number, return string value
58+
59+
| Params | Type | Description |
60+
| --- | --- | --- |
61+
| $number | int | only the number of rut as integer type |
62+
63+
```php
64+
Rut::calculateDv('12312312'); // return 3
65+
```
66+
67+
### Get Number Function
68+
Extract the numerical part of the rut, can return with points according to the parameters, return string value
69+
70+
| Params | Type | Description |
71+
| --- | --- | --- |
72+
| $rut | string | rut with any of these formats 11.111.111-1, 11111111-1, 111111111 |
73+
| $withDotted | bool | return rut with dots format, default true |
74+
75+
```php
76+
Rut::getNumber('12312312-3'); // return 12312312
77+
Rut::getNumber('12312312-3', true); // return 12.312.312
78+
```
79+
80+
81+
### Get Dv Function
82+
Extract the check digit part of the rut, return string value
83+
84+
| Params | Type | Description |
85+
| --- | --- | --- |
86+
| $rut | string | rut with any of these formats 11.111.111-1, 11111111-1, 111111111 |
87+
88+
```php
89+
Rut::getDv('12312312-3'); // return 3
90+
```
91+
92+
93+
94+
95+
### Example
96+
````php
97+
namespace App\Http\Controllers;
98+
99+
use Innovaweb\ChileanRut\Rut;
100+
101+
class RutController extends Controller
102+
{
103+
public function index()
104+
{
105+
$format = Rut::format('123123123');
106+
$unformat = Rut::unformat($format);
107+
return [
108+
$format,
109+
$unformat,
110+
Rut::validate($unformat),
111+
Rut::calculateDv(12312312),
112+
Rut::getNumber($format, false),
113+
Rut::getDv($format),
114+
];
115+
}
116+
}
117+
118+
````
119+
Result
120+
```json
121+
[
122+
"12.312.312-3",
123+
"123123123",
124+
true,
125+
"3",
126+
"12312312",
127+
"3"
128+
]
129+
130+
```
131+
132+
## Change log
133+
134+
Please see the [changelog](changelog.md) for more information on what has changed recently.
135+
136+
## Testing
137+
138+
``` bash
139+
$ composer test
140+
```
141+
142+
## Contributing
143+
144+
Please see [contributing.md](contributing.md) for details and a todolist.
145+
146+
## Security
147+
148+
If you discover any security related issues, please email aisla@innovaweb.cl instead of using the issue tracker.
149+
150+
## Credits
151+
152+
- [Alejandro Isla][link-author]
153+
- [All Contributors][link-contributors]
154+
155+
## License
156+
157+
license. Please see the [license file](license.md) for more information.
158+
159+
[ico-version]: https://img.shields.io/packagist/v/innovawebcl/chileanrut.svg?style=flat-square
160+
161+
[ico-downloads]: https://img.shields.io/packagist/dt/innovawebcl/chileanrut.svg?style=flat-square
162+
163+
[ico-travis]: https://img.shields.io/travis/innovawebcl/chileanrut/master.svg?style=flat-square
164+
165+
[ico-styleci]: https://styleci.io/repos/12345678/shield
166+
167+
[link-packagist]: https://packagist.org/packages/innovawebcl/chileanrut
168+
169+
[link-downloads]: https://packagist.org/packages/innovawebcl/chileanrut
170+
171+
[link-travis]: https://travis-ci.org/innovawebcl/chileanrut
172+
173+
[link-styleci]: https://styleci.io/repos/12345678
174+
175+
[link-author]: https://github.com/innovawebcl
176+
177+
[link-contributors]: ../../contributors

changelog.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
3+
All notable changes to `ChileanRut` will be documented in this file.
4+
5+
## v1.0.0 - 2021-08-25
6+
### Added
7+
- format function
8+
- unformat function
9+
- validate function
10+
- calculateDv function
11+
- getNumber function
12+
- getDv function

composer.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "innovaweb/chileanrut",
3+
"description": "A Chilean Rut script to handle ruts",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Alejandro Isla",
8+
"email": "aisla@innovaweb.cl",
9+
"homepage": "https://github.com/willywes",
10+
"role": "Developer"
11+
}
12+
],
13+
"homepage": "https://github.com/innovawebcl/chilean-rut-php",
14+
"keywords": ["Laravel", "ChileanRut", "Rut", "Rut Chileno", "Validar Rut", "Formatear Rut", "Calcular Rut"],
15+
"require": {
16+
"illuminate/support": "~5|~6|~7|~8"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "~9.0",
20+
"orchestra/testbench": "~5|~6"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"Innovaweb\\ChileanRut\\": "src/"
25+
}
26+
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"Innovaweb\\ChileanRut\\Tests\\": "tests"
30+
}
31+
},
32+
"extra": {
33+
"laravel": {
34+
"providers": [
35+
"Innovaweb\\ChileanRut\\ChileanRutServiceProvider"
36+
],
37+
"aliases": {
38+
"ChileanRut": "Innovaweb\\ChileanRut\\Facades\\ChileanRut"
39+
}
40+
}
41+
}
42+
}

config/chileanrut.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
//
5+
];

contributing.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Contributing
2+
3+
Contributions are welcome and will be fully credited.
4+
5+
Contributions are accepted via Pull Requests on [Github](https://github.com/innovaweb/chileanrut).
6+
7+
# Things you could do
8+
If you want to contribute but do not know where to start, this list provides some starting points.
9+
- Add license text
10+
- Remove rewriteRules.php
11+
- Set up TravisCI, StyleCI, ScrutinizerCI
12+
- Write a comprehensive ReadMe
13+
14+
## Pull Requests
15+
16+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
17+
18+
- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date.
19+
20+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
21+
22+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
23+
24+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
25+
26+
27+
**Happy coding**!

LICENSE license.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# The license
2+
13
MIT License
24

35
Copyright (c) 2021 Innovaweb

phpunit.xml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Package">
14+
<directory suffix=".php">./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory>src/</directory>
20+
</whitelist>
21+
</filter>
22+
</phpunit>

src/ChileanRut.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Innovaweb\ChileanRut;
4+
5+
class ChileanRut
6+
{
7+
8+
}

src/ChileanRutServiceProvider.php

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace Innovaweb\ChileanRut;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class ChileanRutServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Perform post-registration booting of services.
11+
*
12+
* @return void
13+
*/
14+
public function boot(): void
15+
{
16+
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'innovaweb');
17+
// $this->loadViewsFrom(__DIR__.'/../resources/views', 'innovaweb');
18+
// $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
19+
// $this->loadRoutesFrom(__DIR__.'/routes.php');
20+
21+
// Publishing is only necessary when using the CLI.
22+
if ($this->app->runningInConsole()) {
23+
$this->bootForConsole();
24+
}
25+
}
26+
27+
/**
28+
* Register any package services.
29+
*
30+
* @return void
31+
*/
32+
public function register(): void
33+
{
34+
$this->mergeConfigFrom(__DIR__.'/../config/chileanrut.php', 'chileanrut');
35+
36+
// Register the service the package provides.
37+
$this->app->singleton('chileanrut', function ($app) {
38+
return new ChileanRut;
39+
});
40+
}
41+
42+
/**
43+
* Get the services provided by the provider.
44+
*
45+
* @return array
46+
*/
47+
public function provides()
48+
{
49+
return ['chileanrut'];
50+
}
51+
52+
/**
53+
* Console-specific booting.
54+
*
55+
* @return void
56+
*/
57+
protected function bootForConsole(): void
58+
{
59+
// Publishing the configuration file.
60+
$this->publishes([
61+
__DIR__.'/../config/chileanrut.php' => config_path('chileanrut.php'),
62+
], 'chileanrut.config');
63+
64+
// Publishing the views.
65+
/*$this->publishes([
66+
__DIR__.'/../resources/views' => base_path('resources/views/vendor/innovaweb'),
67+
], 'chileanrut.views');*/
68+
69+
// Publishing assets.
70+
/*$this->publishes([
71+
__DIR__.'/../resources/assets' => public_path('vendor/innovaweb'),
72+
], 'chileanrut.views');*/
73+
74+
// Publishing the translation files.
75+
/*$this->publishes([
76+
__DIR__.'/../resources/lang' => resource_path('lang/vendor/innovaweb'),
77+
], 'chileanrut.views');*/
78+
79+
// Registering package commands.
80+
// $this->commands([]);
81+
}
82+
}

0 commit comments

Comments
 (0)