Skip to content

Commit

Permalink
Fix php standards
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhemN committed Oct 20, 2015
1 parent d458866 commit 0c7f045
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/*
composer.lock
.php_cs.cache
32 changes: 32 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Symfony\CS\Config\Config;
use Symfony\CS\Finder\DefaultFinder;
use Symfony\CS\Fixer\Contrib\HeaderCommentFixer;
use Symfony\CS\FixerInterface;

$finder = DefaultFinder::create()
->in(__DIR__)
;

$header = <<<EOF
This file is part of the Security package.
(c) EXSyst
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;
HeaderCommentFixer::setHeader($header);

return Config::create()
->level(FixerInterface::SYMFONY_LEVEL)
->fixers([
'align_double_arrow',
'header_comment',
'ordered_use',
'short_array_syntax',
])
->finder($finder)
->setUsingCache(true)
;
29 changes: 29 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- hhvm

sudo: false

cache:
directories:
- $HOME/.composer/cache

branches:
only:
- master
- /^\d+\.\d+$/

matrix:
fast_finish: true
include:
- php: 5.5
env: COMPOSER_FLAGS="--prefer-lowest"

before_install:
- composer self-update

install: composer update $COMPOSER_FLAGS --prefer-dist
9 changes: 9 additions & 0 deletions Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Security package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EXSyst\Component\Security\Exception;

class InvalidArgumentException extends SecurityException
Expand Down
9 changes: 9 additions & 0 deletions Exception/SecurityException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Security package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EXSyst\Component\Security\Exception;

class SecurityException extends \RuntimeException
Expand Down
9 changes: 9 additions & 0 deletions Exception/TooShortKeyException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Security package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EXSyst\Component\Security\Exception;

class TooShortKeyException extends SecurityException
Expand Down
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
# SecurityComponent
Provides some security helpers
EXSystSecurity
=========
This component provides several tools to help you secure your app.

[![Build Status](https://travis-ci.org/EXSyst/Security.svg?branch=master)](https://travis-ci.org/EXSyst/Security)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/EXSyst/Security/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/EXSyst/Security/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/EXSyst/Security/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/EXSyst/Security/?branch=master)
[![Total Downloads](https://poser.pugx.org/EXSyst/security/downloads.svg)](https://packagist.org/packages/EXSyst/security)
[![Latest Stable Version](https://poser.pugx.org/EXSyst/security/v/stable.svg)](https://packagist.org/packages/EXSyst/security)

Installation
============
Open a command console, enter your project directory and execute the
following command to download the latest stable version of this bundle:

```bash
$ composer require exsyst/security
```

This command requires you to have Composer installed globally, as explained
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
of the Composer documentation.
9 changes: 9 additions & 0 deletions TOTP/TOTP.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Security package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EXSyst\Component\Security\TOTP;

/**
Expand Down
11 changes: 10 additions & 1 deletion TOTP/TOTPGenerator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Security package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EXSyst\Component\Security\TOTP;

use EXSyst\Component\Security\Exception\TooShortKeyException;
Expand Down Expand Up @@ -74,7 +83,7 @@ protected static function base32_decode($b32)
$j = 0;
$binary = '';

for ($i = 0; $i < $l; $i++) {
for ($i = 0; $i < $l; ++$i) {
$n = $n << 5; // Move buffer left by 5 to make room
$n = $n + self::$lut[$b32[$i]]; // Add value into buffer
$j = $j + 5; // Keep track of number of bits in buffer
Expand Down
11 changes: 10 additions & 1 deletion TOTP/TOTPKeyGenerator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Security package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EXSyst\Component\Security\TOTP;

/**
Expand All @@ -23,7 +32,7 @@ public static function generate($length = null)
}
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
for ($i = 0; $i < $length; ++$i) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}

Expand Down
9 changes: 9 additions & 0 deletions TOTP/TOTPTimeManager.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Security package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EXSyst\Component\Security\TOTP;

use EXSyst\Component\Security\Exception\InvalidArgumentException;
Expand Down
11 changes: 10 additions & 1 deletion TOTP/TOTPValidator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Security package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EXSyst\Component\Security\TOTP;

/**
Expand Down Expand Up @@ -55,7 +64,7 @@ public function validate($totp, $key, $stamp = null)
$totp = intval($totp);

// Search the stamp corresponding to the totp provided
for ($st = $stamp - $this->window; $st <= $stamp + $this->window; $st++) {
for ($st = $stamp - $this->window; $st <= $stamp + $this->window; ++$st) {
if (($res = TOTPGenerator::generate($st, $key)) == $totp) {
return $st;
}
Expand Down
11 changes: 10 additions & 1 deletion TOTP/Tests/KeyGenerationTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Security package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EXSyst\Component\Security\TOTP\Tests;

use EXSyst\Component\Security\TOTP\TOTPKeyGenerator;
Expand All @@ -10,7 +19,7 @@ class KeyGenerationTest extends \PHPUnit_Framework_TestCase

public function testKeyGeneration()
{
for ($i = 0; $i < 15; $i++) {
for ($i = 0; $i < 15; ++$i) {
$length = rand(8, 100);
$key = TOTPKeyGenerator::generate($length);
$this->assertRegExp(sprintf('#[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]{%d}#', $length), $key);
Expand Down
11 changes: 10 additions & 1 deletion TOTP/Tests/TimeManagerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Security package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EXSyst\Component\Security\TOTP\Tests;

use EXSyst\Component\Security\TOTP\TOTPTimeManager;
Expand All @@ -11,7 +20,7 @@ class TimeManagerTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->tm = [];
for ($i = 0; $i < 10; $i++) {
for ($i = 0; $i < 10; ++$i) {
$l = rand(1, 120);
$this->tm[$l] = new TOTPTimeManager($l);
}
Expand Down
13 changes: 11 additions & 2 deletions TOTP/Tests/ValidatorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Security package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EXSyst\Component\Security\TOTP\Tests;

use EXSyst\Component\Security\TOTP\TOTPGenerator;
Expand All @@ -22,9 +31,9 @@ protected function setUp()

public function testValidator()
{
for ($t = 0; $t < 10; $t++) {
for ($t = 0; $t < 10; ++$t) {
$stamp = $this->stamp + rand(-300, 300);
for ($i = -5; $i <= 5; $i++) {
for ($i = -5; $i <= 5; ++$i) {
$totp = TOTPGenerator::generate($stamp + $i, $this->key);
$this->assertEquals($stamp + $i, $this->validator->validate($totp, $this->key, $stamp + $i),
sprintf('Error during checking totp "%s" with the key "%s", the stamp "%d" and with %s stamp added', $totp, $this->key, $stamp, $i));
Expand Down
22 changes: 13 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "exsyst/security-component",
"name": "exsyst/security",
"type": "library",
"description": "Provides some security helpers",
"license": "Apache-2.0",
Expand All @@ -10,15 +10,19 @@
],
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0"
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "~4"
"symfony/phpunit-bridge": "~2.7|^3.0"
},
"autoload": {
"psr-0": {
"EXSyst\\Component\\Security": ""
}
},
"target-dir": "EXSyst/Component/Security"
"autoload": {
"psr-4": {
"EXSyst\\Component\\Security\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "0.0.x-dev"
}
}
}

0 comments on commit 0c7f045

Please sign in to comment.