Skip to content

Commit

Permalink
#3 PSR-2
Browse files Browse the repository at this point in the history
- ran PHP Coding Standards Fixer (https://github.com/FriendsOfPhp/PHP-CS-Fixer)
  • Loading branch information
metaclass-nl committed Aug 16, 2016
1 parent eeb5c89 commit 794d1b2
Show file tree
Hide file tree
Showing 23 changed files with 176 additions and 214 deletions.
3 changes: 3 additions & 0 deletions doc/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,7 @@ AuthenticationGuardBundle Issue 9: cross framework library refactoring
- FunctionalTest ::testCheckAuthenticationWithUserReleasedOnIpAddressAndCookie
made compatible with PHP 5.3
------------------------------------
#3 PSR-2
- ran PHP Coding Standards Fixer (https://github.com/FriendsOfPhp/PHP-CS-Fixer)
--------------------------------------
#2DO: tag v0.3 (when finished solving issues)
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ public function executeQuery($query, array $params = array())
}

// transactions may be needed for packing data when reducing granularity is added (NYI)
}
}
3 changes: 1 addition & 2 deletions src/Metaclass/TresholdsGovernor/Connection/PDOException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ public function __construct($errorInfo)
$this->code = $sqlState;
$this->errorInfo = $errorInfo;
}

}
}
3 changes: 1 addition & 2 deletions src/Metaclass/TresholdsGovernor/Gateway/DbalGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
*/
class DbalGateway extends RdbGateway
{

}
}
37 changes: 19 additions & 18 deletions src/Metaclass/TresholdsGovernor/Gateway/RdbGateway.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
<?php
namespace Metaclass\TresholdsGovernor\Gateway;

use Metaclass\Connection\PDOConnection;
use Metaclass\TresholdsGovernor\Connection\PDOConnection;

