From 77bce63a5c51269ade8ecb2296926880958354ac Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Wed, 22 Apr 2015 11:40:17 +0200 Subject: [PATCH] Proper PHP and PHPDoc in library and examples --- .gitignore | 2 - composer.lock | 866 ---------------------------------------------- examples/HOTP.php | 89 ++++- examples/TOTP.php | 90 ++++- lib/OTP.php | 6 +- lib/TOTP.php | 2 +- phpunit.xml.dist | 1 - 7 files changed, 162 insertions(+), 894 deletions(-) delete mode 100644 .gitignore delete mode 100644 composer.lock diff --git a/.gitignore b/.gitignore deleted file mode 100644 index fd8ceeec..00000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -vendor/ -build/ diff --git a/composer.lock b/composer.lock deleted file mode 100644 index efe7bcef..00000000 --- a/composer.lock +++ /dev/null @@ -1,866 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" - ], - "hash": "3fda97a94a3b3dada2de1456dfc7d990", - "packages": [ - { - "name": "christian-riesen/base32", - "version": "1.2", - "source": { - "type": "git", - "url": "https://github.com/ChristianRiesen/base32.git", - "reference": "b883c3f4bf6f3219c1e9acb7c89f197cbf7b19c4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ChristianRiesen/base32/zipball/b883c3f4bf6f3219c1e9acb7c89f197cbf7b19c4", - "reference": "b883c3f4bf6f3219c1e9acb7c89f197cbf7b19c4", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "4.*", - "satooshi/php-coveralls": "0.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Base32\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Riesen", - "email": "chris.riesen@gmail.com", - "homepage": "http://christianriesen.com", - "role": "Developer" - } - ], - "description": "Base32 encoder/decoder according to RFC 4648", - "homepage": "https://github.com/ChristianRiesen/base32", - "keywords": [ - "base32", - "decode", - "encode", - "rfc4648" - ], - "time": "2014-08-11 15:45:52" - } - ], - "packages-dev": [ - { - "name": "doctrine/instantiator", - "version": "1.0.4", - "source": { - "type": "git", - "url": "https://github.com/doctrine/instantiator.git", - "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119", - "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119", - "shasum": "" - }, - "require": { - "php": ">=5.3,<8.0-DEV" - }, - "require-dev": { - "athletic/athletic": "~0.1.8", - "ext-pdo": "*", - "ext-phar": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "2.0.*@ALPHA" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "Doctrine\\Instantiator\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com", - "homepage": "http://ocramius.github.com/" - } - ], - "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://github.com/doctrine/instantiator", - "keywords": [ - "constructor", - "instantiate" - ], - "time": "2014-10-13 12:58:55" - }, - { - "name": "phpunit/php-code-coverage", - "version": "2.0.14", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "ca158276c1200cc27f5409a5e338486bc0b4fc94" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ca158276c1200cc27f5409a5e338486bc0b4fc94", - "reference": "ca158276c1200cc27f5409a5e338486bc0b4fc94", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": "~1.3", - "phpunit/php-text-template": "~1.2", - "phpunit/php-token-stream": "~1.3", - "sebastian/environment": "~1.0", - "sebastian/version": "~1.0" - }, - "require-dev": { - "ext-xdebug": ">=2.1.4", - "phpunit/phpunit": "~4.1" - }, - "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.2.1", - "ext-xmlwriter": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", - "homepage": "https://github.com/sebastianbergmann/php-code-coverage", - "keywords": [ - "coverage", - "testing", - "xunit" - ], - "time": "2014-12-26 13:28:33" - }, - { - "name": "phpunit/php-file-iterator", - "version": "1.3.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", - "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "File/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", - "keywords": [ - "filesystem", - "iterator" - ], - "time": "2013-10-10 15:34:57" - }, - { - "name": "phpunit/php-text-template", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "Text/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", - "keywords": [ - "template" - ], - "time": "2014-01-30 17:20:04" - }, - { - "name": "phpunit/php-timer", - "version": "1.0.5", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "PHP/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", - "keywords": [ - "timer" - ], - "time": "2013-08-02 07:42:54" - }, - { - "name": "phpunit/php-token-stream", - "version": "1.4.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/db32c18eba00b121c145575fcbcd4d4d24e6db74", - "reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "https://github.com/sebastianbergmann/php-token-stream/", - "keywords": [ - "tokenizer" - ], - "time": "2015-01-17 09:51:32" - }, - { - "name": "phpunit/phpunit", - "version": "4.4.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "e90575c2bb86290d57a262862dab1da125431576" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e90575c2bb86290d57a262862dab1da125431576", - "reference": "e90575c2bb86290d57a262862dab1da125431576", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", - "php": ">=5.3.3", - "phpunit/php-code-coverage": "~2.0", - "phpunit/php-file-iterator": "~1.3.2", - "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "~1.0.2", - "phpunit/phpunit-mock-objects": "~2.3", - "sebastian/comparator": "~1.0", - "sebastian/diff": "~1.1", - "sebastian/environment": "~1.1", - "sebastian/exporter": "~1.0", - "sebastian/global-state": "~1.0", - "sebastian/version": "~1.0", - "symfony/yaml": "~2.0" - }, - "suggest": { - "phpunit/php-invoker": "~1.1" - }, - "bin": [ - "phpunit" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.4.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "The PHP Unit Testing framework.", - "homepage": "https://phpunit.de/", - "keywords": [ - "phpunit", - "testing", - "xunit" - ], - "time": "2015-01-17 11:24:41" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "2.3.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "c63d2367247365f688544f0d500af90a11a44c65" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/c63d2367247365f688544f0d500af90a11a44c65", - "reference": "c63d2367247365f688544f0d500af90a11a44c65", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "~1.0,>=1.0.1", - "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2" - }, - "require-dev": { - "phpunit/phpunit": "~4.3" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "time": "2014-10-03 05:12:11" - }, - { - "name": "sebastian/comparator", - "version": "1.1.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "c484a80f97573ab934e37826dba0135a3301b26a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/c484a80f97573ab934e37826dba0135a3301b26a", - "reference": "c484a80f97573ab934e37826dba0135a3301b26a", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "sebastian/diff": "~1.1", - "sebastian/exporter": "~1.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides the functionality to compare PHP values for equality", - "homepage": "http://www.github.com/sebastianbergmann/comparator", - "keywords": [ - "comparator", - "compare", - "equality" - ], - "time": "2014-11-16 21:32:38" - }, - { - "name": "sebastian/diff", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "5843509fed39dee4b356a306401e9dd1a931fec7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/5843509fed39dee4b356a306401e9dd1a931fec7", - "reference": "5843509fed39dee4b356a306401e9dd1a931fec7", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Diff implementation", - "homepage": "http://www.github.com/sebastianbergmann/diff", - "keywords": [ - "diff" - ], - "time": "2014-08-15 10:29:00" - }, - { - "name": "sebastian/environment", - "version": "1.2.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "6e6c71d918088c251b181ba8b3088af4ac336dd7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6e6c71d918088c251b181ba8b3088af4ac336dd7", - "reference": "6e6c71d918088c251b181ba8b3088af4ac336dd7", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides functionality to handle HHVM/PHP environments", - "homepage": "http://www.github.com/sebastianbergmann/environment", - "keywords": [ - "Xdebug", - "environment", - "hhvm" - ], - "time": "2014-10-25 08:00:45" - }, - { - "name": "sebastian/exporter", - "version": "1.0.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", - "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - } - ], - "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "http://www.github.com/sebastianbergmann/exporter", - "keywords": [ - "export", - "exporter" - ], - "time": "2014-09-10 00:51:36" - }, - { - "name": "sebastian/global-state", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", - "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "suggest": { - "ext-uopz": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Snapshotting of global state", - "homepage": "http://www.github.com/sebastianbergmann/global-state", - "keywords": [ - "global state" - ], - "time": "2014-10-06 09:23:50" - }, - { - "name": "sebastian/version", - "version": "1.0.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/version.git", - "reference": "a77d9123f8e809db3fbdea15038c27a95da4058b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/a77d9123f8e809db3fbdea15038c27a95da4058b", - "reference": "a77d9123f8e809db3fbdea15038c27a95da4058b", - "shasum": "" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library that helps with managing the version number of Git-hosted PHP projects", - "homepage": "https://github.com/sebastianbergmann/version", - "time": "2014-12-15 14:25:24" - }, - { - "name": "symfony/yaml", - "version": "v2.6.3", - "target-dir": "Symfony/Component/Yaml", - "source": { - "type": "git", - "url": "https://github.com/symfony/Yaml.git", - "reference": "82462a90848a52c2533aa6b598b107d68076b018" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/82462a90848a52c2533aa6b598b107d68076b018", - "reference": "82462a90848a52c2533aa6b598b107d68076b018", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.6-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\Yaml\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Symfony Yaml Component", - "homepage": "http://symfony.com", - "time": "2015-01-03 15:33:07" - } - ], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": { - "php": ">=5.3.2" - }, - "platform-dev": [] -} diff --git a/examples/HOTP.php b/examples/HOTP.php index 825051c5..199f9360 100644 --- a/examples/HOTP.php +++ b/examples/HOTP.php @@ -6,16 +6,39 @@ class HOTP extends BaseHOTP { + /** + * @var string|null + */ protected $secret = null; + /** + * @var string|null + */ protected $issuer = null; + /** + * @var bool + */ protected $issuer_included_as_parameter = false; + /** + * @var string|null + */ protected $label = null; + /** + * @var string + */ protected $digest = 'sha1'; + /** + * @var int + */ protected $digits = 6; + /** + * @var int + */ protected $counter = 0; /** * @param string $secret + * + * @return self */ public function setSecret($secret) { @@ -25,6 +48,9 @@ public function setSecret($secret) return $this; } + /** + * @return string|null + */ public function getSecret() { return $this->secret; @@ -32,17 +58,23 @@ public function getSecret() /** * @param string $label + * + * @return self + * @throws \InvalidArgumentException */ public function setLabel($label) { if ($this->hasSemicolon($label)) { - throw new \Exception("Label must not containt a semi-colon."); + throw new \InvalidArgumentException("Label must not contain a semi-colon."); } $this->label = $label; return $this; } + /** + * @return string|null + */ public function getLabel() { return $this->label; @@ -50,29 +82,40 @@ public function getLabel() /** * @param string $issuer + * + * @return self + * @throws \InvalidArgumentException */ public function setIssuer($issuer) { if ($this->hasSemicolon($issuer)) { - throw new \Exception("Issuer must not containt a semi-colon."); + throw new \InvalidArgumentException("Issuer must not contain a semi-colon."); } $this->issuer = $issuer; return $this; } + /** + * @return string|null + */ public function getIssuer() { return $this->issuer; } + /** + * @return bool + */ public function isIssuerIncludedAsParameter() { return $this->issuer_included_as_parameter; } /** - * @param boolean $issuer_included_as_parameter + * @param $issuer_included_as_parameter + * + * @return self */ public function setIssuerIncludedAsParameter($issuer_included_as_parameter) { @@ -82,59 +125,82 @@ public function setIssuerIncludedAsParameter($issuer_included_as_parameter) } /** - * @param integer $digits + * @param $digits + * + * @return self + * @throws \InvalidArgumentException */ public function setDigits($digits) { if (!is_integer($digits) || $digits < 1) { - throw new \Exception("Digits must be at least 1."); + throw new \InvalidArgumentException("Digits must be at least 1."); } $this->digits = $digits; return $this; } + /** + * @return int + */ public function getDigits() { return $this->digits; } /** - * @param string $digest + * @param $digest + * + * @return self + * @throws \InvalidArgumentException */ public function setDigest($digest) { if (!in_array($digest, array('md5', 'sha1', 'sha256', 'sha512'))) { - throw new \Exception("'$digest' digest is not supported."); + throw new \InvalidArgumentException("'$digest' digest is not supported."); } $this->digest = $digest; return $this; } + /** + * @return string + */ public function getDigest() { return $this->digest; } /** - * @param integer $counter + * @param $counter + * + * @return self + * @throws \InvalidArgumentException */ public function setCounter($counter) { if (!is_integer($counter) || $counter < 0) { - throw new \Exception("Counter must be at least 0."); + throw new \InvalidArgumentException("Counter must be at least 0."); } $this->counter = $counter; return $this; } + /** + * @return int + */ public function getCounter() { return $this->counter; } + /** + * @param int $counter + * + * @return $this + */ public function updateCounter($counter) { $this->counter = $counter; @@ -142,6 +208,11 @@ public function updateCounter($counter) return $this; } + /** + * @param $value + * + * @return bool + */ private function hasSemicolon($value) { $semicolons = array(':', '%3A', '%3a'); diff --git a/examples/TOTP.php b/examples/TOTP.php index 4ff2793c..7abc5b8d 100644 --- a/examples/TOTP.php +++ b/examples/TOTP.php @@ -6,16 +6,39 @@ class TOTP extends BaseTOTP { + /** + * @var string|null + */ protected $secret = null; + /** + * @var string|null + */ protected $issuer = null; + /** + * @var bool + */ protected $issuer_included_as_parameter = false; + /** + * @var string|null + */ protected $label = null; + /** + * @var string + */ protected $digest = 'sha1'; + /** + * @var int + */ protected $digits = 6; + /** + * @var int + */ protected $interval = 30; /** - * @param string $secret + * @param $secret + * + * @return self */ public function setSecret($secret) { @@ -25,54 +48,74 @@ public function setSecret($secret) return $this; } + /** + * @return string|null + */ public function getSecret() { return $this->secret; } /** - * @param string $label + * @param $label + * + * @return self + * @throws \InvalidArgumentException */ public function setLabel($label) { if ($this->hasSemicolon($label)) { - throw new \Exception("Label must not containt a semi-colon."); + throw new \InvalidArgumentException("Label must not contain a semi-colon."); } $this->label = $label; return $this; } + /** + * @return string|null + */ public function getLabel() { return $this->label; } /** - * @param string $issuer + * @param $issuer + * + * @return self + * @throws \InvalidArgumentException */ public function setIssuer($issuer) { if ($this->hasSemicolon($issuer)) { - throw new \Exception("Issuer must not containt a semi-colon."); + throw new \InvalidArgumentException("Issuer must not contain a semi-colon."); } $this->issuer = $issuer; return $this; } + /** + * @return string|null + */ public function getIssuer() { return $this->issuer; } + /** + * @return bool + */ public function isIssuerIncludedAsParameter() { return $this->issuer_included_as_parameter; } /** - * @param boolean $issuer_included_as_parameter + * @param $issuer_included_as_parameter + * + * @return self */ public function setIssuerIncludedAsParameter($issuer_included_as_parameter) { @@ -82,59 +125,82 @@ public function setIssuerIncludedAsParameter($issuer_included_as_parameter) } /** - * @param integer $digits + * @param $digits + * + * @return self + * @throws \InvalidArgumentException */ public function setDigits($digits) { if (!is_integer($digits) || $digits < 1) { - throw new \Exception("Digits must be at least 1."); + throw new \InvalidArgumentException("Digits must be at least 1."); } $this->digits = $digits; return $this; } + /** + * @return int + */ public function getDigits() { return $this->digits; } /** - * @param string $digest + * @param $digest + * + * @return self + * @throws \InvalidArgumentException */ public function setDigest($digest) { if (!in_array($digest, array('md5', 'sha1', 'sha256', 'sha512'))) { - throw new \Exception("'$digest' digest is not supported."); + throw new \InvalidArgumentException("'$digest' digest is not supported."); } $this->digest = $digest; return $this; } + /** + * @return string + */ public function getDigest() { return $this->digest; } /** - * @param integer $interval + * @param $interval + * + * @return self + * @throws \InvalidArgumentException */ public function setInterval($interval) { if (!is_integer($interval) || $interval < 1) { - throw new \Exception("Interval must be at least 1."); + throw new \InvalidArgumentException("Interval must be at least 1."); } $this->interval = $interval; return $this; } + /** + * @return int + */ public function getInterval() { return $this->interval; } + /** + * @param $value + * + * @return bool + */ private function hasSemicolon($value) { $semicolons = array(':', '%3A', '%3a'); diff --git a/lib/OTP.php b/lib/OTP.php index 3a63d3bb..02710df4 100644 --- a/lib/OTP.php +++ b/lib/OTP.php @@ -32,7 +32,7 @@ protected function generateOTP($input) */ protected function issuerAsParameter() { - if ($this->getIssuer() !== null && $this->isIssuerIncludedAsParameter() === true) { + if (!is_null($this->getIssuer()) && $this->isIssuerIncludedAsParameter() === true) { return true; } @@ -49,7 +49,7 @@ protected function issuerAsParameter() */ protected function generateURI($type, $opt = array()) { - if ($this->getLabel() === null) { + if (is_null($this->getLabel())) { throw new \InvalidArgumentException('No label defined.'); } $opt['algorithm'] = $this->getDigest(); @@ -67,7 +67,7 @@ protected function generateURI($type, $opt = array()) http_build_query($opt) ); - return "otpauth://$type/".rawurlencode(($this->getIssuer() !== null ? $this->getIssuer().':' : '').$this->getLabel())."?$params"; + return "otpauth://$type/".rawurlencode((!is_null($this->getIssuer()) ? $this->getIssuer().':' : '').$this->getLabel())."?$params"; } /** diff --git a/lib/TOTP.php b/lib/TOTP.php index 2b107cd3..a7af8b34 100644 --- a/lib/TOTP.php +++ b/lib/TOTP.php @@ -25,7 +25,7 @@ public function now() */ public function verify($otp, $timestamp = null, $window = null) { - if ($timestamp === null) { + if (is_null($timestamp)) { $timestamp = time(); } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c7286a27..c7008ce7 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,5 @@