Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/.php_cs.cache
symfony.lock
.phpunit.result.cache
.php-cs-fixer.cache
81 changes: 81 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

$header = <<<EOF
This file is part of the RollerworksPasswordStrengthValidator package.

(c) Sebastiaan Stok <[email protected]>

This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

/** @var \Symfony\Component\Finder\Finder $finder */
$finder = PhpCsFixer\Finder::create();
$finder
->in([__DIR__.'/src', __DIR__.'/tests'])
;

$config = new PhpCsFixer\Config();
$config
->setRiskyAllowed(true)
->setRules([
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP73Migration' => true,
'@PHPUnit84Migration:risky' => true,
'@DoctrineAnnotation' => true,
'blank_line_before_statement' => [
'statements' => [
'break',
'case',
'continue',
'declare',
'default',
'do',
'exit',
'for',
'foreach',
'goto',
'if',
'include',
'include_once',
'require',
'require_once',
'return',
'switch',
'throw',
'try',
'while',
],
],
'comment_to_phpdoc' => ['ignored_tags' => ['codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd']],
'concat_space' => ['spacing' => 'one'],
'doctrine_annotation_array_assignment' => ['operator' => '='],
'general_phpdoc_annotation_remove' => ['annotations' => ['author', 'since', 'package', 'subpackage']],
'header_comment' => ['header' => $header],
'list_syntax' => ['syntax' => 'short'],
'mb_str_functions' => true,
'method_argument_space' => ['on_multiline' => 'ignore'],
'method_chaining_indentation' => false,
'no_extra_blank_lines' => ['tokens' => ['extra', 'use_trait']],
'no_superfluous_phpdoc_tags' => ['remove_inheritdoc' => true],
'not_operator_with_successor_space' => true,
'ordered_class_elements' => false,
'ordered_imports' => true,
'php_unit_method_casing' => ['case' => 'snake_case'],
'php_unit_strict' => false,
'php_unit_test_annotation' => ['style' => 'annotation'],
'php_unit_test_class_requires_covers' => false,
'phpdoc_to_comment' => false,
'phpdoc_var_without_name' => false,
'self_static_accessor' => true,
'single_line_throw' => false,
'static_lambda' => true,
'strict_comparison' => false,
'yoda_style' => ['equal' => false, 'identical' => false],
])
->setFinder($finder);

return $config;
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QA_DOCKER_IMAGE=jakzal/phpqa:1.34.1-php7.4-alpine
QA_DOCKER_IMAGE=jakzal/phpqa:1.59.1-php7.4-alpine
QA_DOCKER_COMMAND=docker run --init -t --rm --user "$(shell id -u):$(shell id -g)" --volume /tmp/tmp-phpqa-$(shell id -u):/tmp --volume "$(shell pwd):/project" --workdir /project ${QA_DOCKER_IMAGE}

dist: install cs-full phpstan test-full
Expand Down
7 changes: 1 addition & 6 deletions src/Blacklist/ArrayProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* Array Blacklist Provider.
*
* Provides the blacklist from an array.
*
* @author Sebastiaan Stok <[email protected]>
*/
class ArrayProvider implements BlacklistProviderInterface
{
Expand All @@ -27,12 +25,9 @@ public function __construct(array $blacklist)
$this->blacklist = $blacklist;
}

