From 8f507ce222e253ef926dbdb5103b8040c99abd87 Mon Sep 17 00:00:00 2001 From: ildyria Date: Tue, 6 Aug 2024 18:47:37 +0200 Subject: [PATCH] structure --- .editorconfig | 15 ++++ .gitattributes | 20 ++++++ .github/FUNDING.yml | 1 + .github/workflows/phpstan.yml | 28 ++++++++ .github/workflows/run-tests.yml | 55 +++++++++++++++ .gitignore | 11 +++ .php-cs-fixer.cache | 1 + .php-cs-fixer.php | 56 +++++++++++++++ CHANGELOG.md | 3 + Makefile | 32 +++++++++ README.md | 29 +++++++- composer.json | 68 +++++++++++++++++++ config/verify.php | 15 ++++ database/factories/ModelFactory.php | 19 ++++++ .../create_lycheeverify_table.php.stub | 19 ++++++ phpunit.xml.dist | 31 +++++++++ resources/views/.gitkeep | 0 src/Commands/VerifyCommand.php | 19 ++++++ src/Facades/VerifyFacade.php | 17 +++++ src/Providers/VerifyServiceProvider.php | 26 +++++++ src/Verify.php | 11 +++ tests/TestCase.php | 36 ++++++++++ .../Providers/WorkbenchServiceProvider.php | 25 +++++++ 23 files changed, 536 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/phpstan.yml create mode 100644 .github/workflows/run-tests.yml create mode 100644 .gitignore create mode 100644 .php-cs-fixer.cache create mode 100644 .php-cs-fixer.php create mode 100644 CHANGELOG.md create mode 100644 Makefile create mode 100644 composer.json create mode 100644 config/verify.php create mode 100644 database/factories/ModelFactory.php create mode 100644 database/migrations/create_lycheeverify_table.php.stub create mode 100644 phpunit.xml.dist create mode 100644 resources/views/.gitkeep create mode 100644 src/Commands/VerifyCommand.php create mode 100644 src/Facades/VerifyFacade.php create mode 100644 src/Providers/VerifyServiceProvider.php create mode 100755 src/Verify.php create mode 100644 tests/TestCase.php create mode 100644 workbench/app/Providers/WorkbenchServiceProvider.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..dd9a2b5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c09f81e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,20 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/phpunit.xml.dist export-ignore +/art export-ignore +/docs export-ignore +/tests export-ignore +/workbench export-ignore +/.editorconfig export-ignore +/.php_cs.dist.php export-ignore +/psalm.xml export-ignore +/psalm.xml.dist export-ignore +/testbench.yaml export-ignore +/UPGRADING.md export-ignore +/phpstan.neon.dist export-ignore +/phpstan-baseline.neon export-ignore diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..1f1d7b3 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: LycheeOrg diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..1eff4fb --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,28 @@ +name: PHPStan + +on: + push: + paths: + - '**.php' + - 'phpstan.neon' + - '.github/workflows/phpstan.yml' + +jobs: + phpstan: + name: phpstan + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + coverage: none + + - name: Install composer dependencies + uses: ramsey/composer-install@v3 + + - name: Run PHPStan + run: ./vendor/bin/phpstan --error-format=github diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..c40e569 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,55 @@ +name: run-tests + +on: + push: + paths: + - '**.php' + - '.github/workflows/run-tests.yml' + - 'phpunit.xml.dist' + - 'composer.json' + - 'composer.lock' + +jobs: + test: + runs-on: ${{ matrix.os }} + timeout-minutes: 5 + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest, windows-latest] + php: [8.3, 8.2] + laravel: [11.*] + stability: [prefer-lowest, prefer-stable] + include: + - laravel: 11.* + testbench: 9.* + carbon: ^2.63 + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.os == 'windows-latest' && '^^^' || '' }}${{ matrix.carbon }}" --no-interaction --no-update + composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: List Installed Dependencies + run: composer show -D + + - name: Execute tests + run: composer run test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a7f372d --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +.idea +.phpunit.cache +build +composer.lock +coverage +docs +phpunit.xml +phpstan.neon +testbench.yaml +vendor +node_modules diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache new file mode 100644 index 0000000..9e9ebff --- /dev/null +++ b/.php-cs-fixer.cache @@ -0,0 +1 @@ +{"php":"8.3.9","version":"3.61.1:v3.61.1#94a87189f55814e6cabca2d9a33b06de384a2ab8","indent":"\t","lineEnding":"\n","rules":{"align_multiline_comment":true,"array_syntax":true,"backtick_to_shell_exec":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["return"]},"braces_position":{"allow_single_line_anonymous_functions":true,"allow_single_line_empty_anonymous_classes":true},"class_attributes_separation":{"elements":{"method":"one"}},"class_definition":{"single_line":true},"class_reference_name_casing":true,"clean_namespace":true,"concat_space":{"spacing":"one"},"declare_parentheses":true,"echo_tag_syntax":true,"empty_loop_body":{"style":"braces"},"empty_loop_condition":true,"function_declaration":true,"general_phpdoc_tag_rename":{"replacements":{"inheritDocs":"inheritDoc"}},"global_namespace_import":{"import_classes":false,"import_constants":false,"import_functions":false},"include":true,"increment_style":{"style":"post"},"integer_literal_case":true,"lambda_not_used_import":true,"linebreak_after_opening_tag":true,"magic_constant_casing":true,"magic_method_casing":true,"method_argument_space":{"on_multiline":"ignore"},"native_function_casing":true,"native_type_declaration_casing":true,"no_alias_language_construct_call":true,"no_alternative_syntax":true,"no_binary_string":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_blank_lines":{"tokens":["attribute","case","continue","curly_brace_block","default","extra","parenthesis_brace_block","square_brace_block","switch","throw","use"]},"no_leading_namespace_whitespace":true,"no_mixed_echo_print":true,"no_multiline_whitespace_around_double_arrow":true,"no_null_property_initialization":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_trailing_comma_in_singleline":true,"no_unneeded_braces":{"namespaces":true},"no_unneeded_control_parentheses":{"statements":["break","clone","continue","echo_print","switch_case","yield"]},"no_unneeded_import_alias":true,"no_unset_cast":true,"no_unused_imports":true,"no_useless_concat_operator":true,"no_useless_nullsafe_operator":true,"no_whitespace_before_comma_in_array":true,"normalize_index_brace":true,"nullable_type_declaration_for_default_null_value":true,"object_operator_without_whitespace":true,"operator_linebreak":{"only_booleans":true,"position":"end"},"ordered_imports":{"sort_algorithm":"alpha","imports_order":null},"ordered_types":{"null_adjustment":"always_last","sort_algorithm":"none"},"php_unit_fqcn_annotation":true,"php_unit_method_casing":true,"phpdoc_align":true,"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_inline_tag_normalizer":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_order":{"order":["param","return","throws"]},"phpdoc_return_self_reference":true,"phpdoc_scalar":true,"phpdoc_separation":{"groups":[["Annotation","NamedArgumentConstructor","Target"],["author","copyright","license"],["category","package","subpackage"],["property","property-read","property-write"],["deprecated","link","see","since"]]},"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_tag_type":{"tags":{"inheritDoc":"inline"}},"phpdoc_trim":true,"phpdoc_trim_consecutive_blank_line_separation":true,"phpdoc_types":true,"phpdoc_types_order":{"null_adjustment":"always_last","sort_algorithm":"none"},"phpdoc_var_without_name":true,"semicolon_after_instruction":true,"simple_to_complex_string_variable":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_comment_spacing":true,"single_line_comment_style":{"comment_types":["hash"]},"single_line_throw":true,"single_quote":true,"single_space_around_construct":true,"space_after_semicolon":{"remove_in_empty_for_expressions":true},"standardize_increment":true,"standardize_not_equals":true,"statement_indentation":{"stick_comment_to_next_continuous_control_statement":true},"switch_continue_to_break":true,"trailing_comma_in_multiline":true,"trim_array_spaces":true,"type_declaration_spaces":true,"types_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"array_indentation":true,"cast_spaces":true,"blank_line_after_opening_tag":true,"blank_lines_before_namespace":true,"compact_nullable_type_declaration":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_parentheses":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"return_type_declaration":true,"short_scalar_cast":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_line_after_imports":true,"spaces_inside_parentheses":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"multiline_comment_opening_closing":true,"no_php4_constructor":true},"hashes":{"src\/Providers\/VerifyServiceProvider.php":"c6825d32544c6af8d699d00aebafc43a","src\/Commands\/VerifyCommand.php":"e20b4da0327e827bb92da380b382fe71","src\/Verify.php":"6a24bb3c24d7e63e35e804fcf1257f5d","src\/Facades\/VerifyFacade.php":"8843c3fcda2fd90d0f5a038437fd765e","database\/factories\/ModelFactory.php":"b91e8320557f3aeeb9c15cf96b38ca6b","config\/verify.php":"295af1204a7e9598efdd938a612e63b6","tests\/TestCase.php":"432e695df1baab54bef83616a9c70dae"}} \ No newline at end of file diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..6bd85c4 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,56 @@ +in($dir); + }, + PhpCsFixer\Finder::create()->ignoreUnreadableDirs() +)->notName('*.blade.php'); +$rules = [ + '@Symfony' => true, + 'nullable_type_declaration_for_default_null_value' => true, + 'align_multiline_comment' => true, + 'array_indentation' => true, + 'fully_qualified_strict_types' => false, + 'backtick_to_shell_exec' => true, + 'increment_style' => ['style' => 'post'], + 'indentation_type' => true, + 'multiline_comment_opening_closing' => true, + 'no_php4_constructor' => true, + 'nullable_type_declaration' => false, + 'phpdoc_no_empty_return' => false, + 'single_blank_line_at_eof' => false, + 'yoda_style' => false, + 'concat_space' => ['spacing' => 'one'], + 'no_superfluous_phpdoc_tags' => false, + 'phpdoc_to_comment' => false, // required until https://github.com/phpstan/phpstan/issues/7486 got fixed + 'blank_line_between_import_groups' => false, // not PSR-12 compatible, but preserves old behaviour + 'ordered_imports' => [ + 'sort_algorithm' => 'alpha', + 'imports_order' => null, // for PSR-12 compatability, this need to be `['class', 'function', 'const']`, but no grouping preserves old behaviour + ], + 'no_unneeded_control_parentheses' => [ + 'statements' => ['break', 'clone', 'continue', 'echo_print', 'switch_case', 'yield'], + ], + 'operator_linebreak' => [ + 'only_booleans' => true, + 'position' => 'end', + ], +]; +$config = new PhpCsFixer\Config(); + +$config->setRiskyAllowed(true); +$config->setRules($rules); +$config->setIndent("\t"); +$config->setLineEnding("\n"); +$config->setFinder($finder); + +return $config; diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..dcb1cd1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog + +All notable changes to `LycheeVerify` will be documented in this file. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6fbcd65 --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +.PHONY: dist-gen dist-clean dist clean test formatting phpstan + +composer: + rm -r vendor 2> /dev/null || true + composer install --prefer-dist --no-dev + php artisan vendor:publish --tag=log-viewer-asset + +test: + @if [ -x "vendor/bin/phpunit" ]; then \ + ./vendor/bin/phpunit --stop-on-failure; \ + else \ + echo ""; \ + echo "Please install phpunit:"; \ + echo ""; \ + echo " composer install"; \ + echo ""; \ + fi + +formatting: + @rm .php_cs.cache 2> /dev/null || true + @if [ -x "vendor/bin/php-cs-fixer" ]; then \ + PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix -v --config=.php-cs-fixer.php; \ + else \ + echo ""; \ + echo "Please install php-cs-fixer:"; \ + echo ""; \ + echo " composer install"; \ + echo ""; \ + fi + +phpstan: + vendor/bin/phpstan analyze \ No newline at end of file diff --git a/README.md b/README.md index b6e91b2..7734c93 100644 --- a/README.md +++ b/README.md @@ -1 +1,28 @@ -# verify \ No newline at end of file +# Lychee verification + +## Testing + +```bash +composer test +``` + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. + +## Contributing + +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. + +## Security Vulnerabilities + +Please review [our security policy](../../security/policy) on how to report security vulnerabilities. + +## Credits + +- [LycheeOrg](https://github.com/spatie) +- [All Contributors](../../contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..2f1ba47 --- /dev/null +++ b/composer.json @@ -0,0 +1,68 @@ +{ + "name": "lychee-org/lycheeverify", + "description": "Verification package for Lychee", + "homepage": "https://github.com/LycheeOrg/verify", + "license": "MIT", + "require": { + "php": "^8.2", + "illuminate/contracts": "^10.0||^11.0" + }, + "require-dev": { + "nunomaduro/collision": "^8.3", + "larastan/larastan": "^2.9", + "orchestra/testbench": "^9.0.0||^8.22.0", + "friendsofphp/php-cs-fixer": "^3.3", + "lychee-org/phpstan-lychee": "^v1.0.1", + "php-parallel-lint/php-parallel-lint": "^1.3", + "phpunit/phpunit": "^10.0" + }, + "autoload": { + "psr-4": { + "LycheeVerify\\": "src/", + "LycheeVerify\\Database\\Factories\\": "database/factories/" + } + }, + "autoload-dev": { + "psr-4": { + "LycheeVerify\\Tests\\": "tests/", + "Workbench\\App\\": "workbench/app/" + } + }, + "scripts": { + "post-autoload-dump": "@composer run prepare", + "clear": "@php vendor/bin/testbench package:purge-lycheeverify --ansi", + "prepare": "@php vendor/bin/testbench package:discover --ansi", + "build": [ + "@composer run prepare", + "@php vendor/bin/testbench workbench:build --ansi" + ], + "start": [ + "Composer\\Config::disableProcessTimeout", + "@composer run build", + "@php vendor/bin/testbench serve" + ], + "analyse": "vendor/bin/phpstan analyse", + "test": "vendor/bin/phpunit" + }, + "config": { + "platform": { + "php": "8.2" + }, + "sort-packages": true, + "allow-plugins": { + "phpstan/extension-installer": true + } + }, + "extra": { + "laravel": { + "providers": [ + "LycheeVerify\\VerifyServiceProvider" + ], + "aliases": { + "LycheeVerify": "LycheeVerify\\Facades\\Verify" + } + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} \ No newline at end of file diff --git a/config/verify.php b/config/verify.php new file mode 100644 index 0000000..9847458 --- /dev/null +++ b/config/verify.php @@ -0,0 +1,15 @@ + env('LYCHEE_HASHED_KEY', ''), +]; diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php new file mode 100644 index 0000000..64a54a4 --- /dev/null +++ b/database/factories/ModelFactory.php @@ -0,0 +1,19 @@ +id(); + + // add fields + + $table->timestamps(); + }); + } +}; diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..ba54ada --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,31 @@ + + + + + tests + + + + + + + + ./src + + + diff --git a/resources/views/.gitkeep b/resources/views/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/Commands/VerifyCommand.php b/src/Commands/VerifyCommand.php new file mode 100644 index 0000000..234bdcc --- /dev/null +++ b/src/Commands/VerifyCommand.php @@ -0,0 +1,19 @@ +comment('All done'); + + return self::SUCCESS; + } +} diff --git a/src/Facades/VerifyFacade.php b/src/Facades/VerifyFacade.php new file mode 100644 index 0000000..273a756 --- /dev/null +++ b/src/Facades/VerifyFacade.php @@ -0,0 +1,17 @@ +app->bind('example-name', function () { + return new \LycheeVerify\Verify(); // Replace with your actual instantiation logic. + }); + } + + public function boot(): void + { + // Publish the configuration file during package boot + if ($this->app->runningInConsole()) { + $this->publishes([ + __DIR__ . '/../config/verify.php' => config_path('verify.php'), + ], 'config'); + } + } +} diff --git a/src/Verify.php b/src/Verify.php new file mode 100755 index 0000000..3c0524a --- /dev/null +++ b/src/Verify.php @@ -0,0 +1,11 @@ + 'LycheeVerify\\Database\\Factories\\'.class_basename($modelName).'Factory' + // ); + } + + protected function getPackageProviders($app) + { + return [ + VerifyServiceProvider::class, + ]; + } + + public function getEnvironmentSetUp($app) + { + config()->set('database.default', 'testing'); + + /* + $migration = include __DIR__.'/../database/migrations/create_lycheeverify_table.php.stub'; + $migration->up(); + */ + } +} diff --git a/workbench/app/Providers/WorkbenchServiceProvider.php b/workbench/app/Providers/WorkbenchServiceProvider.php new file mode 100644 index 0000000..001d06d --- /dev/null +++ b/workbench/app/Providers/WorkbenchServiceProvider.php @@ -0,0 +1,25 @@ +