├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── composer.json ├── composer.lock ├── phpunit.xml ├── src └── BoletoValidator.php └── tests └── BoletoValidatorTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | /.c9/ 3 | .idea/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.5 5 | - 5.6 6 | - 7.0 7 | - hhvm 8 | 9 | matrix: 10 | allow_failures: 11 | - php: hhvm 12 | 13 | before_script: 14 | - composer selfupdate 15 | - composer install --dev --prefer-dist 16 | 17 | script: phpunit --coverage-clover=coverage.xml --configuration=phpunit.xml 18 | 19 | after_success: 20 | - bash <(curl -s https://codecov.io/bash) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Filipe Tagliatti 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Boleto Validator 2 | 3 | [![Build Status](https://travis-ci.org/Tagliatti/Boleto-Validator-PHP.svg?branch=master)](https://travis-ci.org/Tagliatti/Boleto-Validator-PHP) 4 | [![Coverage Status](https://img.shields.io/codecov/c/github/Tagliatti/Boleto-Validator-PHP.svg)](https://codecov.io/github/Tagliatti/Boleto-Validator-PHP) 5 | [![Latest Stable Version](https://poser.pugx.org/Tagliatti/Boleto-Validator/version.svg)](https://packagist.org/packages/Tagliatti/Boleto-Validator) 6 | [![Latest Unstable Version](https://poser.pugx.org/Tagliatti/Boleto-Validator/v/unstable.svg)](https://packagist.org/packages/Tagliatti/Boleto-Validator) 7 | [![License](https://poser.pugx.org/tagliatti/boleto-validator/license)](https://packagist.org/packages/Tagliatti/Boleto-Validator) 8 | [![Total Downloads](https://poser.pugx.org/Tagliatti/Boleto-Validator/d/total.svg)](https://packagist.org/packages/Tagliatti/Boleto-Validator) 9 | [![composer.lock available](https://poser.pugx.org/Tagliatti/Boleto-Validator/composerlock)](https://packagist.org/packages/Tagliatti/Boleto-Validator) 10 | 11 | Classe para validação de código de barras e linha digitalizável presente em boletos bancários. Compatível com PHP 5.5+ e deve ser utilizado um Autoloader compatível com a PSR-4. 12 | 13 | Ela valida boletos do tipo convênio (conta de luz, água, IPTU...), que são compostos por 4 blocos de números: 14 | 15 | ![convénio](http://i.imgur.com/CJApi3T.jpg) 16 | 17 | Exemplos:
18 | **83640000001-1 33120138000-2 81288462711-6 08013618155-1**
19 | ou
20 | **85890000460-9 52460179160-5 60759305086-5 83148300001-0** 21 | 22 | Também é possível validar boletos do tipo fatura ou carnê, que são compostos por 5 blocos de números (linha digitalizável): 23 | 24 | ![linha digitalizável](http://i.imgur.com/WImdusq.jpg) 25 | 26 | Exemplo: 27 | **42297.11504 00001.954411 60020.034520 2 68610000054659** 28 | 29 | # Instalação 30 | 31 | A instalação desta biblioteca pode ser feita utilizando o Composer. 32 | 33 | $ composer require tagliatti/boleto-validator 34 | 35 | # Exemplos de uso 36 | 37 | ### Validando convênio 38 | ```php 39 | =5.5" 14 | }, 15 | "require-dev": { 16 | "phpunit/phpunit": "4.8.*" 17 | }, 18 | "autoload": { 19 | "psr-4": { 20 | "Tagliatti\\BoletoValidator\\": ["src", "test"] 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "59f9b046972e9af813e826e9f36e7409", 8 | "content-hash": "46cb3d25fd307f13713f41de03e4af43", 9 | "packages": [], 10 | "packages-dev": [ 11 | { 12 | "name": "doctrine/instantiator", 13 | "version": "1.0.5", 14 | "source": { 15 | "type": "git", 16 | "url": "https://github.com/doctrine/instantiator.git", 17 | "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" 18 | }, 19 | "dist": { 20 | "type": "zip", 21 | "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", 22 | "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", 23 | "shasum": "" 24 | }, 25 | "require": { 26 | "php": ">=5.3,<8.0-DEV" 27 | }, 28 | "require-dev": { 29 | "athletic/athletic": "~0.1.8", 30 | "ext-pdo": "*", 31 | "ext-phar": "*", 32 | "phpunit/phpunit": "~4.0", 33 | "squizlabs/php_codesniffer": "~2.0" 34 | }, 35 | "type": "library", 36 | "extra": { 37 | "branch-alias": { 38 | "dev-master": "1.0.x-dev" 39 | } 40 | }, 41 | "autoload": { 42 | "psr-4": { 43 | "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" 44 | } 45 | }, 46 | "notification-url": "https://packagist.org/downloads/", 47 | "license": [ 48 | "MIT" 49 | ], 50 | "authors": [ 51 | { 52 | "name": "Marco Pivetta", 53 | "email": "ocramius@gmail.com", 54 | "homepage": "http://ocramius.github.com/" 55 | } 56 | ], 57 | "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", 58 | "homepage": "https://github.com/doctrine/instantiator", 59 | "keywords": [ 60 | "constructor", 61 | "instantiate" 62 | ], 63 | "time": "2015-06-14 21:17:01" 64 | }, 65 | { 66 | "name": "phpdocumentor/reflection-common", 67 | "version": "1.0", 68 | "source": { 69 | "type": "git", 70 | "url": "https://github.com/phpDocumentor/ReflectionCommon.git", 71 | "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" 72 | }, 73 | "dist": { 74 | "type": "zip", 75 | "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", 76 | "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", 77 | "shasum": "" 78 | }, 79 | "require": { 80 | "php": ">=5.5" 81 | }, 82 | "require-dev": { 83 | "phpunit/phpunit": "^4.6" 84 | }, 85 | "type": "library", 86 | "extra": { 87 | "branch-alias": { 88 | "dev-master": "1.0.x-dev" 89 | } 90 | }, 91 | "autoload": { 92 | "psr-4": { 93 | "phpDocumentor\\Reflection\\": [ 94 | "src" 95 | ] 96 | } 97 | }, 98 | "notification-url": "https://packagist.org/downloads/", 99 | "license": [ 100 | "MIT" 101 | ], 102 | "authors": [ 103 | { 104 | "name": "Jaap van Otterdijk", 105 | "email": "opensource@ijaap.nl" 106 | } 107 | ], 108 | "description": "Common reflection classes used by phpdocumentor to reflect the code structure", 109 | "homepage": "http://www.phpdoc.org", 110 | "keywords": [ 111 | "FQSEN", 112 | "phpDocumentor", 113 | "phpdoc", 114 | "reflection", 115 | "static analysis" 116 | ], 117 | "time": "2015-12-27 11:43:31" 118 | }, 119 | { 120 | "name": "phpdocumentor/reflection-docblock", 121 | "version": "3.1.0", 122 | "source": { 123 | "type": "git", 124 | "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", 125 | "reference": "9270140b940ff02e58ec577c237274e92cd40cdd" 126 | }, 127 | "dist": { 128 | "type": "zip", 129 | "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9270140b940ff02e58ec577c237274e92cd40cdd", 130 | "reference": "9270140b940ff02e58ec577c237274e92cd40cdd", 131 | "shasum": "" 132 | }, 133 | "require": { 134 | "php": ">=5.5", 135 | "phpdocumentor/reflection-common": "^1.0@dev", 136 | "phpdocumentor/type-resolver": "^0.2.0", 137 | "webmozart/assert": "^1.0" 138 | }, 139 | "require-dev": { 140 | "mockery/mockery": "^0.9.4", 141 | "phpunit/phpunit": "^4.4" 142 | }, 143 | "type": "library", 144 | "autoload": { 145 | "psr-4": { 146 | "phpDocumentor\\Reflection\\": [ 147 | "src/" 148 | ] 149 | } 150 | }, 151 | "notification-url": "https://packagist.org/downloads/", 152 | "license": [ 153 | "MIT" 154 | ], 155 | "authors": [ 156 | { 157 | "name": "Mike van Riel", 158 | "email": "me@mikevanriel.com" 159 | } 160 | ], 161 | "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", 162 | "time": "2016-06-10 09:48:41" 163 | }, 164 | { 165 | "name": "phpdocumentor/type-resolver", 166 | "version": "0.2", 167 | "source": { 168 | "type": "git", 169 | "url": "https://github.com/phpDocumentor/TypeResolver.git", 170 | "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443" 171 | }, 172 | "dist": { 173 | "type": "zip", 174 | "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b39c7a5b194f9ed7bd0dd345c751007a41862443", 175 | "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443", 176 | "shasum": "" 177 | }, 178 | "require": { 179 | "php": ">=5.5", 180 | "phpdocumentor/reflection-common": "^1.0" 181 | }, 182 | "require-dev": { 183 | "mockery/mockery": "^0.9.4", 184 | "phpunit/phpunit": "^5.2||^4.8.24" 185 | }, 186 | "type": "library", 187 | "extra": { 188 | "branch-alias": { 189 | "dev-master": "1.0.x-dev" 190 | } 191 | }, 192 | "autoload": { 193 | "psr-4": { 194 | "phpDocumentor\\Reflection\\": [ 195 | "src/" 196 | ] 197 | } 198 | }, 199 | "notification-url": "https://packagist.org/downloads/", 200 | "license": [ 201 | "MIT" 202 | ], 203 | "authors": [ 204 | { 205 | "name": "Mike van Riel", 206 | "email": "me@mikevanriel.com" 207 | } 208 | ], 209 | "time": "2016-06-10 07:14:17" 210 | }, 211 | { 212 | "name": "phpspec/prophecy", 213 | "version": "v1.6.1", 214 | "source": { 215 | "type": "git", 216 | "url": "https://github.com/phpspec/prophecy.git", 217 | "reference": "58a8137754bc24b25740d4281399a4a3596058e0" 218 | }, 219 | "dist": { 220 | "type": "zip", 221 | "url": "https://api.github.com/repos/phpspec/prophecy/zipball/58a8137754bc24b25740d4281399a4a3596058e0", 222 | "reference": "58a8137754bc24b25740d4281399a4a3596058e0", 223 | "shasum": "" 224 | }, 225 | "require": { 226 | "doctrine/instantiator": "^1.0.2", 227 | "php": "^5.3|^7.0", 228 | "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", 229 | "sebastian/comparator": "^1.1", 230 | "sebastian/recursion-context": "^1.0" 231 | }, 232 | "require-dev": { 233 | "phpspec/phpspec": "^2.0" 234 | }, 235 | "type": "library", 236 | "extra": { 237 | "branch-alias": { 238 | "dev-master": "1.6.x-dev" 239 | } 240 | }, 241 | "autoload": { 242 | "psr-0": { 243 | "Prophecy\\": "src/" 244 | } 245 | }, 246 | "notification-url": "https://packagist.org/downloads/", 247 | "license": [ 248 | "MIT" 249 | ], 250 | "authors": [ 251 | { 252 | "name": "Konstantin Kudryashov", 253 | "email": "ever.zet@gmail.com", 254 | "homepage": "http://everzet.com" 255 | }, 256 | { 257 | "name": "Marcello Duarte", 258 | "email": "marcello.duarte@gmail.com" 259 | } 260 | ], 261 | "description": "Highly opinionated mocking framework for PHP 5.3+", 262 | "homepage": "https://github.com/phpspec/prophecy", 263 | "keywords": [ 264 | "Double", 265 | "Dummy", 266 | "fake", 267 | "mock", 268 | "spy", 269 | "stub" 270 | ], 271 | "time": "2016-06-07 08:13:47" 272 | }, 273 | { 274 | "name": "phpunit/php-code-coverage", 275 | "version": "2.2.4", 276 | "source": { 277 | "type": "git", 278 | "url": "https://github.com/sebastianbergmann/php-code-coverage.git", 279 | "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" 280 | }, 281 | "dist": { 282 | "type": "zip", 283 | "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", 284 | "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", 285 | "shasum": "" 286 | }, 287 | "require": { 288 | "php": ">=5.3.3", 289 | "phpunit/php-file-iterator": "~1.3", 290 | "phpunit/php-text-template": "~1.2", 291 | "phpunit/php-token-stream": "~1.3", 292 | "sebastian/environment": "^1.3.2", 293 | "sebastian/version": "~1.0" 294 | }, 295 | "require-dev": { 296 | "ext-xdebug": ">=2.1.4", 297 | "phpunit/phpunit": "~4" 298 | }, 299 | "suggest": { 300 | "ext-dom": "*", 301 | "ext-xdebug": ">=2.2.1", 302 | "ext-xmlwriter": "*" 303 | }, 304 | "type": "library", 305 | "extra": { 306 | "branch-alias": { 307 | "dev-master": "2.2.x-dev" 308 | } 309 | }, 310 | "autoload": { 311 | "classmap": [ 312 | "src/" 313 | ] 314 | }, 315 | "notification-url": "https://packagist.org/downloads/", 316 | "license": [ 317 | "BSD-3-Clause" 318 | ], 319 | "authors": [ 320 | { 321 | "name": "Sebastian Bergmann", 322 | "email": "sb@sebastian-bergmann.de", 323 | "role": "lead" 324 | } 325 | ], 326 | "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", 327 | "homepage": "https://github.com/sebastianbergmann/php-code-coverage", 328 | "keywords": [ 329 | "coverage", 330 | "testing", 331 | "xunit" 332 | ], 333 | "time": "2015-10-06 15:47:00" 334 | }, 335 | { 336 | "name": "phpunit/php-file-iterator", 337 | "version": "1.4.1", 338 | "source": { 339 | "type": "git", 340 | "url": "https://github.com/sebastianbergmann/php-file-iterator.git", 341 | "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" 342 | }, 343 | "dist": { 344 | "type": "zip", 345 | "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", 346 | "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", 347 | "shasum": "" 348 | }, 349 | "require": { 350 | "php": ">=5.3.3" 351 | }, 352 | "type": "library", 353 | "extra": { 354 | "branch-alias": { 355 | "dev-master": "1.4.x-dev" 356 | } 357 | }, 358 | "autoload": { 359 | "classmap": [ 360 | "src/" 361 | ] 362 | }, 363 | "notification-url": "https://packagist.org/downloads/", 364 | "license": [ 365 | "BSD-3-Clause" 366 | ], 367 | "authors": [ 368 | { 369 | "name": "Sebastian Bergmann", 370 | "email": "sb@sebastian-bergmann.de", 371 | "role": "lead" 372 | } 373 | ], 374 | "description": "FilterIterator implementation that filters files based on a list of suffixes.", 375 | "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", 376 | "keywords": [ 377 | "filesystem", 378 | "iterator" 379 | ], 380 | "time": "2015-06-21 13:08:43" 381 | }, 382 | { 383 | "name": "phpunit/php-text-template", 384 | "version": "1.2.1", 385 | "source": { 386 | "type": "git", 387 | "url": "https://github.com/sebastianbergmann/php-text-template.git", 388 | "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" 389 | }, 390 | "dist": { 391 | "type": "zip", 392 | "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", 393 | "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", 394 | "shasum": "" 395 | }, 396 | "require": { 397 | "php": ">=5.3.3" 398 | }, 399 | "type": "library", 400 | "autoload": { 401 | "classmap": [ 402 | "src/" 403 | ] 404 | }, 405 | "notification-url": "https://packagist.org/downloads/", 406 | "license": [ 407 | "BSD-3-Clause" 408 | ], 409 | "authors": [ 410 | { 411 | "name": "Sebastian Bergmann", 412 | "email": "sebastian@phpunit.de", 413 | "role": "lead" 414 | } 415 | ], 416 | "description": "Simple template engine.", 417 | "homepage": "https://github.com/sebastianbergmann/php-text-template/", 418 | "keywords": [ 419 | "template" 420 | ], 421 | "time": "2015-06-21 13:50:34" 422 | }, 423 | { 424 | "name": "phpunit/php-timer", 425 | "version": "1.0.8", 426 | "source": { 427 | "type": "git", 428 | "url": "https://github.com/sebastianbergmann/php-timer.git", 429 | "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260" 430 | }, 431 | "dist": { 432 | "type": "zip", 433 | "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260", 434 | "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260", 435 | "shasum": "" 436 | }, 437 | "require": { 438 | "php": ">=5.3.3" 439 | }, 440 | "require-dev": { 441 | "phpunit/phpunit": "~4|~5" 442 | }, 443 | "type": "library", 444 | "autoload": { 445 | "classmap": [ 446 | "src/" 447 | ] 448 | }, 449 | "notification-url": "https://packagist.org/downloads/", 450 | "license": [ 451 | "BSD-3-Clause" 452 | ], 453 | "authors": [ 454 | { 455 | "name": "Sebastian Bergmann", 456 | "email": "sb@sebastian-bergmann.de", 457 | "role": "lead" 458 | } 459 | ], 460 | "description": "Utility class for timing", 461 | "homepage": "https://github.com/sebastianbergmann/php-timer/", 462 | "keywords": [ 463 | "timer" 464 | ], 465 | "time": "2016-05-12 18:03:57" 466 | }, 467 | { 468 | "name": "phpunit/php-token-stream", 469 | "version": "1.4.8", 470 | "source": { 471 | "type": "git", 472 | "url": "https://github.com/sebastianbergmann/php-token-stream.git", 473 | "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da" 474 | }, 475 | "dist": { 476 | "type": "zip", 477 | "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", 478 | "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", 479 | "shasum": "" 480 | }, 481 | "require": { 482 | "ext-tokenizer": "*", 483 | "php": ">=5.3.3" 484 | }, 485 | "require-dev": { 486 | "phpunit/phpunit": "~4.2" 487 | }, 488 | "type": "library", 489 | "extra": { 490 | "branch-alias": { 491 | "dev-master": "1.4-dev" 492 | } 493 | }, 494 | "autoload": { 495 | "classmap": [ 496 | "src/" 497 | ] 498 | }, 499 | "notification-url": "https://packagist.org/downloads/", 500 | "license": [ 501 | "BSD-3-Clause" 502 | ], 503 | "authors": [ 504 | { 505 | "name": "Sebastian Bergmann", 506 | "email": "sebastian@phpunit.de" 507 | } 508 | ], 509 | "description": "Wrapper around PHP's tokenizer extension.", 510 | "homepage": "https://github.com/sebastianbergmann/php-token-stream/", 511 | "keywords": [ 512 | "tokenizer" 513 | ], 514 | "time": "2015-09-15 10:49:45" 515 | }, 516 | { 517 | "name": "phpunit/phpunit", 518 | "version": "4.8.26", 519 | "source": { 520 | "type": "git", 521 | "url": "https://github.com/sebastianbergmann/phpunit.git", 522 | "reference": "fc1d8cd5b5de11625979125c5639347896ac2c74" 523 | }, 524 | "dist": { 525 | "type": "zip", 526 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fc1d8cd5b5de11625979125c5639347896ac2c74", 527 | "reference": "fc1d8cd5b5de11625979125c5639347896ac2c74", 528 | "shasum": "" 529 | }, 530 | "require": { 531 | "ext-dom": "*", 532 | "ext-json": "*", 533 | "ext-pcre": "*", 534 | "ext-reflection": "*", 535 | "ext-spl": "*", 536 | "php": ">=5.3.3", 537 | "phpspec/prophecy": "^1.3.1", 538 | "phpunit/php-code-coverage": "~2.1", 539 | "phpunit/php-file-iterator": "~1.4", 540 | "phpunit/php-text-template": "~1.2", 541 | "phpunit/php-timer": "^1.0.6", 542 | "phpunit/phpunit-mock-objects": "~2.3", 543 | "sebastian/comparator": "~1.1", 544 | "sebastian/diff": "~1.2", 545 | "sebastian/environment": "~1.3", 546 | "sebastian/exporter": "~1.2", 547 | "sebastian/global-state": "~1.0", 548 | "sebastian/version": "~1.0", 549 | "symfony/yaml": "~2.1|~3.0" 550 | }, 551 | "suggest": { 552 | "phpunit/php-invoker": "~1.1" 553 | }, 554 | "bin": [ 555 | "phpunit" 556 | ], 557 | "type": "library", 558 | "extra": { 559 | "branch-alias": { 560 | "dev-master": "4.8.x-dev" 561 | } 562 | }, 563 | "autoload": { 564 | "classmap": [ 565 | "src/" 566 | ] 567 | }, 568 | "notification-url": "https://packagist.org/downloads/", 569 | "license": [ 570 | "BSD-3-Clause" 571 | ], 572 | "authors": [ 573 | { 574 | "name": "Sebastian Bergmann", 575 | "email": "sebastian@phpunit.de", 576 | "role": "lead" 577 | } 578 | ], 579 | "description": "The PHP Unit Testing framework.", 580 | "homepage": "https://phpunit.de/", 581 | "keywords": [ 582 | "phpunit", 583 | "testing", 584 | "xunit" 585 | ], 586 | "time": "2016-05-17 03:09:28" 587 | }, 588 | { 589 | "name": "phpunit/phpunit-mock-objects", 590 | "version": "2.3.8", 591 | "source": { 592 | "type": "git", 593 | "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", 594 | "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983" 595 | }, 596 | "dist": { 597 | "type": "zip", 598 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983", 599 | "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983", 600 | "shasum": "" 601 | }, 602 | "require": { 603 | "doctrine/instantiator": "^1.0.2", 604 | "php": ">=5.3.3", 605 | "phpunit/php-text-template": "~1.2", 606 | "sebastian/exporter": "~1.2" 607 | }, 608 | "require-dev": { 609 | "phpunit/phpunit": "~4.4" 610 | }, 611 | "suggest": { 612 | "ext-soap": "*" 613 | }, 614 | "type": "library", 615 | "extra": { 616 | "branch-alias": { 617 | "dev-master": "2.3.x-dev" 618 | } 619 | }, 620 | "autoload": { 621 | "classmap": [ 622 | "src/" 623 | ] 624 | }, 625 | "notification-url": "https://packagist.org/downloads/", 626 | "license": [ 627 | "BSD-3-Clause" 628 | ], 629 | "authors": [ 630 | { 631 | "name": "Sebastian Bergmann", 632 | "email": "sb@sebastian-bergmann.de", 633 | "role": "lead" 634 | } 635 | ], 636 | "description": "Mock Object library for PHPUnit", 637 | "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", 638 | "keywords": [ 639 | "mock", 640 | "xunit" 641 | ], 642 | "time": "2015-10-02 06:51:40" 643 | }, 644 | { 645 | "name": "sebastian/comparator", 646 | "version": "1.2.0", 647 | "source": { 648 | "type": "git", 649 | "url": "https://github.com/sebastianbergmann/comparator.git", 650 | "reference": "937efb279bd37a375bcadf584dec0726f84dbf22" 651 | }, 652 | "dist": { 653 | "type": "zip", 654 | "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22", 655 | "reference": "937efb279bd37a375bcadf584dec0726f84dbf22", 656 | "shasum": "" 657 | }, 658 | "require": { 659 | "php": ">=5.3.3", 660 | "sebastian/diff": "~1.2", 661 | "sebastian/exporter": "~1.2" 662 | }, 663 | "require-dev": { 664 | "phpunit/phpunit": "~4.4" 665 | }, 666 | "type": "library", 667 | "extra": { 668 | "branch-alias": { 669 | "dev-master": "1.2.x-dev" 670 | } 671 | }, 672 | "autoload": { 673 | "classmap": [ 674 | "src/" 675 | ] 676 | }, 677 | "notification-url": "https://packagist.org/downloads/", 678 | "license": [ 679 | "BSD-3-Clause" 680 | ], 681 | "authors": [ 682 | { 683 | "name": "Jeff Welch", 684 | "email": "whatthejeff@gmail.com" 685 | }, 686 | { 687 | "name": "Volker Dusch", 688 | "email": "github@wallbash.com" 689 | }, 690 | { 691 | "name": "Bernhard Schussek", 692 | "email": "bschussek@2bepublished.at" 693 | }, 694 | { 695 | "name": "Sebastian Bergmann", 696 | "email": "sebastian@phpunit.de" 697 | } 698 | ], 699 | "description": "Provides the functionality to compare PHP values for equality", 700 | "homepage": "http://www.github.com/sebastianbergmann/comparator", 701 | "keywords": [ 702 | "comparator", 703 | "compare", 704 | "equality" 705 | ], 706 | "time": "2015-07-26 15:48:44" 707 | }, 708 | { 709 | "name": "sebastian/diff", 710 | "version": "1.4.1", 711 | "source": { 712 | "type": "git", 713 | "url": "https://github.com/sebastianbergmann/diff.git", 714 | "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" 715 | }, 716 | "dist": { 717 | "type": "zip", 718 | "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", 719 | "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", 720 | "shasum": "" 721 | }, 722 | "require": { 723 | "php": ">=5.3.3" 724 | }, 725 | "require-dev": { 726 | "phpunit/phpunit": "~4.8" 727 | }, 728 | "type": "library", 729 | "extra": { 730 | "branch-alias": { 731 | "dev-master": "1.4-dev" 732 | } 733 | }, 734 | "autoload": { 735 | "classmap": [ 736 | "src/" 737 | ] 738 | }, 739 | "notification-url": "https://packagist.org/downloads/", 740 | "license": [ 741 | "BSD-3-Clause" 742 | ], 743 | "authors": [ 744 | { 745 | "name": "Kore Nordmann", 746 | "email": "mail@kore-nordmann.de" 747 | }, 748 | { 749 | "name": "Sebastian Bergmann", 750 | "email": "sebastian@phpunit.de" 751 | } 752 | ], 753 | "description": "Diff implementation", 754 | "homepage": "https://github.com/sebastianbergmann/diff", 755 | "keywords": [ 756 | "diff" 757 | ], 758 | "time": "2015-12-08 07:14:41" 759 | }, 760 | { 761 | "name": "sebastian/environment", 762 | "version": "1.3.7", 763 | "source": { 764 | "type": "git", 765 | "url": "https://github.com/sebastianbergmann/environment.git", 766 | "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716" 767 | }, 768 | "dist": { 769 | "type": "zip", 770 | "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/4e8f0da10ac5802913afc151413bc8c53b6c2716", 771 | "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716", 772 | "shasum": "" 773 | }, 774 | "require": { 775 | "php": ">=5.3.3" 776 | }, 777 | "require-dev": { 778 | "phpunit/phpunit": "~4.4" 779 | }, 780 | "type": "library", 781 | "extra": { 782 | "branch-alias": { 783 | "dev-master": "1.3.x-dev" 784 | } 785 | }, 786 | "autoload": { 787 | "classmap": [ 788 | "src/" 789 | ] 790 | }, 791 | "notification-url": "https://packagist.org/downloads/", 792 | "license": [ 793 | "BSD-3-Clause" 794 | ], 795 | "authors": [ 796 | { 797 | "name": "Sebastian Bergmann", 798 | "email": "sebastian@phpunit.de" 799 | } 800 | ], 801 | "description": "Provides functionality to handle HHVM/PHP environments", 802 | "homepage": "http://www.github.com/sebastianbergmann/environment", 803 | "keywords": [ 804 | "Xdebug", 805 | "environment", 806 | "hhvm" 807 | ], 808 | "time": "2016-05-17 03:18:57" 809 | }, 810 | { 811 | "name": "sebastian/exporter", 812 | "version": "1.2.2", 813 | "source": { 814 | "type": "git", 815 | "url": "https://github.com/sebastianbergmann/exporter.git", 816 | "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4" 817 | }, 818 | "dist": { 819 | "type": "zip", 820 | "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4", 821 | "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4", 822 | "shasum": "" 823 | }, 824 | "require": { 825 | "php": ">=5.3.3", 826 | "sebastian/recursion-context": "~1.0" 827 | }, 828 | "require-dev": { 829 | "ext-mbstring": "*", 830 | "phpunit/phpunit": "~4.4" 831 | }, 832 | "type": "library", 833 | "extra": { 834 | "branch-alias": { 835 | "dev-master": "1.3.x-dev" 836 | } 837 | }, 838 | "autoload": { 839 | "classmap": [ 840 | "src/" 841 | ] 842 | }, 843 | "notification-url": "https://packagist.org/downloads/", 844 | "license": [ 845 | "BSD-3-Clause" 846 | ], 847 | "authors": [ 848 | { 849 | "name": "Jeff Welch", 850 | "email": "whatthejeff@gmail.com" 851 | }, 852 | { 853 | "name": "Volker Dusch", 854 | "email": "github@wallbash.com" 855 | }, 856 | { 857 | "name": "Bernhard Schussek", 858 | "email": "bschussek@2bepublished.at" 859 | }, 860 | { 861 | "name": "Sebastian Bergmann", 862 | "email": "sebastian@phpunit.de" 863 | }, 864 | { 865 | "name": "Adam Harvey", 866 | "email": "aharvey@php.net" 867 | } 868 | ], 869 | "description": "Provides the functionality to export PHP variables for visualization", 870 | "homepage": "http://www.github.com/sebastianbergmann/exporter", 871 | "keywords": [ 872 | "export", 873 | "exporter" 874 | ], 875 | "time": "2016-06-17 09:04:28" 876 | }, 877 | { 878 | "name": "sebastian/global-state", 879 | "version": "1.1.1", 880 | "source": { 881 | "type": "git", 882 | "url": "https://github.com/sebastianbergmann/global-state.git", 883 | "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" 884 | }, 885 | "dist": { 886 | "type": "zip", 887 | "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", 888 | "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", 889 | "shasum": "" 890 | }, 891 | "require": { 892 | "php": ">=5.3.3" 893 | }, 894 | "require-dev": { 895 | "phpunit/phpunit": "~4.2" 896 | }, 897 | "suggest": { 898 | "ext-uopz": "*" 899 | }, 900 | "type": "library", 901 | "extra": { 902 | "branch-alias": { 903 | "dev-master": "1.0-dev" 904 | } 905 | }, 906 | "autoload": { 907 | "classmap": [ 908 | "src/" 909 | ] 910 | }, 911 | "notification-url": "https://packagist.org/downloads/", 912 | "license": [ 913 | "BSD-3-Clause" 914 | ], 915 | "authors": [ 916 | { 917 | "name": "Sebastian Bergmann", 918 | "email": "sebastian@phpunit.de" 919 | } 920 | ], 921 | "description": "Snapshotting of global state", 922 | "homepage": "http://www.github.com/sebastianbergmann/global-state", 923 | "keywords": [ 924 | "global state" 925 | ], 926 | "time": "2015-10-12 03:26:01" 927 | }, 928 | { 929 | "name": "sebastian/recursion-context", 930 | "version": "1.0.2", 931 | "source": { 932 | "type": "git", 933 | "url": "https://github.com/sebastianbergmann/recursion-context.git", 934 | "reference": "913401df809e99e4f47b27cdd781f4a258d58791" 935 | }, 936 | "dist": { 937 | "type": "zip", 938 | "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/913401df809e99e4f47b27cdd781f4a258d58791", 939 | "reference": "913401df809e99e4f47b27cdd781f4a258d58791", 940 | "shasum": "" 941 | }, 942 | "require": { 943 | "php": ">=5.3.3" 944 | }, 945 | "require-dev": { 946 | "phpunit/phpunit": "~4.4" 947 | }, 948 | "type": "library", 949 | "extra": { 950 | "branch-alias": { 951 | "dev-master": "1.0.x-dev" 952 | } 953 | }, 954 | "autoload": { 955 | "classmap": [ 956 | "src/" 957 | ] 958 | }, 959 | "notification-url": "https://packagist.org/downloads/", 960 | "license": [ 961 | "BSD-3-Clause" 962 | ], 963 | "authors": [ 964 | { 965 | "name": "Jeff Welch", 966 | "email": "whatthejeff@gmail.com" 967 | }, 968 | { 969 | "name": "Sebastian Bergmann", 970 | "email": "sebastian@phpunit.de" 971 | }, 972 | { 973 | "name": "Adam Harvey", 974 | "email": "aharvey@php.net" 975 | } 976 | ], 977 | "description": "Provides functionality to recursively process PHP variables", 978 | "homepage": "http://www.github.com/sebastianbergmann/recursion-context", 979 | "time": "2015-11-11 19:50:13" 980 | }, 981 | { 982 | "name": "sebastian/version", 983 | "version": "1.0.6", 984 | "source": { 985 | "type": "git", 986 | "url": "https://github.com/sebastianbergmann/version.git", 987 | "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" 988 | }, 989 | "dist": { 990 | "type": "zip", 991 | "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", 992 | "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", 993 | "shasum": "" 994 | }, 995 | "type": "library", 996 | "autoload": { 997 | "classmap": [ 998 | "src/" 999 | ] 1000 | }, 1001 | "notification-url": "https://packagist.org/downloads/", 1002 | "license": [ 1003 | "BSD-3-Clause" 1004 | ], 1005 | "authors": [ 1006 | { 1007 | "name": "Sebastian Bergmann", 1008 | "email": "sebastian@phpunit.de", 1009 | "role": "lead" 1010 | } 1011 | ], 1012 | "description": "Library that helps with managing the version number of Git-hosted PHP projects", 1013 | "homepage": "https://github.com/sebastianbergmann/version", 1014 | "time": "2015-06-21 13:59:46" 1015 | }, 1016 | { 1017 | "name": "symfony/yaml", 1018 | "version": "v3.1.2", 1019 | "source": { 1020 | "type": "git", 1021 | "url": "https://github.com/symfony/yaml.git", 1022 | "reference": "2884c26ce4c1d61aebf423a8b912950fe7c764de" 1023 | }, 1024 | "dist": { 1025 | "type": "zip", 1026 | "url": "https://api.github.com/repos/symfony/yaml/zipball/2884c26ce4c1d61aebf423a8b912950fe7c764de", 1027 | "reference": "2884c26ce4c1d61aebf423a8b912950fe7c764de", 1028 | "shasum": "" 1029 | }, 1030 | "require": { 1031 | "php": ">=5.5.9" 1032 | }, 1033 | "type": "library", 1034 | "extra": { 1035 | "branch-alias": { 1036 | "dev-master": "3.1-dev" 1037 | } 1038 | }, 1039 | "autoload": { 1040 | "psr-4": { 1041 | "Symfony\\Component\\Yaml\\": "" 1042 | }, 1043 | "exclude-from-classmap": [ 1044 | "/Tests/" 1045 | ] 1046 | }, 1047 | "notification-url": "https://packagist.org/downloads/", 1048 | "license": [ 1049 | "MIT" 1050 | ], 1051 | "authors": [ 1052 | { 1053 | "name": "Fabien Potencier", 1054 | "email": "fabien@symfony.com" 1055 | }, 1056 | { 1057 | "name": "Symfony Community", 1058 | "homepage": "https://symfony.com/contributors" 1059 | } 1060 | ], 1061 | "description": "Symfony Yaml Component", 1062 | "homepage": "https://symfony.com", 1063 | "time": "2016-06-29 05:41:56" 1064 | }, 1065 | { 1066 | "name": "webmozart/assert", 1067 | "version": "1.0.2", 1068 | "source": { 1069 | "type": "git", 1070 | "url": "https://github.com/webmozart/assert.git", 1071 | "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde" 1072 | }, 1073 | "dist": { 1074 | "type": "zip", 1075 | "url": "https://api.github.com/repos/webmozart/assert/zipball/30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", 1076 | "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", 1077 | "shasum": "" 1078 | }, 1079 | "require": { 1080 | "php": ">=5.3.3" 1081 | }, 1082 | "require-dev": { 1083 | "phpunit/phpunit": "^4.6" 1084 | }, 1085 | "type": "library", 1086 | "extra": { 1087 | "branch-alias": { 1088 | "dev-master": "1.0-dev" 1089 | } 1090 | }, 1091 | "autoload": { 1092 | "psr-4": { 1093 | "Webmozart\\Assert\\": "src/" 1094 | } 1095 | }, 1096 | "notification-url": "https://packagist.org/downloads/", 1097 | "license": [ 1098 | "MIT" 1099 | ], 1100 | "authors": [ 1101 | { 1102 | "name": "Bernhard Schussek", 1103 | "email": "bschussek@gmail.com" 1104 | } 1105 | ], 1106 | "description": "Assertions to validate method input/output with nice error messages.", 1107 | "keywords": [ 1108 | "assert", 1109 | "check", 1110 | "validate" 1111 | ], 1112 | "time": "2015-08-24 13:29:44" 1113 | } 1114 | ], 1115 | "aliases": [], 1116 | "minimum-stability": "stable", 1117 | "stability-flags": [], 1118 | "prefer-stable": false, 1119 | "prefer-lowest": false, 1120 | "platform": [], 1121 | "platform-dev": [] 1122 | } 1123 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | ./tests 9 | 10 | 11 | 12 | 13 | 14 | vendor 15 | 16 | 17 | src 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/BoletoValidator.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class BoletoValidator 11 | { 12 | 13 | /** 14 | * Valida boletos do tipo convênio. 15 | * 16 | * @example Exemplo modulo 10: 83640000001-1 33120138000-2 81288462711-6 08013618155-1 17 | * @example Exemplo modulo 11: 85890000460-9 52460179160-5 60759305086-5 83148300001-0 18 | * 19 | * @param string $linhaDigitavel linha digitável com ou sem máscara de boleto de convênio. 20 | * @return boolean Retorna se é válido ou não. 21 | */ 22 | public static function convenio(string $linhaDigitavel): bool 23 | { 24 | $linhaDigitavel = str_replace([' ', '-'], '', $linhaDigitavel); 25 | 26 | if (!preg_match("/^[0-9]{48}$/", $linhaDigitavel)) { 27 | return false; 28 | } 29 | 30 | $blocos[0] = substr($linhaDigitavel, 0, 12); 31 | $blocos[1] = substr($linhaDigitavel, 12, 12); 32 | $blocos[2] = substr($linhaDigitavel, 24, 12); 33 | $blocos[3] = substr($linhaDigitavel, 36, 12); 34 | 35 | /** 36 | * Verifica se é o modulo 10 ou modulo 11. 37 | * Se o 3º digito for 6 ou 7 é modulo 10, se for 8 ou 9, então modulo 11. 38 | */ 39 | $isModulo10 = in_array($linhaDigitavel[2], [6, 7]); 40 | 41 | $valido = 0; 42 | 43 | foreach ($blocos as $bloco) { 44 | if ($isModulo10 && static::modulo10($bloco)) { 45 | $valido++; 46 | } elseif (static::modulo11($bloco)) { 47 | $valido++; 48 | } 49 | } 50 | 51 | return $valido == 4; 52 | } 53 | 54 | /** 55 | * Valida boletos do tipo fatura ou carnê. 56 | * 57 | * @example Exemplo: 42297.11504 00001.954411 60020.034520 2 68610000054659 58 | * 59 | * @param string $linhaDigitavel Linha digitalizável com ou sem máscara de boleto bancário. 60 | * @return boolean Retorna se é válido ou não. 61 | */ 62 | public static function boleto(string $linhaDigitavel): bool 63 | { 64 | $linhaDigitavel = str_replace([' ', '.'], '', $linhaDigitavel); 65 | 66 | if (!preg_match("/^[0-9]{47}$/", $linhaDigitavel)) { 67 | return false; 68 | } 69 | 70 | $blocos[0] = substr($linhaDigitavel, 0, 10); 71 | $blocos[1] = substr($linhaDigitavel, 10, 11); 72 | $blocos[2] = substr($linhaDigitavel, 21, 11); 73 | 74 | $valido = 0; 75 | 76 | foreach ($blocos as $bloco) { 77 | if (static::modulo10($bloco)) { 78 | $valido++; 79 | } 80 | } 81 | 82 | return $valido == 3; 83 | } 84 | 85 | /** 86 | * Cacula o módulo 10 do bloco. 87 | * 88 | * @param string $bloco 89 | * @return boolean Retorna se é válido ou não. 90 | */ 91 | protected static function modulo10($bloco) 92 | { 93 | $tamanhoBloco = strlen($bloco) - 1; 94 | $digitoVerificador = $bloco[$tamanhoBloco]; 95 | 96 | $codigo = substr($bloco, 0, $tamanhoBloco); 97 | $codigo = strrev($codigo); 98 | $codigo = str_split($codigo); 99 | 100 | $somatorio = 0; 101 | 102 | foreach ($codigo as $index => $value) { 103 | $soma = $value * ($index % 2 == 0 ? 2 : 1); 104 | 105 | /** 106 | * Quando a $soma tiver mais de 1 algarismo(ou seja, maior que 9), 107 | * soma-se os algarismos antes de somar com $somatorio 108 | */ 109 | if ($soma > 9) { 110 | $somatorio += array_sum(str_split($soma)); 111 | } else { 112 | $somatorio += $soma; 113 | } 114 | } 115 | 116 | /** 117 | * (ceil($somatorio / 10) * 10) pega a dezena imediatamente superior ao $somatorio 118 | * (dezena superior de 25 é 30, a de 43 é 50...). 119 | */ 120 | $dezenaSuperiorSomatorioMenosSomatorio = (ceil($somatorio / 10) * 10) - $somatorio; 121 | 122 | return $dezenaSuperiorSomatorioMenosSomatorio == $digitoVerificador; 123 | } 124 | 125 | /** 126 | * Cacula o módulo 11 do bloco. 127 | * 128 | * @param string $bloco 129 | * @return boolean Retorna se é válido ou não. 130 | */ 131 | protected static function modulo11($bloco) 132 | { 133 | $tamanhoBloco = strlen($bloco) - 1; 134 | $digitoVerificador = $bloco[$tamanhoBloco]; 135 | 136 | $codigo = substr($bloco, 0, $tamanhoBloco); 137 | $codigo = strrev($codigo); 138 | $codigo = str_split($codigo); 139 | 140 | $somatorio = 0; 141 | 142 | foreach ($codigo as $index => $value) { 143 | $somatorio += $value * (2 + ($index >= 8 ? $index - 8 : $index)); 144 | } 145 | 146 | $restoDivisao = $somatorio % 11; 147 | 148 | if ($restoDivisao == 0 || $restoDivisao == 1) { 149 | $dezenaSuperiorSomatorioMenosSomatorio = 0; 150 | } elseif ($restoDivisao == 10) { 151 | $dezenaSuperiorSomatorioMenosSomatorio = 1; 152 | } else { 153 | $dezenaSuperiorSomatorioMenosSomatorio = (ceil($somatorio / 11) * 11) - $somatorio; 154 | } 155 | 156 | return $dezenaSuperiorSomatorioMenosSomatorio == $digitoVerificador; 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /tests/BoletoValidatorTest.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class BoletoValidatorTest extends \PHPUnit_Framework_TestCase 11 | { 12 | 13 | public function testConvenioValidModule10() 14 | { 15 | $this->assertTrue(BoletoValidator::convenio('83640000001-1 33120138000-2 81288462711-6 08013618155-1')); 16 | } 17 | 18 | public function testConvenioValidModule11() 19 | { 20 | $this->assertTrue(BoletoValidator::convenio('85890000460-9 52460179160-5 60759305086-5 83148300001-0')); 21 | } 22 | 23 | /** 24 | * Teste para cobrir 100% de coverage. 25 | */ 26 | public function testConvenioValidModule11IfRestOfDivisiono10() 27 | { 28 | $this->assertTrue(BoletoValidator::convenio('85890000464-1 52460179160-5 60759305086-5 83148300001-0')); 29 | } 30 | 31 | public function testConvenioInalidModule10() 32 | { 33 | $this->assertFalse(BoletoValidator::convenio('83640000001-2 33120138000-2 81288462711-6 08013618155-1')); 34 | } 35 | 36 | public function testConvenioInalidModule11() 37 | { 38 | $this->assertFalse(BoletoValidator::convenio('85890000460-8 52460179160-5 60759305086-5 83148300001-0')); 39 | } 40 | 41 | /** 42 | * 1 caracter a mais 43 | * 44 | * @expectedException Exception 45 | */ 46 | public function testConvenioInvalidFormatWithOneMoreCharacter() { 47 | $this->assertFalse(BoletoValidator::convenio('85890000460-9 52460179160-5 60759305086-5 83148300001-09')); 48 | } 49 | 50 | /** 51 | * Passando uma letra 52 | * 53 | * @expectedException Exception 54 | */ 55 | public function testConvenioInvalidFormatPassingALetter() 56 | { 57 | $this->assertFalse(BoletoValidator::convenio('85890000460-9 52460179160-5 60759305086-5 83148300001-a')); 58 | } 59 | 60 | public function testBoletoValid() 61 | { 62 | $this->assertTrue(BoletoValidator::boleto('42297.11504 00001.954411 60020.034520 2 68610000054659')); 63 | } 64 | 65 | public function testBoletoInvalid() 66 | { 67 | $this->assertFalse(BoletoValidator::boleto('92297.11504 00001.954411 60020.034520 2 68610000054659')); 68 | } 69 | 70 | 71 | /** 72 | * 1 caracter a mais 73 | * 74 | * @expectedException Exception 75 | */ 76 | public function testBoletoInvalidFormatWithOneMoreCharacter() 77 | { 78 | $this->assertFalse(BoletoValidator::boleto('42297.11504 00001.954411 60020.034520 2 686100000546590')); 79 | } 80 | 81 | /** 82 | * Passando uma letra 83 | * 84 | * @expectedException Exception 85 | */ 86 | public function testBoletoInvalidFormatPassingALetter() 87 | { 88 | $this->assertFalse(BoletoValidator::boleto('42297.11504 00001.954411 60020.034520 2 6861000005465a')); 89 | } 90 | 91 | } 92 | --------------------------------------------------------------------------------