class RdbGateway {
class RdbGateway
{

/**
* @var PDOConnection|Doctrine\DBAL\Connection $dbalConnection The database connection to use.
* @var PDOConnection|\Doctrine\DBAL\Connection $dbalConnection The database connection to use.
*/
protected $connection;

/**
* @param PDOConnection|Doctrine\DBAL\Connection $dbalConnection The database connection to use.
* @param PDOConnection|\Doctrine\DBAL\Connection $dbalConnection The database connection to use.
*/
public function __construct($dbalConnection) {
public function __construct($dbalConnection)
{
$this->connection = $dbalConnection;
}

/**
* @return PDOConnection|Doctrine\DBAL\Connection
* @return PDOConnection|\Doctrine\DBAL\Connection
*/
protected function getConnection()
protected function getConnection()
{
return $this->connection;
}

//----------------------------- RequestCountsGatewayInterface ------------------------------------

/**
* @return int Total of $counterColumn counted for $ipAddress with dtFrom after $timeLimit
* AND as far as specified username, ipAddress and cookieToken equal to specified.
Expand Down Expand Up @@ -89,7 +91,6 @@ public function insertOrIncrementCount(\DateTime $dateTime, $username, $ipAddres
} else {
$this->createRequestCountsWith($dateTime, $ipAddress, $username, $cookieToken, $counter, $blockedCounterName);
}

}

/**
Expand All @@ -100,7 +101,8 @@ public function insertOrIncrementCount(\DateTime $dateTime, $username, $ipAddres
* @param string $ipAddress
* @param string $cookieToken
*/
protected function getCountsIdWhereDateAndUsernameAndIpAddressAndCookie(\DateTime $dateTime, $username, $ipAddress, $cookieToken) {
protected function getCountsIdWhereDateAndUsernameAndIpAddressAndCookie(\DateTime $dateTime, $username, $ipAddress, $cookieToken)
{
$sql = 'SELECT r.id FROM secu_requests r
WHERE (r.username = :username)
AND (r.ipAddress = :ipAddress)
Expand Down Expand Up @@ -184,9 +186,10 @@ protected function createRequestCountsWith($datetime, $ipAddress, $username, $co
* @param string $cookieToken
* @throws BadFunctionCallException
*/
public function updateCountsColumnWhereColumnNullAfterSupplied($columnToUpdate, \DateTime $value, \DateTime $dtLimit, $username, $ipAddress, $cookieToken) {
public function updateCountsColumnWhereColumnNullAfterSupplied($columnToUpdate, \DateTime $value, \DateTime $dtLimit, $username, $ipAddress, $cookieToken)
{
if ($username === null && $ipAddress == null) {
throw new \BadFunctionCallException ('At least one of username and ip address must be supplied');
throw new \BadFunctionCallException('At least one of username and ip address must be supplied');
}
$sql = "UPDATE secu_requests
SET $columnToUpdate = :value
Expand Down Expand Up @@ -215,7 +218,7 @@ public function updateCountsColumnWhereColumnNullAfterSupplied($columnToUpdate,
* Delete all RequestCounts with dtFrom before $dtLimit
* @param \DateTime $dtLimit
*/
public function deleteCountsUntil(\DateTime $dtLimit)
public function deleteCountsUntil(\DateTime $dtLimit)
{
$sql = 'DELETE FROM secu_requests WHERE dtFrom < :dtLimit';
$params = array('dtLimit' => $dtLimit->format('Y-m-d H:i:s'));
Expand Down Expand Up @@ -337,7 +340,7 @@ public function countAddressesBlocked(\DateTime $timeLimit, $failureLimit)
";

$conn = $this->getConnection();
$found = $conn->fetchAll( $sql, array($timeLimit->format('Y-m-d H:i:s'), $failureLimit) );
$found = $conn->fetchAll($sql, array($timeLimit->format('Y-m-d H:i:s'), $failureLimit));
return isset($found['blocked']) ? $found['blocked'] : 0;
}

Expand Down Expand Up @@ -376,7 +379,7 @@ public function insertOrUpdateRelease(\DateTime $datetime, $username, $ipAddress
* @param string $cookieToken
* @return int id of the Release
*/
protected function getReleasesIdWhereDateAndUsernameAndIpAddressAndCookie($username, $ipAddress, $cookieToken)
protected function getReleasesIdWhereDateAndUsernameAndIpAddressAndCookie($username, $ipAddress, $cookieToken)
{
$params = array(
'username' => $username,
Expand Down Expand Up @@ -459,13 +462,11 @@ public function isUserReleasedByCookieFrom($username, $cookieToken, \DateTime $r
* Delete all releases dated before $dtLimit
* @param DateTime $dtLimit
*/
public function deleteReleasesUntil(\DateTime $dtLimit)
public function deleteReleasesUntil(\DateTime $dtLimit)
{
$sql = 'DELETE FROM secu_releases WHERE releasedAt < :dtLimit';
$params = array('dtLimit' => $dtLimit->format('Y-m-d H:i:s'));

$this->getConnection()->executeQuery($sql, $params);
}
}

?>
19 changes: 8 additions & 11 deletions src/Metaclass/TresholdsGovernor/Manager/RdbManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public function countLoginsFailedForIpAddres($ipAddress, \DateTime $timeLimit)

/** {@inheritdoc} */
public function countLoginsFailedForUserName($username, \DateTime $timeLimit)
{
{
return $this->gateway->countWhereSpecifiedAfter('loginsFailed', $username, null, null, $timeLimit, 'userReleasedAt');
}

/** {@inheritdoc} */
public function countLoginsFailedForUserOnAddress($username, $ipAddress, \DateTime $timeLimit)
{
{
return $this->gateway->countWhereSpecifiedAfter('loginsFailed', $username, $ipAddress, null, $timeLimit, 'userReleasedForAddressAndCookieAt');
}

Expand All @@ -53,7 +53,7 @@ public function countLoginsFailedForUserByCookie($username, $cookieToken, \DateT
/** {@inheritdoc} */
public function insertOrIncrementSuccessCount(\DateTime $dateTime, $username, $ipAddress, $cookieToken)
{
$this->gateway->insertOrIncrementCount($dateTime, $username, $ipAddress, $cookieToken, true);
$this->gateway->insertOrIncrementCount($dateTime, $username, $ipAddress, $cookieToken, true);
}

/** {@inheritdoc} */
Expand Down Expand Up @@ -100,12 +100,12 @@ public function deleteCountsUntil(\DateTime $limit)
//StatisticsManagerInterface

/** {@inheritdoc} */
public function countLoginsFailed( \DateTime $timeLimit)
public function countLoginsFailed(\DateTime $timeLimit)
{
return $this->gateway->countWhereSpecifiedAfter('loginsFailed', null, null, null, $timeLimit);
}
/** {@inheritdoc} */
public function countLoginsSucceeded( \DateTime $timeLimit)
public function countLoginsSucceeded(\DateTime $timeLimit)
{
return $this->gateway->countWhereSpecifiedAfter('loginsSucceeded', null, null, null, $timeLimit);
}
Expand Down Expand Up @@ -151,9 +151,9 @@ public function isUserReleasedOnAddressFrom($username, $ipAddress, $timeLimit)

/** {@inheritdoc} */
public function isUserReleasedByCookieFrom($username, $cookieToken, $timeLimit)
{
return $this->gateway->isUserReleasedByCookieFrom($username, $cookieToken, $timeLimit);
}
{
return $this->gateway->isUserReleasedByCookieFrom($username, $cookieToken, $timeLimit);
}

/** {@inheritdoc} */
public function insertOrUpdateRelease($dateTime, $username, $ipAddress, $cookieToken)
Expand All @@ -166,7 +166,4 @@ public function deleteReleasesUntil($limit)
{
$this->gateway->deleteReleasesUntil($limit);
}

}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ public function insertOrUpdateRelease($dateTime, $username, $ipAddress, $cookieT
* @param \DateTime $limit
*/
public function deleteReleasesUntil($limit);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,4 @@ public function releaseCountsForUserNameAndCookie($username, $cookieToken, \Date
* @param \DateTime $limit
*/
public function deleteCountsUntil(\DateTime $limit);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ interface StatisticsManagerInterface
* @param \DateTime $timeLimit
* @return int Total of `loginsFailed` counted with `dtFrom` after $timeLimit
*/
public function countLoginsFailed( \DateTime $timeLimit);
public function countLoginsFailed(\DateTime $timeLimit);

/**
* @param \DateTime $timeLimit
* @return int Total of `loginsSucceeded` counted with `dtFrom` after $timeLimit
*/
public function countLoginsSucceeded( \DateTime $timeLimit);
public function countLoginsSucceeded(\DateTime $timeLimit);

/**
* @param $username
Expand Down Expand Up @@ -74,4 +74,4 @@ public function countsByUsernameBetween($username, \DateTime $limitFrom, \DateTi
* @return array of arrays, each with values for all column of `secu_requests`
*/
public function countsByAddressBetween($ipAddress, \DateTime $limitFrom, \DateTime $limitUntil);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ public function getCounterName()
return 'ipAddressBlocked';
}
}
?>
1 change: 0 additions & 1 deletion src/Metaclass/TresholdsGovernor/Result/Rejection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ public function __construct($message, $parameters=array())
* */
abstract public function getCounterName();
}
?>
2 changes: 0 additions & 2 deletions src/Metaclass/TresholdsGovernor/Result/UsernameBlocked.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ public function getCounterName()
{
return 'usernameBlocked';
}

}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ public function getCounterName()
{
return 'usernameBlockedForCookie';
}

}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* @copyright MetaClass Groningen 2014
*/
class UsernameBlockedForIpAddress extends Rejection
{
{
public function getCounterName()
{
return 'usernameBlockedForIpAddress';
}
}
}
Loading

0 comments on commit 794d1b2

Please sign in to comment.