/**
* {@inheritdoc}
*/
public function isBlacklisted($password)
{
if (in_array($password, $this->blacklist, true)) {
if (\in_array($password, $this->blacklist, true)) {
return true;
}

Expand Down
2 changes: 0 additions & 2 deletions src/Blacklist/BlacklistProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

/**
* Blacklist Provider Interface.
*
* @author Sebastiaan Stok <[email protected]>
*/
interface BlacklistProviderInterface
{
Expand Down
4 changes: 1 addition & 3 deletions src/Blacklist/ChainProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

/**
* Chained blacklist provider.
*
* @author Sebastiaan Stok <[email protected]>
*/
class ChainProvider implements BlacklistProviderInterface
{
Expand Down Expand Up @@ -71,7 +69,7 @@ public function getProviders()
public function isBlacklisted($password)
{
foreach ($this->providers as $provider) {
if (true === $provider->isBlacklisted($password)) {
if ($provider->isBlacklisted($password) === true) {
return true;
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/Blacklist/LazyChainProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

/**
* Chained blacklist provider.
*
* @author Sebastiaan Stok <[email protected]>
*/
final class LazyChainProvider implements BlacklistProviderInterface
{
Expand All @@ -42,7 +40,7 @@ public function __construct(ContainerInterface $container, array $providers)
public function isBlacklisted($password)
{
foreach ($this->providers as $provider) {
if (true === $this->container->get($provider)->isBlacklisted($password)) {
if ($this->container->get($provider)->isBlacklisted($password) === true) {
return true;
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/Blacklist/NoopProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@
* Noop Blacklist Provider.
*
* Always returns false.
*
* @author Sebastiaan Stok <[email protected]>
*/
class NoopProvider implements BlacklistProviderInterface
{
/**
* {@inheritdoc}
*/
public function isBlacklisted($password)
{
return false;
Expand Down
42 changes: 12 additions & 30 deletions src/Blacklist/PdoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

/**
* Sqlite Blacklist Provider.
*
* @author Sebastiaan Stok <[email protected]>
*/
abstract class PdoProvider implements UpdatableBlacklistProviderInterface
{
Expand All @@ -37,16 +35,13 @@ public function __construct($dsn, $username = '', $password = '')
$this->password = $password;
}

/**
* {@inheritdoc}
*/
public function add($password)
{
if (!is_scalar($password)) {
if (! is_scalar($password)) {
throw new \InvalidArgumentException('Only scalar values are accepted.');
}

if ('' === $password) {
if ($password === '') {
return -1;
}

Expand All @@ -67,19 +62,16 @@ public function add($password)
$status = false;
}

if (!$status) {
if (! $status) {
$this->close($db);
}

return $status;
}

/**
* {@inheritdoc}
*/
public function delete($password)
{
if (!is_scalar($password)) {
if (! is_scalar($password)) {
throw new \InvalidArgumentException('Only scalar values are accepted.');
}

Expand All @@ -95,46 +87,37 @@ public function delete($password)
$status = false;
}

if (!$status) {
if (! $status) {
$this->close($db);
}

return $status;
}

/**
* {@inheritdoc}
*/
public function all()
{
$db = $this->initDb();

return $this->exec($db, 'SELECT passwd FROM rollerworks_passdbl');
}

/**
* {@inheritdoc}
*/
public function purge()
{
$db = $this->initDb();
$this->exec($db, 'DELETE FROM rollerworks_passdbl');
$this->close($db);
}

/**
* {@inheritdoc}
*/
public function isBlacklisted($password)
{
if (!is_scalar($password)) {
if (! is_scalar($password)) {
throw new \InvalidArgumentException('Only scalar values are accepted.');
}

$db = $this->initDb();
$tokenExists = $this->fetch($db, 'SELECT 1 FROM rollerworks_passdbl WHERE passwd = :password LIMIT 1', [':password' => $password]);

return !empty($tokenExists);
return ! empty($tokenExists);
}

/**
Expand All @@ -147,15 +130,13 @@ abstract protected function initDb();
/**
* @param object $db
* @param string $query
*
* @return mixed
*/
protected function fetch($db, $query, array $args = [])
{
$stmt = $this->prepareStatement($db, $query);

foreach ($args as $arg => $val) {
$stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
$stmt->bindValue($arg, $val, \is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
}
$stmt->execute();

Expand All @@ -173,11 +154,12 @@ protected function exec($db, $query, array $args = [])
$stmt = $this->prepareStatement($db, $query);

foreach ($args as $arg => $val) {
$stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
$stmt->bindValue($arg, $val, \is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
}

$success = $stmt->execute();
if (!$success) {

if (! $success) {
throw new \RuntimeException(sprintf('Error executing query "%s".', $query));
}
}
Expand All @@ -198,7 +180,7 @@ protected function prepareStatement($db, $query)
$stmt = false;
}

if (false === $stmt) {
if ($stmt === false) {
throw new \RuntimeException('The database cannot successfully prepare the statement.');
}

Expand Down
Loading