From b9103aef69476baf7cd3d4dc7c6736b8b997311b Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Sun, 7 Jul 2024 13:01:11 +0700 Subject: [PATCH 01/12] #1 feat: add test running and style code tools --- .gitignore | 47 +++++++++++++++++++++++++++-------------------- .scrutinizer.yml | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 .scrutinizer.yml diff --git a/.gitignore b/.gitignore index 2e9c4f6..46caeb9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,31 @@ -/vendor/ -node_modules/ -npm-debug.log -yarn-error.log - -# Laravel 4 specific -bootstrap/compiled.php -app/storage/ - -# Laravel 5 & Lumen specific -public/storage -public/hot +/vendor +composer.lock +composer.phar +.DS_Store +/node_modules +/public/storage +/storage/*.key +Thumbs.db +/bower_components -# Laravel 5 & Lumen specific with changed public path -public_html/storage -public_html/hot - -storage/*.key .env -.idea/ -Homestead.yaml +.env.backup +.idea +.vscode + +.vagrant Homestead.json -/.vagrant +Homestead.yaml +npm-debug.log + +.phpunit.cache .phpunit.result.cache +/storage/.license +/storage/fonts +/storage/installing +/storage/installed +/log + +package-lock.json +yarn.lock +/.sass-cache diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..dcc939f --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,42 @@ +build: + nodes: + analysis: + project_setup: + override: true + tests: + override: [ php-scrutinizer-run ] + environment: + php: + version: 8.0 + +checks: + php: + code_rating: true + remove_extra_empty_lines: true + remove_php_closing_tag: true + remove_trailing_whitespace: true + fix_use_statements: + remove_unused: true + preserve_multiple: false + preserve_blanklines: true + order_alphabetically: true + fix_php_opening_tag: true + fix_linefeed: true + fix_line_ending: true + fix_identation_4spaces: true + fix_doc_comments: true + +tools: + php_analyzer: true + php_code_coverage: true + php_code_sniffer: + config: + standard: PSR4 + filter: + paths: [ 'src' ] + php_loc: + enabled: true + excluded_dirs: [ vendor ] + php_cpd: + enabled: true + excluded_dirs: [ vendor ] From ef682539f4f1c3b3452dd2b7a390fda3e0e90794 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Sun, 7 Jul 2024 13:01:27 +0700 Subject: [PATCH 02/12] #1 feat: add test running and style code tools --- .styleci.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .styleci.yml diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..06256fb --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,4 @@ +preset: laravel + +disabled: + - not_operator_with_successor_space From a24b6064ce3a6865e60df7c29d665e2dbf59ca21 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Sun, 7 Jul 2024 13:04:19 +0700 Subject: [PATCH 03/12] #1 feat: init require files --- common/helpers.php | 0 composer.json | 0 config/blog-api.php | 0 phpunit.xml | 20 ++++++++++++++++++++ routes/blog-api.php | 0 src/Providers/BlogApiServiceProvider.php | 0 tests/IntegrationTest.php | 7 +++++++ 7 files changed, 27 insertions(+) create mode 100644 common/helpers.php create mode 100644 composer.json create mode 100644 config/blog-api.php create mode 100644 phpunit.xml create mode 100644 routes/blog-api.php create mode 100644 src/Providers/BlogApiServiceProvider.php create mode 100644 tests/IntegrationTest.php diff --git a/common/helpers.php b/common/helpers.php new file mode 100644 index 0000000..e69de29 diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..e69de29 diff --git a/config/blog-api.php b/config/blog-api.php new file mode 100644 index 0000000..e69de29 diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..3b5640c --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,20 @@ + + + + + src/ + + + + + tests + + + diff --git a/routes/blog-api.php b/routes/blog-api.php new file mode 100644 index 0000000..e69de29 diff --git a/src/Providers/BlogApiServiceProvider.php b/src/Providers/BlogApiServiceProvider.php new file mode 100644 index 0000000..e69de29 diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php new file mode 100644 index 0000000..55bdbe1 --- /dev/null +++ b/tests/IntegrationTest.php @@ -0,0 +1,7 @@ + Date: Sun, 7 Jul 2024 13:18:44 +0700 Subject: [PATCH 04/12] #1 feat: update composer to add cslant blog api package --- composer.json | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/composer.json b/composer.json index e69de29..d48c5c7 100644 --- a/composer.json +++ b/composer.json @@ -0,0 +1,70 @@ +{ + "name": "cslant/blog-api-package", + "description": "Send notification from Gitlab and Github events to Telegram", + "keywords": [ + "cslant", + "laravel", + "cslant-blog-api-package", + "cslant-blog-api", + "cslant-blog", + "cslant-api", + "cslant-package", + "blog-api-package" + ], + "homepage": "https://github.com/cslant/blog-api-package", + "license": "MIT", + "authors": [ + { + "name": "Tan Nguyen", + "email": "tannp27@gmail.com", + "homepage": "https://tanhongit.com", + "role": "Developer" + } + ], + "autoload": { + "psr-4": { + "CSlant\\BlogApi\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "CSlant\\BlogApi\\Tests\\": "tests/" + } + }, + "require": { + "php": "^8.1" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^v3.0", + "nunomaduro/collision": "^7.10", + "nunomaduro/larastan": "^2.9", + "orchestra/testbench": "^8.0", + "pestphp/pest": "^2.0", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan-deprecation-rules": "^1.1", + "phpstan/phpstan-phpunit": "^1.3" + }, + "scripts": { + "analyse": "vendor/bin/phpstan analyse", + "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes" + }, + "support": { + "issues": "https://github.com/cslant/blog-api-package/issues" + }, + "extra": { + "laravel": { + "providers": [ + "CSlant\\BlogApi\\Providers\\BlogApiServiceProvider" + ] + } + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true, + "phpstan/extension-installer": true + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} From f157d94f63daabd3463df445e39bf72e0d217d81 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Sun, 7 Jul 2024 13:30:41 +0700 Subject: [PATCH 05/12] #1 feat: init provider for blog api --- src/Providers/BlogApiServiceProvider.php | 73 ++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/Providers/BlogApiServiceProvider.php b/src/Providers/BlogApiServiceProvider.php index e69de29..20d4a9b 100644 --- a/src/Providers/BlogApiServiceProvider.php +++ b/src/Providers/BlogApiServiceProvider.php @@ -0,0 +1,73 @@ +loadRoutesFrom($routePath); + } + + $this->loadTranslationsFrom(__DIR__.'/../../lang', 'blog-api'); + + $this->registerCommands(); + + $this->registerAssetPublishing(); + } + + /** + * Register services. + * + * @return void + */ + public function register(): void + { + $configPath = __DIR__.'/../../config/blog-api.php'; + $this->mergeConfigFrom($configPath, 'blog-api'); + } + + /** + * Get the services provided by the provider. + * + * @return array|null + */ + public function provides(): ?array + { + return ['blog-api']; + } + + /** + * @return void + */ + protected function registerCommands(): void + { + $this->commands([ + // + ]); + } + + /** + * @return void + */ + protected function registerAssetPublishing(): void + { + $configPath = __DIR__.'/../../config/blog-api.php'; + $this->publishes([ + $configPath => config_path('blog-api.php'), + ], 'config'); + + $this->publishes([ + __DIR__.'/../../lang' => resource_path('lang/packages/blog-api'), + ], 'lang'); + } +} From eb0904e2345097cdedd4b6a3ee84d2553441665a Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Sun, 7 Jul 2024 13:36:15 +0700 Subject: [PATCH 06/12] #1 feat: init lang folder --- lang/en/blog-api.php | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 lang/en/blog-api.php diff --git a/lang/en/blog-api.php b/lang/en/blog-api.php new file mode 100644 index 0000000..65283c3 --- /dev/null +++ b/lang/en/blog-api.php @@ -0,0 +1,5 @@ + 'Hello from the blog API!', +]; From 07b5dbc39bf30611d4b572b0052d5bc58bcd4184 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Sun, 7 Jul 2024 13:36:48 +0700 Subject: [PATCH 07/12] #1 feat: init route for the bot API with config and env --- config/blog-api.php | 10 ++++++++++ routes/blog-api.php | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/config/blog-api.php b/config/blog-api.php index e69de29..3d8509d 100644 --- a/config/blog-api.php +++ b/config/blog-api.php @@ -0,0 +1,10 @@ + [ + /* Set route prefix for the blog API */ + 'route_prefix' => $routePrefix, + ], +]; diff --git a/routes/blog-api.php b/routes/blog-api.php index e69de29..3c476cd 100644 --- a/routes/blog-api.php +++ b/routes/blog-api.php @@ -0,0 +1,24 @@ +name("$routePrefix.")->group(function () { + Route::get('/posts', function () { + return response()->json([ + 'message' => 'Hello from the blog API!', + ]); + }); +}); From 70b8b69bf1a58e1a0b3573f4414c6ab35f157944 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Sun, 7 Jul 2024 13:39:29 +0700 Subject: [PATCH 08/12] #1 feat: add phpstan to analyze "phpstan/extension-installer": "^1.3", "phpstan/phpstan-deprecation-rules": "^1.1", "phpstan/phpstan-phpunit": "^1.3" --- phpstan-baseline.neon | 0 phpstan.neon.dist | 11 +++++++++++ 2 files changed, 11 insertions(+) create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon.dist diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..e69de29 diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..5da8159 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,11 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 9 + paths: + - src + - routes + tmpDir: build/phpstan + checkOctaneCompatibility: true + checkModelProperties: true From c8dc7aed5bef9fca3dbcd1fdd210b3d4a9cfcfeb Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Sun, 7 Jul 2024 14:17:38 +0700 Subject: [PATCH 09/12] #1 fix: ignore phpstan error --- phpstan-baseline.neon | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e69de29..2d0db27 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -0,0 +1,7 @@ +parameters: + ignoreErrors: + - message: '#Parameter \#1 \$prefix of static method Illuminate\\Support\\Facades\\Route::prefix\(\) expects string, mixed given\.#' + path: routes/blog-api.php + + - message: '#Part \$routePrefix \(mixed\) of encapsed string cannot be cast to string\.#' + path: routes/blog-api.php From 27d1d29a5dbc663e55c58583c4c28a905289202c Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Mon, 8 Jul 2024 00:52:10 +0700 Subject: [PATCH 10/12] #1 feat: create new model trait for base model --- .gitignore | 2 +- src/Models/Traits/IsIncrementing.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 src/Models/Traits/IsIncrementing.php diff --git a/.gitignore b/.gitignore index 46caeb9..29f0943 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,7 @@ npm-debug.log /storage/installing /storage/installed /log - +build package-lock.json yarn.lock /.sass-cache diff --git a/src/Models/Traits/IsIncrementing.php b/src/Models/Traits/IsIncrementing.php new file mode 100644 index 0000000..8f136bf --- /dev/null +++ b/src/Models/Traits/IsIncrementing.php @@ -0,0 +1,8 @@ + Date: Mon, 8 Jul 2024 02:05:43 +0700 Subject: [PATCH 11/12] #1 fix: update first api --- routes/blog-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/blog-api.php b/routes/blog-api.php index 3c476cd..166cb52 100644 --- a/routes/blog-api.php +++ b/routes/blog-api.php @@ -16,7 +16,7 @@ $routePrefix = config('blog-api.defaults.route_prefix'); Route::prefix($routePrefix)->name("$routePrefix.")->group(function () { - Route::get('/posts', function () { + Route::get('/hello', function () { return response()->json([ 'message' => 'Hello from the blog API!', ]); From b949e43b366f98b7bfa291169eb813e3fd91ab26 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Mon, 8 Jul 2024 02:07:12 +0700 Subject: [PATCH 12/12] #5 fix: PR template --- .github/{pull_request_tempalet.md => pull_request_template.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{pull_request_tempalet.md => pull_request_template.md} (100%) diff --git a/.github/pull_request_tempalet.md b/.github/pull_request_template.md similarity index 100% rename from .github/pull_request_tempalet.md rename to .github/pull_request_template.md