Skip to content

Commit

Permalink
refactor #5 Refactor/standards workflow (sstok)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------

| Q             | A
| ------------- | ---
| Bug fix?      |no
| New feature?  | no
| BC breaks?    | no
| Deprecations? |no
| Fixed tickets | 
| License       | MIT


Commits
-------

3c99c06 Normalize composer.json
9e8f95c Update workflow versions
1800beb Switch to rollerscapes/standards
f8dd958 Fix contribution links in README.md
62c3ed4 Fix CS
  • Loading branch information
sstok authored Nov 4, 2023
2 parents 22a439e + 62c3ed4 commit d5a1aa5
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 152 deletions.
46 changes: 18 additions & 28 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
steps:
-
name: 'Check out'
uses: 'actions/checkout@v2'
uses: 'actions/checkout@v4'

-
name: 'Set up PHP'
Expand All @@ -34,23 +34,23 @@ jobs:
-
name: 'Get Composer cache directory'
id: 'composer-cache'
run: 'echo "::set-output name=cache-dir::$(composer config cache-files-dir)"'
run: 'echo "cache_dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT'

-
name: 'Cache dependencies'
uses: 'actions/cache@v2'
uses: 'actions/cache@v3'
with:
path: '${{ steps.composer-cache.outputs.cache-dir }}'
path: '${{ steps.composer-cache.outputs.cache_dir }}'
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: 'php-${{ matrix.php-version }}-composer-locked-'

-
name: 'Install dependencies'
run: 'composer update --no-progress --prefer-stable'
run: 'composer install --no-progress'

-
name: 'Check the code style'
run: 'make cs-full'
run: 'make cs'

phpstan:
name: 'PhpStan'
Expand All @@ -65,7 +65,7 @@ jobs:
steps:
-
name: 'Check out'
uses: 'actions/checkout@v2'
uses: 'actions/checkout@v4'

-
name: 'Set up PHP'
Expand All @@ -77,19 +77,19 @@ jobs:
-
name: 'Get Composer cache directory'
id: 'composer-cache'
run: 'echo "::set-output name=cache-dir::$(composer config cache-files-dir)"'
run: 'echo "cache_dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT'

-
name: 'Cache dependencies'
uses: 'actions/cache@v2'
uses: 'actions/cache@v3'
with:
path: '${{ steps.composer-cache.outputs.cache-dir }}'
path: '${{ steps.composer-cache.outputs.cache_dir }}'
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: 'php-${{ matrix.php-version }}-composer-locked-'

-
name: 'Install dependencies'
run: 'composer update --no-progress --prefer-stable'
run: 'composer install --no-progress'

-
name: 'Run PhpStan'
Expand All @@ -104,14 +104,9 @@ jobs:
matrix:
include:
-
php-version: '8.0'
php-version: '8.1'
composer-options: '--prefer-stable'
symfony-version: '5.4'

-
php-version: '8.0'
composer-options: '--prefer-stable'
symfony-version: '6.0'
symfony-version: '6.3'
-
php-version: '8.2'
composer-options: '--prefer-stable'
Expand All @@ -125,7 +120,7 @@ jobs:
steps:
-
name: 'Check out'
uses: 'actions/checkout@v2'
uses: 'actions/checkout@v4'

-
name: 'Set up PHP'
Expand All @@ -137,13 +132,13 @@ jobs:
-
name: 'Get Composer cache directory'
id: 'composer-cache'
run: 'echo "::set-output name=cache-dir::$(composer config cache-files-dir)"'
run: 'echo "cache_dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT'

-
name: 'Cache dependencies'
uses: 'actions/cache@v2'
uses: 'actions/cache@v3'
with:
path: '${{ steps.composer-cache.outputs.cache-dir }}'
path: '${{ steps.composer-cache.outputs.cache_dir }}'
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: 'php-${{ matrix.php-version }}-composer-locked-'

Expand All @@ -157,11 +152,6 @@ jobs:
composer global require --no-progress --no-scripts --no-plugins symfony/flex
composer update --no-progress $COMPOSER_OPTIONS
-
name: 'Install PHPUnit'
run: 'vendor/bin/simple-phpunit install'

-
name: 'Run tests'
run: |
vendor/bin/simple-phpunit
run: make phpunit
63 changes: 5 additions & 58 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,64 +19,11 @@
$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],
])
->setRules(
array_merge(
require __DIR__ . '/vendor/rollerscapes/standards/php-cs-fixer-rules.php',
['header_comment' => ['header' => $header]])
)
->setFinder($finder);

return $config;
30 changes: 1 addition & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1 @@
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
lint: install cs-full phpstan

install:
composer install --no-progress --no-interaction --no-suggest --optimize-autoloader --prefer-dist --ansi

test:
./vendor/bin/phpunit --verbose

# Linting tools
phpstan: ensure
sh -c "${QA_DOCKER_COMMAND} phpstan analyse --configuration phpstan.neon"

cs: ensure
sh -c "${QA_DOCKER_COMMAND} php-cs-fixer fix -vvv --diff"

cs-full: ensure
sh -c "${QA_DOCKER_COMMAND} php-cs-fixer fix -vvv --using-cache=false --diff"

cs-full-check: ensure
sh -c "${QA_DOCKER_COMMAND} php-cs-fixer fix -vvv --using-cache=false --diff --dry-run"

ensure:
mkdir -p ${HOME}/.composer /tmp/tmp-phpqa-$(shell id -u)

