Skip to content

Commit ea37af9

Browse files
committed
Correct style and PHPStan errors
1 parent 12e17bc commit ea37af9

22 files changed

+196
-186
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ matrix:
66
- php: 7.0
77
env: DEPENDENCIES='dev'
88
- php: 7.1
9-
env: DEPENDENCIES='low'
9+
env: DEPENDENCIES='low' lint=1
1010
fast_finish: true
1111

1212
sudo: false
@@ -17,6 +17,10 @@ cache:
1717

1818
before_install:
1919
- phpenv config-rm xdebug.ini || echo "xdebug not available"
20+
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
21+
- if [[ $lint = 1 ]]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.3.2/php-cs-fixer.phar; fi
22+
- if [[ $lint = 1 ]]; then composer global require --dev 'phpstan/phpstan:^0.8'; fi
23+
- export PATH="$PATH:$HOME/.composer/vendor/bin"
2024

2125
install:
2226
- if [ "$DEPENDENCIES" == "dev" ]; then composer config minimum-stability dev; fi;
@@ -28,3 +32,5 @@ script:
2832
- export SYMFONY_PHPUNIT_REMOVE="symfony/yaml"
2933
- export SYMFONY_DEPRECATIONS_HELPER=strict
3034
- vendor/bin/simple-phpunit --verbose
35+
- if [[ $lint = 1 ]]; then php php-cs-fixer.phar fix --dry-run --diff --no-ansi; fi
36+
- if [[ $lint = 1 ]]; then phpstan analyse -c phpstan.neon -l5 --ansi src tests; fi

phpstan.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
parameters:
2+
autoload_files:
3+
- vendor/autoload.php
4+
- vendor/symfony/phpunit-bridge/bin/.phpunit/phpunit-5.7.1/vendor/autoload.php
5+
6+
ignoreErrors:
7+
#- '#__construct\(\) does not call parent constructor from .+#'
8+
- '#Access to an undefined property Symfony\\Component\\Validator\\Constraint\:\:#'
9+
- "#Casting to string something that's already string#"
10+
11+
# Tests
12+
- '#Parameter \#1 \$password of method Rollerworks\\Component\\PasswordStrength\\Blacklist\\[a-zA-Z]+\:\:isBlacklisted\(\) expects string#'

src/Blacklist/ArrayProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class ArrayProvider implements BlacklistProviderInterface
2222
{
23-
private $blacklist = array();
23+
private $blacklist = [];
2424

2525
/**
2626
* @param array $blacklist

src/Blacklist/ChainProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ChainProvider implements BlacklistProviderInterface
2828
*
2929
* @param BlacklistProviderInterface[] $providers
3030
*/
31-
public function __construct(array $providers = array())
31+
public function __construct(array $providers = [])
3232
{
3333
foreach ($providers as $provider) {
3434
$this->addProvider($provider);

src/Blacklist/PdoProvider.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public function add($password)
5151
}
5252

5353
$db = $this->initDb();
54-
$args = array(
54+
$args = [
5555
':password' => $password,
5656
':created_at' => time(),
57-
);
57+
];
5858

5959
try {
6060
if ($this->isBlacklisted($password)) {
@@ -84,9 +84,9 @@ public function delete($password)
8484
}
8585

8686
$db = $this->initDb();
87-
$args = array(
87+
$args = [
8888
':password' => $password,
89-
);
89+
];
9090

9191
try {
9292
$this->exec($db, 'DELETE FROM rollerworks_passdbl WHERE passwd = :password', $args);
@@ -132,7 +132,7 @@ public function isBlacklisted($password)
132132
}
133133

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

137137
return !empty($tokenExists);
138138
}
@@ -151,7 +151,7 @@ abstract protected function initDb();
151151
*
152152
* @return mixed
153153
*/
154-
protected function fetch($db, $query, array $args = array())
154+
protected function fetch($db, $query, array $args = [])
155155
{
156156
$stmt = $this->prepareStatement($db, $query);
157157

@@ -170,7 +170,7 @@ protected function fetch($db, $query, array $args = array())
170170
*
171171
* @throws \RuntimeException
172172
*/
173-
protected function exec($db, $query, array $args = array())
173+
protected function exec($db, $query, array $args = [])
174174
{
175175
$stmt = $this->prepareStatement($db, $query);
176176

src/Blacklist/SqliteProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected function initDb()
7777
/**
7878
* {@inheritdoc}
7979
*/
80-
protected function exec($db, $query, array $args = array())
80+
protected function exec($db, $query, array $args = [])
8181
{
8282
if ($db instanceof \SQLite3) {
8383
$stmt = $this->prepareStatement($db, $query);
@@ -98,12 +98,12 @@ protected function exec($db, $query, array $args = array())
9898
/**
9999
* {@inheritdoc}
100100
*/
101-
protected function fetch($db, $query, array $args = array())
101+
protected function fetch($db, $query, array $args = [])
102102
{
103-
$return = array();
103+
$return = [];
104104

105105
if ($db instanceof \SQLite3) {
106-
$stmt = $this->prepareStatement($db, $query, true);
106+
$stmt = $this->prepareStatement($db, $query);
107107
foreach ($args as $arg => $val) {
108108
$stmt->bindValue($arg, $val, is_int($val) ? \SQLITE3_INTEGER : \SQLITE3_TEXT);
109109
}

src/Command/BlacklistCommonCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Rollerworks\Component\PasswordStrength\Command;
1313

14-
use Rollerworks\Component\PasswordStrength\Blacklist\SqliteProvider;
1514
use Rollerworks\Component\PasswordStrength\Blacklist\UpdatableBlacklistProviderInterface;
1615
use Symfony\Component\Console\Input\InputInterface;
1716
use Symfony\Component\Console\Output\OutputInterface;

src/Command/BlacklistDeleteCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Rollerworks\Component\PasswordStrength\Command;
1313

14-
use Rollerworks\Component\PasswordStrength\Blacklist\SqliteProvider;
1514
use Rollerworks\Component\PasswordStrength\Blacklist\UpdatableBlacklistProviderInterface;
1615
use Symfony\Component\Console\Input\InputArgument;
1716
use Symfony\Component\Console\Input\InputOption;

src/Command/BlacklistPurgeCommand.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@
1111

1212
namespace Rollerworks\Component\PasswordStrength\Command;
1313

14-
use Symfony\Component\Console\Helper\DialogHelper;
15-
use Symfony\Component\Console\Helper\QuestionHelper;
1614
use Symfony\Component\Console\Input\InputInterface;
1715
use Symfony\Component\Console\Input\InputOption;
1816
use Symfony\Component\Console\Output\OutputInterface;
19-
use Symfony\Component\Console\Question\ConfirmationQuestion;
2017
use Symfony\Component\Console\Style\SymfonyStyle;
2118

2219
class BlacklistPurgeCommand extends BlacklistCommand

src/Validator/Constraints/PasswordRequirementsValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function validate($value, Constraint $constraint)
3333

3434
if ($constraint->minLength > 0 && (mb_strlen($value) < $constraint->minLength)) {
3535
$this->context->buildViolation($constraint->tooShortMessage)
36-
->setParameters(array('{{length}}' => $constraint->minLength))
36+
->setParameters(['{{length}}' => $constraint->minLength])
3737
->setInvalidValue($value)
3838
->addViolation();
3939
}

0 commit comments

Comments
 (0)