From 3343b7fe4ec78cca18e887209dac0645cb276134 Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Wed, 19 Feb 2025 18:27:23 +0530 Subject: [PATCH 01/11] Add Laravel CI workflow --- .github/workflows/ci.yml | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..916f465 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,66 @@ +name: Laravel CI + +on: [push, pull_request] # Run CI on every push and PR + +jobs: + laravel-tests: + runs-on: ubuntu-latest + + services: + mysql: + image: mysql:8 + env: + MYSQL_DATABASE: testing_db + MYSQL_USER: user + MYSQL_PASSWORD: password + MYSQL_ROOT_PASSWORD: root + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping --host=localhost --user=root --password=root" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: mbstring, bcmath, pdo, pdo_mysql + coverage: none + + - name: Install Composer Dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: Setup Environment + run: | + cp .env.example .env + php artisan key:generate + + - name: Run Migrations + env: + DB_CONNECTION: mysql + DB_DATABASE: testing_db + DB_USERNAME: user + DB_PASSWORD: password + DB_HOST: 127.0.0.1 + run: php artisan migrate --force + + - name: Run Pint (Code Formatting) + run: composer require laravel/pint --dev && ./vendor/bin/pint --test + + - name: Run PHPStan (Static Analysis) + run: composer require nunomaduro/larastan --dev && ./vendor/bin/phpstan analyse --memory-limit=1G + + - name: Run Pest Tests + env: + DB_CONNECTION: mysql + DB_DATABASE: testing_db + DB_USERNAME: user + DB_PASSWORD: password + DB_HOST: 127.0.0.1 + run: php artisan test --parallel From bb40a26089364d0710a1c4e1c216a7823b866876 Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Wed, 19 Feb 2025 18:51:22 +0530 Subject: [PATCH 02/11] Update Laravel CI workflow and dependencies --- .github/workflows/ci.yml | 22 ++++++++++++++-------- composer.json | 4 +++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 916f465..c10d5ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ -name: Laravel CI +name: Laravel CI Test -on: [push, pull_request] # Run CI on every push and PR +on: [push, pull_request] jobs: laravel-tests: @@ -36,7 +36,10 @@ jobs: - name: Install Composer Dependencies run: composer install --no-progress --prefer-dist --optimize-autoloader - - name: Setup Environment + - name: Install Node Dependencies + run: npm install + + - name: Setup Laravel Environment run: | cp .env.example .env php artisan key:generate @@ -50,13 +53,16 @@ jobs: DB_HOST: 127.0.0.1 run: php artisan migrate --force - - name: Run Pint (Code Formatting) - run: composer require laravel/pint --dev && ./vendor/bin/pint --test + # Check PHP code formatting with PHPFMT + - name: Run PHPFMT + run: ./vendor/bin/phpmd app,routes text cleancode,codesize,controversial,design,naming,unusedcode - - name: Run PHPStan (Static Analysis) - run: composer require nunomaduro/larastan --dev && ./vendor/bin/phpstan analyse --memory-limit=1G + # Static analysis using Larastan + - name: Run Larastan + run: ./vendor/bin/phpstan analyse --memory-limit=1G - - name: Run Pest Tests + # Run Laravel tests + - name: Run Laravel Tests env: DB_CONNECTION: mysql DB_DATABASE: testing_db diff --git a/composer.json b/composer.json index cd7c17a..8c1a0c8 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,10 @@ "laravel/sail": "^1.26", "mockery/mockery": "^1.6", "nunomaduro/collision": "^8.1", + "nunomaduro/larastan": "^3.0", "pestphp/pest": "^3.7", - "pestphp/pest-plugin-laravel": "^3.1" + "pestphp/pest-plugin-laravel": "^3.1", + "phpmd/phpmd": "^2.15" }, "autoload": { "psr-4": { From 56431c536d455b3a1aa524336e14c5aac4645076 Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Fri, 21 Feb 2025 12:10:26 +0530 Subject: [PATCH 03/11] Update Laravel CI workflow and dependencies --- composer.lock | 903 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 865 insertions(+), 38 deletions(-) diff --git a/composer.lock b/composer.lock index 4dd1623..a7521e9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1232c6e6c7cb602f02276a5bb355ec1b", + "content-hash": "28399c373e33c98f230439dbed86d7ad", "packages": [ { "name": "brick/math", @@ -6040,6 +6040,151 @@ ], "time": "2024-12-11T14:50:44+00:00" }, + { + "name": "composer/pcre", + "version": "3.3.2", + "source": { + "type": "git", + "url": "https://github.com/composer/pcre.git", + "reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/pcre/zipball/b2bed4734f0cc156ee1fe9c0da2550420d99a21e", + "reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0" + }, + "conflict": { + "phpstan/phpstan": "<1.11.10" + }, + "require-dev": { + "phpstan/phpstan": "^1.12 || ^2", + "phpstan/phpstan-strict-rules": "^1 || ^2", + "phpunit/phpunit": "^8 || ^9" + }, + "type": "library", + "extra": { + "phpstan": { + "includes": [ + "extension.neon" + ] + }, + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Pcre\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "PCRE wrapping library that offers type-safe preg_* replacements.", + "keywords": [ + "PCRE", + "preg", + "regex", + "regular expression" + ], + "support": { + "issues": "https://github.com/composer/pcre/issues", + "source": "https://github.com/composer/pcre/tree/3.3.2" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2024-11-12T16:29:46+00:00" + }, + { + "name": "composer/xdebug-handler", + "version": "3.0.5", + "source": { + "type": "git", + "url": "https://github.com/composer/xdebug-handler.git", + "reference": "6c1925561632e83d60a44492e0b344cf48ab85ef" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/6c1925561632e83d60a44492e0b344cf48ab85ef", + "reference": "6c1925561632e83d60a44492e0b344cf48ab85ef", + "shasum": "" + }, + "require": { + "composer/pcre": "^1 || ^2 || ^3", + "php": "^7.2.5 || ^8.0", + "psr/log": "^1 || ^2 || ^3" + }, + "require-dev": { + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-strict-rules": "^1.1", + "phpunit/phpunit": "^8.5 || ^9.6 || ^10.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Composer\\XdebugHandler\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "John Stevenson", + "email": "john-stevenson@blueyonder.co.uk" + } + ], + "description": "Restarts a process without Xdebug.", + "keywords": [ + "Xdebug", + "performance" + ], + "support": { + "irc": "ircs://irc.libera.chat:6697/composer", + "issues": "https://github.com/composer/xdebug-handler/issues", + "source": "https://github.com/composer/xdebug-handler/tree/3.0.5" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2024-05-06T16:37:16+00:00" + }, { "name": "doctrine/deprecations", "version": "1.1.4", @@ -6899,6 +7044,163 @@ ], "time": "2025-01-23T13:41:43+00:00" }, + { + "name": "nunomaduro/larastan", + "version": "v3.1.0", + "source": { + "type": "git", + "url": "https://github.com/larastan/larastan.git", + "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/larastan/larastan/zipball/dbb2dc20e5c8e1ed3ff289054e1955f269187312", + "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312", + "shasum": "" + }, + "require": { + "ext-json": "*", + "illuminate/console": "^11.15.0 || ^12.0", + "illuminate/container": "^11.15.0 || ^12.0", + "illuminate/contracts": "^11.15.0 || ^12.0", + "illuminate/database": "^11.15.0 || ^12.0", + "illuminate/http": "^11.15.0 || ^12.0", + "illuminate/pipeline": "^11.15.0 || ^12.0", + "illuminate/support": "^11.15.0 || ^12.0", + "php": "^8.2", + "phpmyadmin/sql-parser": "^5.9.0", + "phpstan/phpstan": "^2.1.3" + }, + "require-dev": { + "doctrine/coding-standard": "^12.0", + "laravel/framework": "^11.15.0 || ^12.0", + "mockery/mockery": "^1.6", + "nikic/php-parser": "^5.3", + "orchestra/canvas": "^v9.1.3 || ^10.0", + "orchestra/testbench-core": "^9.5.2 || ^10.0", + "phpstan/phpstan-deprecation-rules": "^2.0.0", + "phpunit/phpunit": "^10.5.35 || ^11.3.6" + }, + "suggest": { + "orchestra/testbench": "Using Larastan for analysing a package needs Testbench" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon" + ] + }, + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Larastan\\Larastan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Can Vural", + "email": "can9119@gmail.com" + }, + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "larastan", + "laravel", + "package", + "php", + "static analysis" + ], + "support": { + "issues": "https://github.com/larastan/larastan/issues", + "source": "https://github.com/larastan/larastan/tree/v3.1.0" + }, + "funding": [ + { + "url": "https://github.com/canvural", + "type": "github" + } + ], + "abandoned": "larastan/larastan", + "time": "2025-02-20T15:25:15+00:00" + }, + { + "name": "pdepend/pdepend", + "version": "2.16.2", + "source": { + "type": "git", + "url": "https://github.com/pdepend/pdepend.git", + "reference": "f942b208dc2a0868454d01b29f0c75bbcfc6ed58" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pdepend/pdepend/zipball/f942b208dc2a0868454d01b29f0c75bbcfc6ed58", + "reference": "f942b208dc2a0868454d01b29f0c75bbcfc6ed58", + "shasum": "" + }, + "require": { + "php": ">=5.3.7", + "symfony/config": "^2.3.0|^3|^4|^5|^6.0|^7.0", + "symfony/dependency-injection": "^2.3.0|^3|^4|^5|^6.0|^7.0", + "symfony/filesystem": "^2.3.0|^3|^4|^5|^6.0|^7.0", + "symfony/polyfill-mbstring": "^1.19" + }, + "require-dev": { + "easy-doc/easy-doc": "0.0.0|^1.2.3", + "gregwar/rst": "^1.0", + "squizlabs/php_codesniffer": "^2.0.0" + }, + "bin": [ + "src/bin/pdepend" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "PDepend\\": "src/main/php/PDepend" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Official version of pdepend to be handled with Composer", + "keywords": [ + "PHP Depend", + "PHP_Depend", + "dev", + "pdepend" + ], + "support": { + "issues": "https://github.com/pdepend/pdepend/issues", + "source": "https://github.com/pdepend/pdepend/tree/2.16.2" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/pdepend/pdepend", + "type": "tidelift" + } + ], + "time": "2023-12-17T18:09:59+00:00" + }, { "name": "pestphp/pest", "version": "v3.7.4", @@ -7591,73 +7893,301 @@ "time": "2024-11-09T15:12:26+00:00" }, { - "name": "phpstan/phpdoc-parser", - "version": "2.0.1", + "name": "phpmd/phpmd", + "version": "2.15.0", "source": { "type": "git", - "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "72e51f7c32c5aef7c8b462195b8c599b11199893" + "url": "https://github.com/phpmd/phpmd.git", + "reference": "74a1f56e33afad4128b886e334093e98e1b5e7c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/72e51f7c32c5aef7c8b462195b8c599b11199893", - "reference": "72e51f7c32c5aef7c8b462195b8c599b11199893", + "url": "https://api.github.com/repos/phpmd/phpmd/zipball/74a1f56e33afad4128b886e334093e98e1b5e7c0", + "reference": "74a1f56e33afad4128b886e334093e98e1b5e7c0", "shasum": "" }, "require": { - "php": "^7.4 || ^8.0" + "composer/xdebug-handler": "^1.0 || ^2.0 || ^3.0", + "ext-xml": "*", + "pdepend/pdepend": "^2.16.1", + "php": ">=5.3.9" }, "require-dev": { - "doctrine/annotations": "^2.0", - "nikic/php-parser": "^5.3.0", - "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^2.0", - "phpstan/phpstan-phpunit": "^2.0", - "phpstan/phpstan-strict-rules": "^2.0", - "phpunit/phpunit": "^9.6", - "symfony/process": "^5.2" + "easy-doc/easy-doc": "0.0.0 || ^1.3.2", + "ext-json": "*", + "ext-simplexml": "*", + "gregwar/rst": "^1.0", + "mikey179/vfsstream": "^1.6.8", + "squizlabs/php_codesniffer": "^2.9.2 || ^3.7.2" }, + "bin": [ + "src/bin/phpmd" + ], "type": "library", "autoload": { - "psr-4": { - "PHPStan\\PhpDocParser\\": [ - "src/" - ] + "psr-0": { + "PHPMD\\": "src/main/php" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Manuel Pichler", + "email": "github@manuel-pichler.de", + "homepage": "https://github.com/manuelpichler", + "role": "Project Founder" + }, + { + "name": "Marc Würth", + "email": "ravage@bluewin.ch", + "homepage": "https://github.com/ravage84", + "role": "Project Maintainer" + }, + { + "name": "Other contributors", + "homepage": "https://github.com/phpmd/phpmd/graphs/contributors", + "role": "Contributors" + } + ], + "description": "PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD.", + "homepage": "https://phpmd.org/", + "keywords": [ + "dev", + "mess detection", + "mess detector", + "pdepend", + "phpmd", + "pmd" ], - "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { - "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/2.0.1" + "irc": "irc://irc.freenode.org/phpmd", + "issues": "https://github.com/phpmd/phpmd/issues", + "source": "https://github.com/phpmd/phpmd/tree/2.15.0" }, - "time": "2025-02-13T12:25:43+00:00" + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/phpmd/phpmd", + "type": "tidelift" + } + ], + "time": "2023-12-11T08:22:20+00:00" }, { - "name": "phpunit/php-code-coverage", - "version": "11.0.8", + "name": "phpmyadmin/sql-parser", + "version": "5.10.3", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "418c59fd080954f8c4aa5631d9502ecda2387118" + "url": "https://github.com/phpmyadmin/sql-parser.git", + "reference": "5346664973d10cf1abff20837fb1183f3c11a055" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/418c59fd080954f8c4aa5631d9502ecda2387118", - "reference": "418c59fd080954f8c4aa5631d9502ecda2387118", + "url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/5346664973d10cf1abff20837fb1183f3c11a055", + "reference": "5346664973d10cf1abff20837fb1183f3c11a055", "shasum": "" }, "require": { - "ext-dom": "*", - "ext-libxml": "*", - "ext-xmlwriter": "*", - "nikic/php-parser": "^5.3.1", - "php": ">=8.2", - "phpunit/php-file-iterator": "^5.1.0", + "php": "^7.2 || ^8.0", + "symfony/polyfill-mbstring": "^1.3", + "symfony/polyfill-php80": "^1.16" + }, + "conflict": { + "phpmyadmin/motranslator": "<3.0" + }, + "require-dev": { + "phpbench/phpbench": "^1.1", + "phpmyadmin/coding-standard": "^3.0", + "phpmyadmin/motranslator": "^4.0 || ^5.0", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.9.12", + "phpstan/phpstan-phpunit": "^1.3.3", + "phpunit/phpunit": "^8.5 || ^9.6", + "psalm/plugin-phpunit": "^0.16.1", + "vimeo/psalm": "^4.11", + "zumba/json-serializer": "~3.0.2" + }, + "suggest": { + "ext-mbstring": "For best performance", + "phpmyadmin/motranslator": "Translate messages to your favorite locale" + }, + "bin": [ + "bin/highlight-query", + "bin/lint-query", + "bin/sql-parser", + "bin/tokenize-query" + ], + "type": "library", + "autoload": { + "psr-4": { + "PhpMyAdmin\\SqlParser\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "The phpMyAdmin Team", + "email": "developers@phpmyadmin.net", + "homepage": "https://www.phpmyadmin.net/team/" + } + ], + "description": "A validating SQL lexer and parser with a focus on MySQL dialect.", + "homepage": "https://github.com/phpmyadmin/sql-parser", + "keywords": [ + "analysis", + "lexer", + "parser", + "query linter", + "sql", + "sql lexer", + "sql linter", + "sql parser", + "sql syntax highlighter", + "sql tokenizer" + ], + "support": { + "issues": "https://github.com/phpmyadmin/sql-parser/issues", + "source": "https://github.com/phpmyadmin/sql-parser" + }, + "funding": [ + { + "url": "https://www.phpmyadmin.net/donate/", + "type": "other" + } + ], + "time": "2025-01-19T04:14:02+00:00" + }, + { + "name": "phpstan/phpdoc-parser", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "72e51f7c32c5aef7c8b462195b8c599b11199893" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/72e51f7c32c5aef7c8b462195b8c599b11199893", + "reference": "72e51f7c32c5aef7c8b462195b8c599b11199893", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^5.3.0", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpunit/phpunit": "^9.6", + "symfony/process": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/2.0.1" + }, + "time": "2025-02-13T12:25:43+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "2.1.5", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "451b17f9665481ee502adc39be987cb71067ece2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/451b17f9665481ee502adc39be987cb71067ece2", + "reference": "451b17f9665481ee502adc39be987cb71067ece2", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2025-02-13T12:49:56+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "11.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "418c59fd080954f8c4aa5631d9502ecda2387118" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/418c59fd080954f8c4aa5631d9502ecda2387118", + "reference": "418c59fd080954f8c4aa5631d9502ecda2387118", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "nikic/php-parser": "^5.3.1", + "php": ">=8.2", + "phpunit/php-file-iterator": "^5.1.0", "phpunit/php-text-template": "^4.0.1", "sebastian/code-unit-reverse-lookup": "^4.0.1", "sebastian/complexity": "^4.0.1", @@ -9039,6 +9569,303 @@ ], "time": "2024-10-20T05:08:20+00:00" }, + { + "name": "symfony/config", + "version": "v7.2.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/config.git", + "reference": "7716594aaae91d9141be080240172a92ecca4d44" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/config/zipball/7716594aaae91d9141be080240172a92ecca4d44", + "reference": "7716594aaae91d9141be080240172a92ecca4d44", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/filesystem": "^7.1", + "symfony/polyfill-ctype": "~1.8" + }, + "conflict": { + "symfony/finder": "<6.4", + "symfony/service-contracts": "<2.5" + }, + "require-dev": { + "symfony/event-dispatcher": "^6.4|^7.0", + "symfony/finder": "^6.4|^7.0", + "symfony/messenger": "^6.4|^7.0", + "symfony/service-contracts": "^2.5|^3", + "symfony/yaml": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Config\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Helps you find, load, combine, autofill and validate configuration values of any kind", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/config/tree/v7.2.3" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2025-01-22T12:07:01+00:00" + }, + { + "name": "symfony/dependency-injection", + "version": "v7.2.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/dependency-injection.git", + "reference": "1d321c4bc3fe926fd4c38999a4c9af4f5d61ddfc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/1d321c4bc3fe926fd4c38999a4c9af4f5d61ddfc", + "reference": "1d321c4bc3fe926fd4c38999a4c9af4f5d61ddfc", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "psr/container": "^1.1|^2.0", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/service-contracts": "^3.5", + "symfony/var-exporter": "^6.4|^7.0" + }, + "conflict": { + "ext-psr": "<1.1|>=2", + "symfony/config": "<6.4", + "symfony/finder": "<6.4", + "symfony/yaml": "<6.4" + }, + "provide": { + "psr/container-implementation": "1.1|2.0", + "symfony/service-implementation": "1.1|2.0|3.0" + }, + "require-dev": { + "symfony/config": "^6.4|^7.0", + "symfony/expression-language": "^6.4|^7.0", + "symfony/yaml": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\DependencyInjection\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Allows you to standardize and centralize the way objects are constructed in your application", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/dependency-injection/tree/v7.2.3" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2025-01-17T10:56:55+00:00" + }, + { + "name": "symfony/filesystem", + "version": "v7.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "b8dce482de9d7c9fe2891155035a7248ab5c7fdb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/b8dce482de9d7c9fe2891155035a7248ab5c7fdb", + "reference": "b8dce482de9d7c9fe2891155035a7248ab5c7fdb", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.8" + }, + "require-dev": { + "symfony/process": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides basic utilities for the filesystem", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/filesystem/tree/v7.2.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-10-25T15:15:23+00:00" + }, + { + "name": "symfony/var-exporter", + "version": "v7.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/var-exporter.git", + "reference": "1a6a89f95a46af0f142874c9d650a6358d13070d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/var-exporter/zipball/1a6a89f95a46af0f142874c9d650a6358d13070d", + "reference": "1a6a89f95a46af0f142874c9d650a6358d13070d", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "symfony/property-access": "^6.4|^7.0", + "symfony/serializer": "^6.4|^7.0", + "symfony/var-dumper": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\VarExporter\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Allows exporting any serializable PHP data structure to plain PHP code", + "homepage": "https://symfony.com", + "keywords": [ + "clone", + "construct", + "export", + "hydrate", + "instantiate", + "lazy-loading", + "proxy", + "serialize" + ], + "support": { + "source": "https://github.com/symfony/var-exporter/tree/v7.2.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-10-18T07:58:17+00:00" + }, { "name": "symfony/yaml", "version": "v7.2.3", From d1fdee8cd8a85d35b04deaee6728caac70337da9 Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Fri, 21 Feb 2025 12:21:21 +0530 Subject: [PATCH 04/11] Refactor CI workflow to remove unnecessary Node dependencies --- .github/workflows/ci.yml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c10d5ce..92ed29c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,9 +36,6 @@ jobs: - name: Install Composer Dependencies run: composer install --no-progress --prefer-dist --optimize-autoloader - - name: Install Node Dependencies - run: npm install - - name: Setup Laravel Environment run: | cp .env.example .env @@ -60,13 +57,3 @@ jobs: # Static analysis using Larastan - name: Run Larastan run: ./vendor/bin/phpstan analyse --memory-limit=1G - - # Run Laravel tests - - name: Run Laravel Tests - env: - DB_CONNECTION: mysql - DB_DATABASE: testing_db - DB_USERNAME: user - DB_PASSWORD: password - DB_HOST: 127.0.0.1 - run: php artisan test --parallel From 79b1e3fa9b7d0bc02fa0d16979a649e0fc384c81 Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Fri, 21 Feb 2025 13:01:20 +0530 Subject: [PATCH 05/11] fix larastan + phpmd erros --- .github/workflows/ci.yml | 2 +- .../Auth/AuthenticatedSessionController.php | 14 ++++-- .../Auth/NewPasswordController.php | 42 +++++++++++------- .../Auth/PasswordResetLinkController.php | 23 +++++----- .../Auth/RegisteredUserController.php | 36 +++++++++++---- app/Http/Requests/Auth/LoginRequest.php | 44 +++++++++++++------ app/Providers/AppServiceProvider.php | 18 ++++---- bootstrap/app.php | 20 ++++----- composer.json | 2 +- composer.lock | 2 +- routes/console.php | 8 ---- 11 files changed, 128 insertions(+), 83 deletions(-) delete mode 100644 routes/console.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92ed29c..c59592a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,4 +56,4 @@ jobs: # Static analysis using Larastan - name: Run Larastan - run: ./vendor/bin/phpstan analyse --memory-limit=1G + run: ./vendor/bin/phpstan analyse app routes --memory-limit=2G diff --git a/app/Http/Controllers/Auth/AuthenticatedSessionController.php b/app/Http/Controllers/Auth/AuthenticatedSessionController.php index 265b618..66c11f8 100644 --- a/app/Http/Controllers/Auth/AuthenticatedSessionController.php +++ b/app/Http/Controllers/Auth/AuthenticatedSessionController.php @@ -5,13 +5,19 @@ use App\Http\Controllers\Controller; use App\Http\Requests\Auth\LoginRequest; use App\Models\User; +use Illuminate\Contracts\Auth\StatefulGuard; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Http\Response; -use Illuminate\Support\Facades\Auth; class AuthenticatedSessionController extends Controller { + protected StatefulGuard $auth; + + public function __construct(StatefulGuard $auth) + { + $this->auth = $auth; + } + /** * Handle an incoming authentication request. */ @@ -24,7 +30,7 @@ public function store(LoginRequest $request): JsonResponse $user = User::where('email', $request->email)->first(); - if (!Auth::attempt($validatedData)) { + if (!$this->auth->attempt($validatedData)) { return response()->json([ 'success' => false, 'message' => 'Login failed. Please check your credentials.' @@ -45,7 +51,7 @@ public function store(LoginRequest $request): JsonResponse */ public function destroy(Request $request): JsonResponse { - Auth::guard('web')->logout(); + $this->auth->logout(); $request->session()->invalidate(); diff --git a/app/Http/Controllers/Auth/NewPasswordController.php b/app/Http/Controllers/Auth/NewPasswordController.php index 4277c32..46f0741 100644 --- a/app/Http/Controllers/Auth/NewPasswordController.php +++ b/app/Http/Controllers/Auth/NewPasswordController.php @@ -4,16 +4,27 @@ use App\Http\Controllers\Controller; use Illuminate\Auth\Events\PasswordReset; +use Illuminate\Contracts\Auth\PasswordBroker; +use Illuminate\Contracts\Hashing\Hasher; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Hash; -use Illuminate\Support\Facades\Password; use Illuminate\Support\Str; -use Illuminate\Validation\Rules; -use Illuminate\Validation\ValidationException; +use Illuminate\Validation\Rules\Password; +use Illuminate\Validation\ValidationException as ValidationEx; class NewPasswordController extends Controller { + protected PasswordBroker $passwordBroker; + protected Hasher $hasher; + protected Str $strHelper; + + public function __construct(PasswordBroker $passwordBroker, Hasher $hasher, Str $strHelper) + { + $this->passwordBroker = $passwordBroker; + $this->hasher = $hasher; + $this->strHelper = $strHelper; + } + /** * Handle an incoming new password request. * @@ -24,28 +35,29 @@ public function store(Request $request): JsonResponse $request->validate([ 'token' => ['required'], 'email' => ['required', 'email'], - 'password' => ['required', 'confirmed', Rules\Password::defaults()], + 'password' => ['required', 'confirmed', Password::min(8) + ->letters() + ->mixedCase() + ->numbers() + ->symbols() + ->uncompromised()], ]); - // Here we will attempt to reset the user's password. If it is successful we - // will update the password on an actual user model and persist it to the - // database. Otherwise we will parse the error and return the response. - $status = Password::reset( + // Attempt to reset the user's password + $status = $this->passwordBroker->reset( $request->only('email', 'password', 'password_confirmation', 'token'), function ($user) use ($request) { $user->forceFill([ - 'password' => Hash::make($request->string('password')), - 'remember_token' => Str::random(60), + 'password' => $this->hasher->make($request->string('password')), + 'remember_token' => $this->strHelper->random(60), ])->save(); event(new PasswordReset($user)); } ); - if ($status != Password::PASSWORD_RESET) { - throw ValidationException::withMessages([ - 'email' => [__($status)], - ]); + if ($status != PasswordBroker::PASSWORD_RESET) { + throw new ValidationEx(__('email'), [__($status)]); } return response()->json(['status' => __($status)]); diff --git a/app/Http/Controllers/Auth/PasswordResetLinkController.php b/app/Http/Controllers/Auth/PasswordResetLinkController.php index 95cde8e..5445eee 100644 --- a/app/Http/Controllers/Auth/PasswordResetLinkController.php +++ b/app/Http/Controllers/Auth/PasswordResetLinkController.php @@ -3,13 +3,20 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; +use Illuminate\Contracts\Auth\PasswordBroker; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Password; -use Illuminate\Validation\ValidationException; +use Illuminate\Validation\ValidationException as ValidationEx; class PasswordResetLinkController extends Controller { + protected PasswordBroker $passwordBroker; + + public function __construct(PasswordBroker $passwordBroker) + { + $this->passwordBroker = $passwordBroker; + } + /** * Handle an incoming password reset link request. * @@ -21,17 +28,13 @@ public function store(Request $request): JsonResponse 'email' => ['required', 'email'], ]); - // We will send the password reset link to this user. Once we have attempted - // to send the link, we will examine the response then see the message we - // need to show to the user. Finally, we'll send out a proper response. - $status = Password::sendResetLink( + // Use the injected PasswordBroker instead of static access + $status = $this->passwordBroker->sendResetLink( $request->only('email') ); - if ($status != Password::RESET_LINK_SENT) { - throw ValidationException::withMessages([ - 'email' => [__($status)], - ]); + if ($status != PasswordBroker::RESET_LINK_SENT) { + throw new ValidationEx(__('email'), [__($status)]); } return response()->json(['status' => __($status)]); diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index 9690a3a..c3b29c0 100644 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -5,14 +5,25 @@ use App\Http\Controllers\Controller; use App\Models\User; use Illuminate\Auth\Events\Registered; -use Illuminate\Http\Request; +use Illuminate\Contracts\Auth\StatefulGuard; +use Illuminate\Contracts\Hashing\Hasher; use Illuminate\Http\JsonResponse; -use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\Hash; -use Illuminate\Validation\Rules; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Password; class RegisteredUserController extends Controller { + protected User $user; + protected Hasher $hasher; + protected StatefulGuard $auth; + + public function __construct(User $user, Hasher $hasher, StatefulGuard $auth) + { + $this->user = $user; + $this->hasher = $hasher; + $this->auth = $auth; + } + /** * Handle an incoming registration request. * @@ -20,21 +31,28 @@ class RegisteredUserController extends Controller */ public function store(Request $request): JsonResponse { + $passwordDefaults = Password::min(8) + ->letters() + ->mixedCase() + ->numbers() + ->symbols() + ->uncompromised(); + $request->validate([ 'name' => ['required', 'string', 'max:255'], - 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . User::class], - 'password' => ['required', 'confirmed', Rules\Password::defaults()], + 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . $this->user->getTable()], + 'password' => ['required', 'confirmed', $passwordDefaults], ]); - $user = User::create([ + $user = $this->user->create([ 'name' => $request->name, 'email' => $request->email, - 'password' => Hash::make($request->string('password')), + 'password' => $this->hasher->make($request->string('password')), ]); event(new Registered($user)); - Auth::login($user); + $this->auth->login($user); return response()->json([ 'message' => 'User registered successfully', diff --git a/app/Http/Requests/Auth/LoginRequest.php b/app/Http/Requests/Auth/LoginRequest.php index f5692bf..54b08a4 100644 --- a/app/Http/Requests/Auth/LoginRequest.php +++ b/app/Http/Requests/Auth/LoginRequest.php @@ -4,13 +4,31 @@ use Illuminate\Auth\Events\Lockout; use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\RateLimiter; -use Illuminate\Support\Str; +use Illuminate\Contracts\Auth\StatefulGuard; +use Illuminate\Cache\RateLimiter as RateLimiterContract; +use Illuminate\Contracts\Translation\Translator; use Illuminate\Validation\ValidationException; +use Illuminate\Support\Str; class LoginRequest extends FormRequest { + protected $auth; + protected $rateLimiter; + protected $translator; + protected $stringHelper; + + /** + * Constructor to inject dependencies. + */ + public function __construct(StatefulGuard $auth, RateLimiterContract $rateLimiter, Translator $translator, Str $stringHelper) + { + parent::__construct(); + $this->auth = $auth; + $this->rateLimiter = $rateLimiter; + $this->translator = $translator; + $this->stringHelper = $stringHelper; + } + /** * Determine if the user is authorized to make this request. */ @@ -41,15 +59,15 @@ public function authenticate(): void { $this->ensureIsNotRateLimited(); - if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) { - RateLimiter::hit($this->throttleKey()); + if (!$this->auth->attempt($this->only('email', 'password'), $this->boolean('remember'))) { + $this->rateLimiter->hit($this->throttleKey()); - throw ValidationException::withMessages([ - 'email' => __('auth.failed'), + throw new ValidationException($this->getMessageBag(), [ + 'email' => $this->translator->get('auth.failed'), ]); } - RateLimiter::clear($this->throttleKey()); + $this->rateLimiter->clear($this->throttleKey()); } /** @@ -59,16 +77,16 @@ public function authenticate(): void */ public function ensureIsNotRateLimited(): void { - if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { + if (!$this->rateLimiter->tooManyAttempts($this->throttleKey(), 5)) { return; } event(new Lockout($this)); - $seconds = RateLimiter::availableIn($this->throttleKey()); + $seconds = $this->rateLimiter->availableIn($this->throttleKey()); - throw ValidationException::withMessages([ - 'email' => trans('auth.throttle', [ + throw new ValidationException($this->getMessageBag(), [ + 'email' => $this->translator->get('auth.throttle', [ 'seconds' => $seconds, 'minutes' => ceil($seconds / 60), ]), @@ -80,6 +98,6 @@ public function ensureIsNotRateLimited(): void */ public function throttleKey(): string { - return Str::transliterate(Str::lower($this->input('email')).'|'.$this->ip()); + return $this->stringHelper->transliterate($this->stringHelper->lower($this->input('email')) . '|' . $this->ip()); } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6051392..dc8671f 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,10 +2,9 @@ namespace App\Providers; - use Illuminate\Auth\Notifications\ResetPassword; +use Illuminate\Contracts\Auth\Access\Gate as GateContract; use Illuminate\Support\ServiceProvider; -use Illuminate\Support\Facades\Gate; class AppServiceProvider extends ServiceProvider { @@ -20,17 +19,16 @@ public function register(): void /** * Bootstrap any application services. */ - public function boot(): void + public function boot(ResetPassword $resetPassword, GateContract $gate): void { - ResetPassword::createUrlUsing(function (object $notifiable, string $token) { - return config('app.frontend_url')."/password-reset/$token?email={$notifiable->getEmailForPasswordReset()}"; + // Using the injected ResetPassword instance + $resetPassword::createUrlUsing(function (object $notifiable, string $token) { + return config('app.frontend_url') . "/password-reset/$token?email={$notifiable->getEmailForPasswordReset()}"; }); - Gate::after(function ($user, $ability) { - if($user->hasRole('admin')){ - return true; - } - return false; + // Using the injected GateContract instance + $gate->after(function ($user) { + return $user->hasRole('admin') ? true : null; }); } } diff --git a/bootstrap/app.php b/bootstrap/app.php index 4201e16..853622e 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -18,9 +18,8 @@ return Application::configure(basePath: dirname(__DIR__)) ->withRouting( - web: __DIR__.'/../routes/web.php', - api: __DIR__.'/../routes/api.php', - commands: __DIR__.'/../routes/console.php', + web: __DIR__ . '/../routes/web.php', + api: __DIR__ . '/../routes/api.php', health: '/up', ) ->withMiddleware(function (Middleware $middleware) { @@ -40,50 +39,49 @@ ]); }) ->withExceptions(function (Exceptions $exceptions) { - $exceptions->render(function(ModelNotFoundException $e) { + $exceptions->render(function (ModelNotFoundException $e) { return response()->json([ 'success' => false, 'message' => 'Resource not found' ], 404); }); - $exceptions->render(function(NotFoundHttpException $e) { + $exceptions->render(function (NotFoundHttpException $e) { return response()->json([ 'success' => false, 'message' => 'Resource not found' ], 404); }); - $exceptions->render(function(AuthorizationException $e) { + $exceptions->render(function (AuthorizationException $e) { return response()->json([ 'success' => false, 'message' => 'You are not authorized to perform this action' ], 403); }); - $exceptions->render(function(ValidationException $e) { + $exceptions->render(function (ValidationException $e) { return response()->json([ 'success' => false, 'message' => 'Validation failed', 'errors' => $e->errors() ], 422); }); - $exceptions->render(function(MethodNotAllowedHttpException $e) { + $exceptions->render(function (MethodNotAllowedHttpException $e) { return response()->json([ 'success' => false, 'message' => 'Method is not allowed for the requested route' ], 405); }); - $exceptions->render(function(AccessDeniedHttpException $e) { + $exceptions->render(function (AccessDeniedHttpException $e) { return response()->json([ 'success' => false, 'message' => 'You are not authorized to perform this action' ], 403); }); - $exceptions->render(function(\Throwable $e) { + $exceptions->render(function (\Throwable $e) { return response()->json([ 'success' => false, 'message' => 'An error occurred', 'error' => $e->getMessage() ], 500); }); - })->create(); diff --git a/composer.json b/composer.json index 8c1a0c8..19e13c2 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "laravel/sail": "^1.26", "mockery/mockery": "^1.6", "nunomaduro/collision": "^8.1", - "nunomaduro/larastan": "^3.0", + "nunomaduro/larastan": "^3.1", "pestphp/pest": "^3.7", "pestphp/pest-plugin-laravel": "^3.1", "phpmd/phpmd": "^2.15" diff --git a/composer.lock b/composer.lock index a7521e9..9b8bff2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "28399c373e33c98f230439dbed86d7ad", + "content-hash": "f45493c028af791e9edaace1456b4f33", "packages": [ { "name": "brick/math", diff --git a/routes/console.php b/routes/console.php deleted file mode 100644 index 3c9adf1..0000000 --- a/routes/console.php +++ /dev/null @@ -1,8 +0,0 @@ -comment(Inspiring::quote()); -})->purpose('Display an inspiring quote'); From c9c8bab1d3940fa6b87922ed77706edbf475aa68 Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Fri, 21 Feb 2025 13:18:11 +0530 Subject: [PATCH 06/11] remove unused code --- app/Providers/AppServiceProvider.php | 10 +- composer.lock | 253 +++++++++++++-------------- 2 files changed, 128 insertions(+), 135 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index dc8671f..457cb42 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,7 +2,6 @@ namespace App\Providers; -use Illuminate\Auth\Notifications\ResetPassword; use Illuminate\Contracts\Auth\Access\Gate as GateContract; use Illuminate\Support\ServiceProvider; @@ -19,14 +18,9 @@ public function register(): void /** * Bootstrap any application services. */ - public function boot(ResetPassword $resetPassword, GateContract $gate): void + public function boot(GateContract $gate): void { - // Using the injected ResetPassword instance - $resetPassword::createUrlUsing(function (object $notifiable, string $token) { - return config('app.frontend_url') . "/password-reset/$token?email={$notifiable->getEmailForPasswordReset()}"; - }); - - // Using the injected GateContract instance + // Use the injected GateContract instance $gate->after(function ($user) { return $user->hasRole('admin') ? true : null; }); diff --git a/composer.lock b/composer.lock index 9b8bff2..a1604a0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f45493c028af791e9edaace1456b4f33", + "content-hash": "5c0a9cea6fd5479dcf1d99142d250bad", "packages": [ { "name": "brick/math", @@ -1056,16 +1056,16 @@ }, { "name": "laravel/framework", - "version": "v11.42.1", + "version": "v11.43.2", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "ff392f42f6c55cc774ce75553a11c6b031da67f8" + "reference": "99d1573698abc42222f04d25fcd5b213d0eedf21" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/ff392f42f6c55cc774ce75553a11c6b031da67f8", - "reference": "ff392f42f6c55cc774ce75553a11c6b031da67f8", + "url": "https://api.github.com/repos/laravel/framework/zipball/99d1573698abc42222f04d25fcd5b213d0eedf21", + "reference": "99d1573698abc42222f04d25fcd5b213d0eedf21", "shasum": "" }, "require": { @@ -1267,7 +1267,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2025-02-12T20:58:18+00:00" + "time": "2025-02-19T21:53:48+00:00" }, { "name": "laravel/prompts", @@ -2175,16 +2175,16 @@ }, { "name": "nesbot/carbon", - "version": "3.8.5", + "version": "3.8.6", "source": { "type": "git", "url": "https://github.com/CarbonPHP/carbon.git", - "reference": "b1a53a27898639579a67de42e8ced5d5386aa9a4" + "reference": "ff2f20cf83bd4d503720632ce8a426dc747bf7fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/CarbonPHP/carbon/zipball/b1a53a27898639579a67de42e8ced5d5386aa9a4", - "reference": "b1a53a27898639579a67de42e8ced5d5386aa9a4", + "url": "https://api.github.com/repos/CarbonPHP/carbon/zipball/ff2f20cf83bd4d503720632ce8a426dc747bf7fd", + "reference": "ff2f20cf83bd4d503720632ce8a426dc747bf7fd", "shasum": "" }, "require": { @@ -2277,7 +2277,7 @@ "type": "tidelift" } ], - "time": "2025-02-11T16:28:45+00:00" + "time": "2025-02-20T17:33:38+00:00" }, { "name": "nette/schema", @@ -6535,6 +6535,99 @@ }, "time": "2024-11-18T16:19:46+00:00" }, + { + "name": "larastan/larastan", + "version": "v3.1.0", + "source": { + "type": "git", + "url": "https://github.com/larastan/larastan.git", + "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/larastan/larastan/zipball/dbb2dc20e5c8e1ed3ff289054e1955f269187312", + "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312", + "shasum": "" + }, + "require": { + "ext-json": "*", + "illuminate/console": "^11.15.0 || ^12.0", + "illuminate/container": "^11.15.0 || ^12.0", + "illuminate/contracts": "^11.15.0 || ^12.0", + "illuminate/database": "^11.15.0 || ^12.0", + "illuminate/http": "^11.15.0 || ^12.0", + "illuminate/pipeline": "^11.15.0 || ^12.0", + "illuminate/support": "^11.15.0 || ^12.0", + "php": "^8.2", + "phpmyadmin/sql-parser": "^5.9.0", + "phpstan/phpstan": "^2.1.3" + }, + "require-dev": { + "doctrine/coding-standard": "^12.0", + "laravel/framework": "^11.15.0 || ^12.0", + "mockery/mockery": "^1.6", + "nikic/php-parser": "^5.3", + "orchestra/canvas": "^v9.1.3 || ^10.0", + "orchestra/testbench-core": "^9.5.2 || ^10.0", + "phpstan/phpstan-deprecation-rules": "^2.0.0", + "phpunit/phpunit": "^10.5.35 || ^11.3.6" + }, + "suggest": { + "orchestra/testbench": "Using Larastan for analysing a package needs Testbench" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon" + ] + }, + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Larastan\\Larastan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Can Vural", + "email": "can9119@gmail.com" + }, + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "larastan", + "laravel", + "package", + "php", + "static analysis" + ], + "support": { + "issues": "https://github.com/larastan/larastan/issues", + "source": "https://github.com/larastan/larastan/tree/v3.1.0" + }, + "funding": [ + { + "url": "https://github.com/canvural", + "type": "github" + } + ], + "time": "2025-02-20T15:25:15+00:00" + }, { "name": "laravel/breeze", "version": "v2.3.4", @@ -6676,16 +6769,16 @@ }, { "name": "laravel/pint", - "version": "v1.20.0", + "version": "v1.21.0", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "53072e8ea22213a7ed168a8a15b96fbb8b82d44b" + "reference": "531fa0871fbde719c51b12afa3a443b8f4e4b425" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/53072e8ea22213a7ed168a8a15b96fbb8b82d44b", - "reference": "53072e8ea22213a7ed168a8a15b96fbb8b82d44b", + "url": "https://api.github.com/repos/laravel/pint/zipball/531fa0871fbde719c51b12afa3a443b8f4e4b425", + "reference": "531fa0871fbde719c51b12afa3a443b8f4e4b425", "shasum": "" }, "require": { @@ -6693,15 +6786,15 @@ "ext-mbstring": "*", "ext-tokenizer": "*", "ext-xml": "*", - "php": "^8.1.0" + "php": "^8.2.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.66.0", - "illuminate/view": "^10.48.25", - "larastan/larastan": "^2.9.12", - "laravel-zero/framework": "^10.48.25", + "friendsofphp/php-cs-fixer": "^3.68.5", + "illuminate/view": "^11.42.0", + "larastan/larastan": "^3.0.4", + "laravel-zero/framework": "^11.36.1", "mockery/mockery": "^1.6.12", - "nunomaduro/termwind": "^1.17.0", + "nunomaduro/termwind": "^2.3", "pestphp/pest": "^2.36.0" }, "bin": [ @@ -6738,7 +6831,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2025-01-14T16:20:53+00:00" + "time": "2025-02-18T03:18:57+00:00" }, { "name": "laravel/sail", @@ -7044,100 +7137,6 @@ ], "time": "2025-01-23T13:41:43+00:00" }, - { - "name": "nunomaduro/larastan", - "version": "v3.1.0", - "source": { - "type": "git", - "url": "https://github.com/larastan/larastan.git", - "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/larastan/larastan/zipball/dbb2dc20e5c8e1ed3ff289054e1955f269187312", - "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312", - "shasum": "" - }, - "require": { - "ext-json": "*", - "illuminate/console": "^11.15.0 || ^12.0", - "illuminate/container": "^11.15.0 || ^12.0", - "illuminate/contracts": "^11.15.0 || ^12.0", - "illuminate/database": "^11.15.0 || ^12.0", - "illuminate/http": "^11.15.0 || ^12.0", - "illuminate/pipeline": "^11.15.0 || ^12.0", - "illuminate/support": "^11.15.0 || ^12.0", - "php": "^8.2", - "phpmyadmin/sql-parser": "^5.9.0", - "phpstan/phpstan": "^2.1.3" - }, - "require-dev": { - "doctrine/coding-standard": "^12.0", - "laravel/framework": "^11.15.0 || ^12.0", - "mockery/mockery": "^1.6", - "nikic/php-parser": "^5.3", - "orchestra/canvas": "^v9.1.3 || ^10.0", - "orchestra/testbench-core": "^9.5.2 || ^10.0", - "phpstan/phpstan-deprecation-rules": "^2.0.0", - "phpunit/phpunit": "^10.5.35 || ^11.3.6" - }, - "suggest": { - "orchestra/testbench": "Using Larastan for analysing a package needs Testbench" - }, - "type": "phpstan-extension", - "extra": { - "phpstan": { - "includes": [ - "extension.neon" - ] - }, - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "Larastan\\Larastan\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Can Vural", - "email": "can9119@gmail.com" - }, - { - "name": "Nuno Maduro", - "email": "enunomaduro@gmail.com" - } - ], - "description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel", - "keywords": [ - "PHPStan", - "code analyse", - "code analysis", - "larastan", - "laravel", - "package", - "php", - "static analysis" - ], - "support": { - "issues": "https://github.com/larastan/larastan/issues", - "source": "https://github.com/larastan/larastan/tree/v3.1.0" - }, - "funding": [ - { - "url": "https://github.com/canvural", - "type": "github" - } - ], - "abandoned": "larastan/larastan", - "time": "2025-02-20T15:25:15+00:00" - }, { "name": "pdepend/pdepend", "version": "2.16.2", @@ -8064,16 +8063,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "2.0.1", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "72e51f7c32c5aef7c8b462195b8c599b11199893" + "reference": "9b30d6fd026b2c132b3985ce6b23bec09ab3aa68" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/72e51f7c32c5aef7c8b462195b8c599b11199893", - "reference": "72e51f7c32c5aef7c8b462195b8c599b11199893", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/9b30d6fd026b2c132b3985ce6b23bec09ab3aa68", + "reference": "9b30d6fd026b2c132b3985ce6b23bec09ab3aa68", "shasum": "" }, "require": { @@ -8105,22 +8104,22 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/2.0.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/2.1.0" }, - "time": "2025-02-13T12:25:43+00:00" + "time": "2025-02-19T13:28:12+00:00" }, { "name": "phpstan/phpstan", - "version": "2.1.5", + "version": "2.1.6", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "451b17f9665481ee502adc39be987cb71067ece2" + "reference": "6eaec7c6c9e90dcfe46ad1e1ffa5171e2dab641c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/451b17f9665481ee502adc39be987cb71067ece2", - "reference": "451b17f9665481ee502adc39be987cb71067ece2", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/6eaec7c6c9e90dcfe46ad1e1ffa5171e2dab641c", + "reference": "6eaec7c6c9e90dcfe46ad1e1ffa5171e2dab641c", "shasum": "" }, "require": { @@ -8165,7 +8164,7 @@ "type": "github" } ], - "time": "2025-02-13T12:49:56+00:00" + "time": "2025-02-19T15:46:42+00:00" }, { "name": "phpunit/php-code-coverage", From 912467306a69bf0501cc5442a1e3545a58170af7 Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Fri, 21 Feb 2025 13:21:18 +0530 Subject: [PATCH 07/11] Update composer.lock --- composer.lock | 189 +++++++++++++++++++++++++------------------------- 1 file changed, 95 insertions(+), 94 deletions(-) diff --git a/composer.lock b/composer.lock index a1604a0..8409abf 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5c0a9cea6fd5479dcf1d99142d250bad", + "content-hash": "f45493c028af791e9edaace1456b4f33", "packages": [ { "name": "brick/math", @@ -6535,99 +6535,6 @@ }, "time": "2024-11-18T16:19:46+00:00" }, - { - "name": "larastan/larastan", - "version": "v3.1.0", - "source": { - "type": "git", - "url": "https://github.com/larastan/larastan.git", - "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/larastan/larastan/zipball/dbb2dc20e5c8e1ed3ff289054e1955f269187312", - "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312", - "shasum": "" - }, - "require": { - "ext-json": "*", - "illuminate/console": "^11.15.0 || ^12.0", - "illuminate/container": "^11.15.0 || ^12.0", - "illuminate/contracts": "^11.15.0 || ^12.0", - "illuminate/database": "^11.15.0 || ^12.0", - "illuminate/http": "^11.15.0 || ^12.0", - "illuminate/pipeline": "^11.15.0 || ^12.0", - "illuminate/support": "^11.15.0 || ^12.0", - "php": "^8.2", - "phpmyadmin/sql-parser": "^5.9.0", - "phpstan/phpstan": "^2.1.3" - }, - "require-dev": { - "doctrine/coding-standard": "^12.0", - "laravel/framework": "^11.15.0 || ^12.0", - "mockery/mockery": "^1.6", - "nikic/php-parser": "^5.3", - "orchestra/canvas": "^v9.1.3 || ^10.0", - "orchestra/testbench-core": "^9.5.2 || ^10.0", - "phpstan/phpstan-deprecation-rules": "^2.0.0", - "phpunit/phpunit": "^10.5.35 || ^11.3.6" - }, - "suggest": { - "orchestra/testbench": "Using Larastan for analysing a package needs Testbench" - }, - "type": "phpstan-extension", - "extra": { - "phpstan": { - "includes": [ - "extension.neon" - ] - }, - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "Larastan\\Larastan\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Can Vural", - "email": "can9119@gmail.com" - }, - { - "name": "Nuno Maduro", - "email": "enunomaduro@gmail.com" - } - ], - "description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel", - "keywords": [ - "PHPStan", - "code analyse", - "code analysis", - "larastan", - "laravel", - "package", - "php", - "static analysis" - ], - "support": { - "issues": "https://github.com/larastan/larastan/issues", - "source": "https://github.com/larastan/larastan/tree/v3.1.0" - }, - "funding": [ - { - "url": "https://github.com/canvural", - "type": "github" - } - ], - "time": "2025-02-20T15:25:15+00:00" - }, { "name": "laravel/breeze", "version": "v2.3.4", @@ -7137,6 +7044,100 @@ ], "time": "2025-01-23T13:41:43+00:00" }, + { + "name": "nunomaduro/larastan", + "version": "v3.1.0", + "source": { + "type": "git", + "url": "https://github.com/larastan/larastan.git", + "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/larastan/larastan/zipball/dbb2dc20e5c8e1ed3ff289054e1955f269187312", + "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312", + "shasum": "" + }, + "require": { + "ext-json": "*", + "illuminate/console": "^11.15.0 || ^12.0", + "illuminate/container": "^11.15.0 || ^12.0", + "illuminate/contracts": "^11.15.0 || ^12.0", + "illuminate/database": "^11.15.0 || ^12.0", + "illuminate/http": "^11.15.0 || ^12.0", + "illuminate/pipeline": "^11.15.0 || ^12.0", + "illuminate/support": "^11.15.0 || ^12.0", + "php": "^8.2", + "phpmyadmin/sql-parser": "^5.9.0", + "phpstan/phpstan": "^2.1.3" + }, + "require-dev": { + "doctrine/coding-standard": "^12.0", + "laravel/framework": "^11.15.0 || ^12.0", + "mockery/mockery": "^1.6", + "nikic/php-parser": "^5.3", + "orchestra/canvas": "^v9.1.3 || ^10.0", + "orchestra/testbench-core": "^9.5.2 || ^10.0", + "phpstan/phpstan-deprecation-rules": "^2.0.0", + "phpunit/phpunit": "^10.5.35 || ^11.3.6" + }, + "suggest": { + "orchestra/testbench": "Using Larastan for analysing a package needs Testbench" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon" + ] + }, + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Larastan\\Larastan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Can Vural", + "email": "can9119@gmail.com" + }, + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "larastan", + "laravel", + "package", + "php", + "static analysis" + ], + "support": { + "issues": "https://github.com/larastan/larastan/issues", + "source": "https://github.com/larastan/larastan/tree/v3.1.0" + }, + "funding": [ + { + "url": "https://github.com/canvural", + "type": "github" + } + ], + "abandoned": "larastan/larastan", + "time": "2025-02-20T15:25:15+00:00" + }, { "name": "pdepend/pdepend", "version": "2.16.2", From 27e2b8d5463302f0b94fdced74337f0d145a67ba Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Fri, 21 Feb 2025 13:44:33 +0530 Subject: [PATCH 08/11] cleanups --- .github/workflows/ci.yml | 2 +- .../Auth/AuthenticatedSessionController.php | 13 ++---- .../Auth/NewPasswordController.php | 42 +++++++----------- .../Auth/PasswordResetLinkController.php | 23 +++++----- .../Auth/RegisteredUserController.php | 36 ++++----------- app/Http/Requests/Auth/LoginRequest.php | 44 ++++++------------- app/Providers/AppServiceProvider.php | 18 +++++--- 7 files changed, 64 insertions(+), 114 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c59592a..1338fa6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,7 +52,7 @@ jobs: # Check PHP code formatting with PHPFMT - name: Run PHPFMT - run: ./vendor/bin/phpmd app,routes text cleancode,codesize,controversial,design,naming,unusedcode + run: ./vendor/bin/phpmd app,routes text codesize,controversial,design,naming,unusedcode # Static analysis using Larastan - name: Run Larastan diff --git a/app/Http/Controllers/Auth/AuthenticatedSessionController.php b/app/Http/Controllers/Auth/AuthenticatedSessionController.php index 66c11f8..62f8d03 100644 --- a/app/Http/Controllers/Auth/AuthenticatedSessionController.php +++ b/app/Http/Controllers/Auth/AuthenticatedSessionController.php @@ -5,19 +5,12 @@ use App\Http\Controllers\Controller; use App\Http\Requests\Auth\LoginRequest; use App\Models\User; -use Illuminate\Contracts\Auth\StatefulGuard; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; class AuthenticatedSessionController extends Controller { - protected StatefulGuard $auth; - - public function __construct(StatefulGuard $auth) - { - $this->auth = $auth; - } - /** * Handle an incoming authentication request. */ @@ -30,7 +23,7 @@ public function store(LoginRequest $request): JsonResponse $user = User::where('email', $request->email)->first(); - if (!$this->auth->attempt($validatedData)) { + if (!Auth::attempt($validatedData)) { return response()->json([ 'success' => false, 'message' => 'Login failed. Please check your credentials.' @@ -51,7 +44,7 @@ public function store(LoginRequest $request): JsonResponse */ public function destroy(Request $request): JsonResponse { - $this->auth->logout(); + Auth::guard('web')->logout(); $request->session()->invalidate(); diff --git a/app/Http/Controllers/Auth/NewPasswordController.php b/app/Http/Controllers/Auth/NewPasswordController.php index 46f0741..4277c32 100644 --- a/app/Http/Controllers/Auth/NewPasswordController.php +++ b/app/Http/Controllers/Auth/NewPasswordController.php @@ -4,27 +4,16 @@ use App\Http\Controllers\Controller; use Illuminate\Auth\Events\PasswordReset; -use Illuminate\Contracts\Auth\PasswordBroker; -use Illuminate\Contracts\Hashing\Hasher; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Password; use Illuminate\Support\Str; -use Illuminate\Validation\Rules\Password; -use Illuminate\Validation\ValidationException as ValidationEx; +use Illuminate\Validation\Rules; +use Illuminate\Validation\ValidationException; class NewPasswordController extends Controller { - protected PasswordBroker $passwordBroker; - protected Hasher $hasher; - protected Str $strHelper; - - public function __construct(PasswordBroker $passwordBroker, Hasher $hasher, Str $strHelper) - { - $this->passwordBroker = $passwordBroker; - $this->hasher = $hasher; - $this->strHelper = $strHelper; - } - /** * Handle an incoming new password request. * @@ -35,29 +24,28 @@ public function store(Request $request): JsonResponse $request->validate([ 'token' => ['required'], 'email' => ['required', 'email'], - 'password' => ['required', 'confirmed', Password::min(8) - ->letters() - ->mixedCase() - ->numbers() - ->symbols() - ->uncompromised()], + 'password' => ['required', 'confirmed', Rules\Password::defaults()], ]); - // Attempt to reset the user's password - $status = $this->passwordBroker->reset( + // Here we will attempt to reset the user's password. If it is successful we + // will update the password on an actual user model and persist it to the + // database. Otherwise we will parse the error and return the response. + $status = Password::reset( $request->only('email', 'password', 'password_confirmation', 'token'), function ($user) use ($request) { $user->forceFill([ - 'password' => $this->hasher->make($request->string('password')), - 'remember_token' => $this->strHelper->random(60), + 'password' => Hash::make($request->string('password')), + 'remember_token' => Str::random(60), ])->save(); event(new PasswordReset($user)); } ); - if ($status != PasswordBroker::PASSWORD_RESET) { - throw new ValidationEx(__('email'), [__($status)]); + if ($status != Password::PASSWORD_RESET) { + throw ValidationException::withMessages([ + 'email' => [__($status)], + ]); } return response()->json(['status' => __($status)]); diff --git a/app/Http/Controllers/Auth/PasswordResetLinkController.php b/app/Http/Controllers/Auth/PasswordResetLinkController.php index 5445eee..95cde8e 100644 --- a/app/Http/Controllers/Auth/PasswordResetLinkController.php +++ b/app/Http/Controllers/Auth/PasswordResetLinkController.php @@ -3,20 +3,13 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; -use Illuminate\Contracts\Auth\PasswordBroker; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Validation\ValidationException as ValidationEx; +use Illuminate\Support\Facades\Password; +use Illuminate\Validation\ValidationException; class PasswordResetLinkController extends Controller { - protected PasswordBroker $passwordBroker; - - public function __construct(PasswordBroker $passwordBroker) - { - $this->passwordBroker = $passwordBroker; - } - /** * Handle an incoming password reset link request. * @@ -28,13 +21,17 @@ public function store(Request $request): JsonResponse 'email' => ['required', 'email'], ]); - // Use the injected PasswordBroker instead of static access - $status = $this->passwordBroker->sendResetLink( + // We will send the password reset link to this user. Once we have attempted + // to send the link, we will examine the response then see the message we + // need to show to the user. Finally, we'll send out a proper response. + $status = Password::sendResetLink( $request->only('email') ); - if ($status != PasswordBroker::RESET_LINK_SENT) { - throw new ValidationEx(__('email'), [__($status)]); + if ($status != Password::RESET_LINK_SENT) { + throw ValidationException::withMessages([ + 'email' => [__($status)], + ]); } return response()->json(['status' => __($status)]); diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index c3b29c0..9690a3a 100644 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -5,25 +5,14 @@ use App\Http\Controllers\Controller; use App\Models\User; use Illuminate\Auth\Events\Registered; -use Illuminate\Contracts\Auth\StatefulGuard; -use Illuminate\Contracts\Hashing\Hasher; -use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Password; +use Illuminate\Http\JsonResponse; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Hash; +use Illuminate\Validation\Rules; class RegisteredUserController extends Controller { - protected User $user; - protected Hasher $hasher; - protected StatefulGuard $auth; - - public function __construct(User $user, Hasher $hasher, StatefulGuard $auth) - { - $this->user = $user; - $this->hasher = $hasher; - $this->auth = $auth; - } - /** * Handle an incoming registration request. * @@ -31,28 +20,21 @@ public function __construct(User $user, Hasher $hasher, StatefulGuard $auth) */ public function store(Request $request): JsonResponse { - $passwordDefaults = Password::min(8) - ->letters() - ->mixedCase() - ->numbers() - ->symbols() - ->uncompromised(); - $request->validate([ 'name' => ['required', 'string', 'max:255'], - 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . $this->user->getTable()], - 'password' => ['required', 'confirmed', $passwordDefaults], + 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . User::class], + 'password' => ['required', 'confirmed', Rules\Password::defaults()], ]); - $user = $this->user->create([ + $user = User::create([ 'name' => $request->name, 'email' => $request->email, - 'password' => $this->hasher->make($request->string('password')), + 'password' => Hash::make($request->string('password')), ]); event(new Registered($user)); - $this->auth->login($user); + Auth::login($user); return response()->json([ 'message' => 'User registered successfully', diff --git a/app/Http/Requests/Auth/LoginRequest.php b/app/Http/Requests/Auth/LoginRequest.php index 54b08a4..f5692bf 100644 --- a/app/Http/Requests/Auth/LoginRequest.php +++ b/app/Http/Requests/Auth/LoginRequest.php @@ -4,31 +4,13 @@ use Illuminate\Auth\Events\Lockout; use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Contracts\Auth\StatefulGuard; -use Illuminate\Cache\RateLimiter as RateLimiterContract; -use Illuminate\Contracts\Translation\Translator; -use Illuminate\Validation\ValidationException; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\Str; +use Illuminate\Validation\ValidationException; class LoginRequest extends FormRequest { - protected $auth; - protected $rateLimiter; - protected $translator; - protected $stringHelper; - - /** - * Constructor to inject dependencies. - */ - public function __construct(StatefulGuard $auth, RateLimiterContract $rateLimiter, Translator $translator, Str $stringHelper) - { - parent::__construct(); - $this->auth = $auth; - $this->rateLimiter = $rateLimiter; - $this->translator = $translator; - $this->stringHelper = $stringHelper; - } - /** * Determine if the user is authorized to make this request. */ @@ -59,15 +41,15 @@ public function authenticate(): void { $this->ensureIsNotRateLimited(); - if (!$this->auth->attempt($this->only('email', 'password'), $this->boolean('remember'))) { - $this->rateLimiter->hit($this->throttleKey()); + if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) { + RateLimiter::hit($this->throttleKey()); - throw new ValidationException($this->getMessageBag(), [ - 'email' => $this->translator->get('auth.failed'), + throw ValidationException::withMessages([ + 'email' => __('auth.failed'), ]); } - $this->rateLimiter->clear($this->throttleKey()); + RateLimiter::clear($this->throttleKey()); } /** @@ -77,16 +59,16 @@ public function authenticate(): void */ public function ensureIsNotRateLimited(): void { - if (!$this->rateLimiter->tooManyAttempts($this->throttleKey(), 5)) { + if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { return; } event(new Lockout($this)); - $seconds = $this->rateLimiter->availableIn($this->throttleKey()); + $seconds = RateLimiter::availableIn($this->throttleKey()); - throw new ValidationException($this->getMessageBag(), [ - 'email' => $this->translator->get('auth.throttle', [ + throw ValidationException::withMessages([ + 'email' => trans('auth.throttle', [ 'seconds' => $seconds, 'minutes' => ceil($seconds / 60), ]), @@ -98,6 +80,6 @@ public function ensureIsNotRateLimited(): void */ public function throttleKey(): string { - return $this->stringHelper->transliterate($this->stringHelper->lower($this->input('email')) . '|' . $this->ip()); + return Str::transliterate(Str::lower($this->input('email')).'|'.$this->ip()); } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 457cb42..6051392 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,8 +2,10 @@ namespace App\Providers; -use Illuminate\Contracts\Auth\Access\Gate as GateContract; + +use Illuminate\Auth\Notifications\ResetPassword; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Facades\Gate; class AppServiceProvider extends ServiceProvider { @@ -18,11 +20,17 @@ public function register(): void /** * Bootstrap any application services. */ - public function boot(GateContract $gate): void + public function boot(): void { - // Use the injected GateContract instance - $gate->after(function ($user) { - return $user->hasRole('admin') ? true : null; + ResetPassword::createUrlUsing(function (object $notifiable, string $token) { + return config('app.frontend_url')."/password-reset/$token?email={$notifiable->getEmailForPasswordReset()}"; + }); + + Gate::after(function ($user, $ability) { + if($user->hasRole('admin')){ + return true; + } + return false; }); } } From 416ed8815f2431d846a75e17677fcd5ac9df46ec Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Fri, 21 Feb 2025 14:13:46 +0530 Subject: [PATCH 09/11] Refactor CI workflow + dependencies and improve test reporting --- .github/workflows/ci.yml | 21 +++++++++++++++++++++ app/Providers/AppServiceProvider.php | 12 ++++++------ tests/Feature/Auth/AuthenticationTest.php | 4 ++-- tests/Feature/Auth/RegistrationTest.php | 2 +- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1338fa6..9d6b280 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,3 +57,24 @@ jobs: # Static analysis using Larastan - name: Run Larastan run: ./vendor/bin/phpstan analyse app routes --memory-limit=2G + + # Run PHPUnit Tests + - name: Run PHPUnit Tests + env: + DB_CONNECTION: mysql + DB_DATABASE: testing_db + DB_USERNAME: user + DB_PASSWORD: password + DB_HOST: 127.0.0.1 + run: | + php artisan config:clear + php artisan cache:clear + php artisan test --testsuite=Feature --stop-on-failure + + # Optional: Upload Test Results (JUnit format) for better visibility in CI + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v3 + with: + name: test-results + path: storage/test-results diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6051392..aa5fa1e 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -23,14 +23,14 @@ public function register(): void public function boot(): void { ResetPassword::createUrlUsing(function (object $notifiable, string $token) { - return config('app.frontend_url')."/password-reset/$token?email={$notifiable->getEmailForPasswordReset()}"; + return config('app.frontend_url') . "/password-reset/$token?email={$notifiable->getEmailForPasswordReset()}"; }); - Gate::after(function ($user, $ability) { - if($user->hasRole('admin')){ - return true; - } - return false; + Gate::after(function ($user) { + if ($user->hasRole('admin')) { + return true; + } + return false; }); } } diff --git a/tests/Feature/Auth/AuthenticationTest.php b/tests/Feature/Auth/AuthenticationTest.php index 316a4f4..1a5a163 100644 --- a/tests/Feature/Auth/AuthenticationTest.php +++ b/tests/Feature/Auth/AuthenticationTest.php @@ -11,7 +11,7 @@ ]); $this->assertAuthenticated(); - $response->assertNoContent(); + $response->assertStatus(200); }); test('users can not authenticate with invalid password', function () { @@ -31,5 +31,5 @@ $response = $this->actingAs($user)->post('/logout'); $this->assertGuest(); - $response->assertNoContent(); + $response->assertStatus(200); }); diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php index 012ef40..d3ff0ff 100644 --- a/tests/Feature/Auth/RegistrationTest.php +++ b/tests/Feature/Auth/RegistrationTest.php @@ -9,5 +9,5 @@ ]); $this->assertAuthenticated(); - $response->assertNoContent(); + $response->assertStatus(201); }); From 21149e14935dc1a7277f6aaee31f56f966005bd4 Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Fri, 21 Feb 2025 14:14:41 +0530 Subject: [PATCH 10/11] update ci checks --- .github/workflows/ci.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d6b280..1cf146a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,11 +70,3 @@ jobs: php artisan config:clear php artisan cache:clear php artisan test --testsuite=Feature --stop-on-failure - - # Optional: Upload Test Results (JUnit format) for better visibility in CI - - name: Upload Test Results - if: always() - uses: actions/upload-artifact@v3 - with: - name: test-results - path: storage/test-results From d6f3caa799ea94c0ce07289ab7ea789bd2d8a3bf Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Fri, 21 Feb 2025 14:18:20 +0530 Subject: [PATCH 11/11] remove nunomaduro for larastan test --- composer.json | 2 +- composer.lock | 189 +++++++++++++++++++++++++------------------------- 2 files changed, 95 insertions(+), 96 deletions(-) diff --git a/composer.json b/composer.json index 19e13c2..43c15eb 100644 --- a/composer.json +++ b/composer.json @@ -17,13 +17,13 @@ }, "require-dev": { "fakerphp/faker": "^1.23", + "larastan/larastan": "^3.1", "laravel/breeze": "^2.3", "laravel/pail": "^1.1", "laravel/pint": "^1.13", "laravel/sail": "^1.26", "mockery/mockery": "^1.6", "nunomaduro/collision": "^8.1", - "nunomaduro/larastan": "^3.1", "pestphp/pest": "^3.7", "pestphp/pest-plugin-laravel": "^3.1", "phpmd/phpmd": "^2.15" diff --git a/composer.lock b/composer.lock index 8409abf..82fd279 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f45493c028af791e9edaace1456b4f33", + "content-hash": "8f864f830993103f89d8e0a1e3d7652c", "packages": [ { "name": "brick/math", @@ -6535,6 +6535,99 @@ }, "time": "2024-11-18T16:19:46+00:00" }, + { + "name": "larastan/larastan", + "version": "v3.1.0", + "source": { + "type": "git", + "url": "https://github.com/larastan/larastan.git", + "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/larastan/larastan/zipball/dbb2dc20e5c8e1ed3ff289054e1955f269187312", + "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312", + "shasum": "" + }, + "require": { + "ext-json": "*", + "illuminate/console": "^11.15.0 || ^12.0", + "illuminate/container": "^11.15.0 || ^12.0", + "illuminate/contracts": "^11.15.0 || ^12.0", + "illuminate/database": "^11.15.0 || ^12.0", + "illuminate/http": "^11.15.0 || ^12.0", + "illuminate/pipeline": "^11.15.0 || ^12.0", + "illuminate/support": "^11.15.0 || ^12.0", + "php": "^8.2", + "phpmyadmin/sql-parser": "^5.9.0", + "phpstan/phpstan": "^2.1.3" + }, + "require-dev": { + "doctrine/coding-standard": "^12.0", + "laravel/framework": "^11.15.0 || ^12.0", + "mockery/mockery": "^1.6", + "nikic/php-parser": "^5.3", + "orchestra/canvas": "^v9.1.3 || ^10.0", + "orchestra/testbench-core": "^9.5.2 || ^10.0", + "phpstan/phpstan-deprecation-rules": "^2.0.0", + "phpunit/phpunit": "^10.5.35 || ^11.3.6" + }, + "suggest": { + "orchestra/testbench": "Using Larastan for analysing a package needs Testbench" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon" + ] + }, + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Larastan\\Larastan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Can Vural", + "email": "can9119@gmail.com" + }, + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "larastan", + "laravel", + "package", + "php", + "static analysis" + ], + "support": { + "issues": "https://github.com/larastan/larastan/issues", + "source": "https://github.com/larastan/larastan/tree/v3.1.0" + }, + "funding": [ + { + "url": "https://github.com/canvural", + "type": "github" + } + ], + "time": "2025-02-20T15:25:15+00:00" + }, { "name": "laravel/breeze", "version": "v2.3.4", @@ -7044,100 +7137,6 @@ ], "time": "2025-01-23T13:41:43+00:00" }, - { - "name": "nunomaduro/larastan", - "version": "v3.1.0", - "source": { - "type": "git", - "url": "https://github.com/larastan/larastan.git", - "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/larastan/larastan/zipball/dbb2dc20e5c8e1ed3ff289054e1955f269187312", - "reference": "dbb2dc20e5c8e1ed3ff289054e1955f269187312", - "shasum": "" - }, - "require": { - "ext-json": "*", - "illuminate/console": "^11.15.0 || ^12.0", - "illuminate/container": "^11.15.0 || ^12.0", - "illuminate/contracts": "^11.15.0 || ^12.0", - "illuminate/database": "^11.15.0 || ^12.0", - "illuminate/http": "^11.15.0 || ^12.0", - "illuminate/pipeline": "^11.15.0 || ^12.0", - "illuminate/support": "^11.15.0 || ^12.0", - "php": "^8.2", - "phpmyadmin/sql-parser": "^5.9.0", - "phpstan/phpstan": "^2.1.3" - }, - "require-dev": { - "doctrine/coding-standard": "^12.0", - "laravel/framework": "^11.15.0 || ^12.0", - "mockery/mockery": "^1.6", - "nikic/php-parser": "^5.3", - "orchestra/canvas": "^v9.1.3 || ^10.0", - "orchestra/testbench-core": "^9.5.2 || ^10.0", - "phpstan/phpstan-deprecation-rules": "^2.0.0", - "phpunit/phpunit": "^10.5.35 || ^11.3.6" - }, - "suggest": { - "orchestra/testbench": "Using Larastan for analysing a package needs Testbench" - }, - "type": "phpstan-extension", - "extra": { - "phpstan": { - "includes": [ - "extension.neon" - ] - }, - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "Larastan\\Larastan\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Can Vural", - "email": "can9119@gmail.com" - }, - { - "name": "Nuno Maduro", - "email": "enunomaduro@gmail.com" - } - ], - "description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel", - "keywords": [ - "PHPStan", - "code analyse", - "code analysis", - "larastan", - "laravel", - "package", - "php", - "static analysis" - ], - "support": { - "issues": "https://github.com/larastan/larastan/issues", - "source": "https://github.com/larastan/larastan/tree/v3.1.0" - }, - "funding": [ - { - "url": "https://github.com/canvural", - "type": "github" - } - ], - "abandoned": "larastan/larastan", - "time": "2025-02-20T15:25:15+00:00" - }, { "name": "pdepend/pdepend", "version": "2.16.2",