.PHONY: install test phpstan cs cs-full cs-full-check
include vendor/rollerscapes/standards/Makefile
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ To install this package, add `rollerworks/password-common-list` to your composer
$ php composer.phar require rollerworks/password-common-list
```

Now, [Composer] will automatically download all required files, and install them
for you.
Now, [Composer][composer] will automatically download all required files,
and install them for you.

**Note:** To use this library with a Symfony Application make sure the
`\Rollerworks\Bundle\PasswordCommonListBundle\RollerworksPasswordCommonListBundle` is enabled.
Expand Down Expand Up @@ -62,11 +62,12 @@ This library is released under the [MIT license](LICENSE).
## Contributing

This is an open source project. If you'd like to contribute,
please read the [Contributing Guidelines]. If you're submitting
a pull request, please follow the guidelines in the [Submitting a Patch] section.
please read the [Contributing Guidelines][contributing]. If you're submitting
a pull request, please follow the guidelines in the [Submitting a Patch][patches] section.

[Symfony Validator]: (http://symfony.com/doc/current/components/validator.html
[xato-net-10-million-passwords-1000000]: https://github.com/danielmiessler/SecLists/tree/master/Passwords
[Composer]: https://getcomposer.org/doc/00-intro.md
[Contributing Guidelines]: https://github.com/rollerworks/contributing
[Submitting a Patch]: https://contributing.readthedocs.org/en/latest/code/patches.html
[composer]: https://getcomposer.org/doc/00-intro.md
[flex]: https://symfony.com/doc/current/setup/flex.html
[contributing]: https://contributing.rollerscapes.net/
[patches]: https://contributing.rollerscapes.net/latest/patches.html
32 changes: 20 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"name": "rollerworks/password-common-list",
"description": "Password CommonList validator for Symfony",
"keywords": ["password", "validator", "symfony"],
"type": "library",
"license": "MIT",
"type": "library",
"keywords": [
"password",
"validator",
"symfony"
],
"authors": [
{
"name": "Sebastiaan Stok",
Expand All @@ -23,32 +27,36 @@
"phpstan/phpstan": "^1.10.39",
"phpstan/phpstan-phpunit": "1.3.15",
"phpunit/phpunit": "^9.5",
"rollerscapes/standards": "^1.0",
"symfony/framework-bundle": "^5.3 || ^6.0 || ^7.0",
"symfony/phpunit-bridge": "^5.3 || ^6.0 || ^7.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"Rollerworks\\Component\\PasswordCommonList\\": "src/",
"Rollerworks\\Bundle\\PasswordCommonListBundle\\": "src/Bundle"
"Rollerworks\\Bundle\\PasswordCommonListBundle\\": "src/Bundle",
"Rollerworks\\Component\\PasswordCommonList\\": "src/"
},
"exclude-from-classmap": ["test/", "Resources/"]
"exclude-from-classmap": [
"test/",
"Resources/"
]
},
"autoload-dev": {
"psr-4": {
"Rollerworks\\Component\\PasswordCommonList\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-main": "1.0-dev"
}
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
"extra": {
"branch-alias": {
"dev-main": "1.0-dev"
}
}
}
8 changes: 6 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/rollerscapes/standards/phpstan.neon
#- phpstan-baseline.neon

parameters:
level: 5
#reportUnmatchedIgnoredErrors: false

paths:
- ./src
- ./tests
excludePaths:
- ./src/Resources

ignoreErrors:
#ignoreErrors:
23 changes: 7 additions & 16 deletions tests/Constraints/NotInPasswordCommonListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ protected function createValidator(): ConstraintValidatorInterface
return new NotInPasswordCommonListValidator();
}

/** @test */
public function it_ignores_empty_values(): void
public function test_it_ignores_empty_values(): void
{
$this->validator->validate(null, new NotInPasswordCommonList());
$this->assertNoViolation();
Expand All @@ -51,8 +50,7 @@ public function __toString(): string
$this->assertNoViolation();
}

/** @test */
public function no_violation_for_unlisted_password(): void
public function test_no_violation_for_unlisted_password(): void
{
$this->validator->validate('#*Xqz%<*8wHi', new NotInPasswordCommonList());
$this->assertNoViolation();
Expand All @@ -61,12 +59,8 @@ public function no_violation_for_unlisted_password(): void
$this->assertNoViolation();
}

/**
* @test
*
* @dataProvider provide_unsafe_passwords
*/
public function it_raises_a_violation_for_common_used_password_as_string(string $password): void
/** @dataProvider provide_unsafe_passwords */
public function test_it_raises_a_violation_for_common_used_password_as_string(string $password): void
{
$this->validator->validate($password, $constraint = new NotInPasswordCommonList());

Expand All @@ -76,12 +70,8 @@ public function it_raises_a_violation_for_common_used_password_as_string(string
;
}

/**
* @test
*
* @dataProvider provide_unsafe_passwords
*/
public function it_raises_a_violation_for_common_used_password_as_stringable(string $password): void
/** @dataProvider provide_unsafe_passwords */
public function test_it_raises_a_violation_for_common_used_password_as_stringable(string $password): void
{
$value = new class($password) implements \Stringable {
private string $password;
Expand All @@ -105,6 +95,7 @@ public function __toString(): string
;
}

/** @return iterable<int, array{0: string}> */
public function provide_unsafe_passwords(): iterable
{
yield ['hunter'];
Expand Down

0 comments on commit d5a1aa5

Please sign in to comment.