diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 293bb8eb..59c4b08d 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -44,12 +44,6 @@ jobs: - name: Install dependencies with composer run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - name: Setup project - run: | - mv config/autoload/local.php.dist config/autoload/local.php - mv config/autoload/mail.local.php.dist config/autoload/mail.local.php - mv config/autoload/local.test.php.dist config/autoload/local.test.php - - name: Collect code coverage with PHPUnit run: vendor/bin/phpunit --colors=always --coverage-clover clover.xml diff --git a/.github/workflows/qodana_code_quality.yml b/.github/workflows/qodana_code_quality.yml index 4bbb0dda..833566c3 100644 --- a/.github/workflows/qodana_code_quality.yml +++ b/.github/workflows/qodana_code_quality.yml @@ -14,6 +14,9 @@ jobs: contents: write pull-requests: write checks: write + strategy: + matrix: + php-versions: [ '8.2', '8.3' ] steps: - uses: actions/checkout@v4 with: @@ -22,7 +25,7 @@ jobs: - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: "${{ matrix.php }}" + php-version: ${{ matrix.php-versions }} coverage: pcov ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On tools: composer:v2, cs2pr diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 6a700f5d..ee7251d0 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -44,11 +44,5 @@ jobs: - name: Install dependencies with composer run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - name: Setup project - run: | - mv config/autoload/local.php.dist config/autoload/local.php - mv config/autoload/mail.local.php.dist config/autoload/mail.local.php - mv config/autoload/local.test.php.dist config/autoload/local.test.php - - name: Run static analysis with PHPStan run: vendor/bin/phpstan analyse diff --git a/bin/composer-post-install-script.php b/bin/composer-post-install-script.php new file mode 100644 index 00000000..af2e8a93 --- /dev/null +++ b/bin/composer-post-install-script.php @@ -0,0 +1,35 @@ + 'config/autoload/local.php.dist', + 'destination' => 'config/autoload/local.php', + ], + [ + 'source' => 'config/autoload/local.test.php.dist', + 'destination' => 'config/autoload/local.test.php', + ], + [ + 'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist', + 'destination' => 'config/autoload/mail.global.php', + ], +]; + +array_walk($files, 'copyFile'); diff --git a/composer.json b/composer.json index b5736e6e..6a10c612 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "dotkernel/dot-flashmessenger": "^3.4.2", "dotkernel/dot-geoip": "^3.6.0", "dotkernel/dot-helpers": "^3.4.2", - "dotkernel/dot-mail": "^4.1.1", + "dotkernel/dot-mail": "^5.1.0", "dotkernel/dot-navigation": "^3.4.2", "dotkernel/dot-rbac-guard": "^3.4.2", "dotkernel/dot-session": "^5.6.0", @@ -57,9 +57,8 @@ }, "require-dev": { "filp/whoops": "^2.15.4", - "laminas/laminas-coding-standard": "^2.5.0", + "laminas/laminas-coding-standard": "^3.0", "laminas/laminas-development-mode": "^3.12.0", - "laminas/laminas-http": "^2.19.0", "mezzio/mezzio-tooling": "^2.9.0", "phpunit/phpunit": "^10.5.9", "roave/security-advisories": "dev-latest", @@ -88,6 +87,9 @@ "post-create-project-cmd": [ "@development-enable" ], + "post-update-cmd": [ + "php bin/composer-post-install-script.php" + ], "development-disable": "laminas-development-mode disable", "development-enable": "laminas-development-mode enable", "development-status": "laminas-development-mode status", @@ -101,7 +103,7 @@ "cs-check": "phpcs", "cs-fix": "phpcbf", "serve": "php -S 0.0.0.0:8080 -t public/", - "static-analysis": "phpstan analyse", + "static-analysis": "phpstan analyse --memory-limit 1G", "test": "phpunit --colors=always", "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", "twig-cs-check": "vendor/bin/twig-cs-fixer lint --config=config/twig-cs-fixer.php", diff --git a/config/autoload/authentication.global.php b/config/autoload/authentication.global.php index 6fe90289..f8f71cf0 100644 --- a/config/autoload/authentication.global.php +++ b/config/autoload/authentication.global.php @@ -12,7 +12,6 @@ 'identity_class' => Admin::class, 'identity_property' => 'identity', 'credential_property' => 'password', - 'credential_callable' => 'Admin\Admin\Doctrine\AdminAuthentication::verifyCredential', 'messages' => [ 'success' => 'Authenticated successfully.', 'not_found' => 'Identity not found.', diff --git a/config/autoload/local.php.dist b/config/autoload/local.php.dist index 9935f62b..455334fc 100644 --- a/config/autoload/local.php.dist +++ b/config/autoload/local.php.dist @@ -26,13 +26,13 @@ $databases = [ ]; return [ - 'application' => [ + 'application' => [ 'name' => $app['name'] ?? '', 'url' => $baseUrl, ], - 'databases' => $databases, - 'doctrine' => [ - 'connection' => [ + 'databases' => $databases, + 'doctrine' => [ + 'connection' => [ 'orm_default' => [ 'params' => $databases['default'], ], diff --git a/config/autoload/mail.local.php.dist b/config/autoload/mail.local.php.dist deleted file mode 100644 index 79bad532..00000000 --- a/config/autoload/mail.local.php.dist +++ /dev/null @@ -1,92 +0,0 @@ - [ -// the key is the mail service name, this is the default one, which does not extend any configuration - 'default' => [ -// tells which other mail service configuration to extend - 'extends' => null, - /** - * the mail transport to use - * can be any class implementing Laminas\Mail\Transport\TransportInterface - * - * for standard mail transports, you can use these aliases - * - sendmail => Laminas\Mail\Transport\Sendmail - * - smtp => Laminas\Mail\Transport\Smtp - * - file => Laminas\Mail\Transport\File - * - in_memory => Laminas\Mail\Transport\InMemory - * - * defaults to sendmail - **/ - 'transport' => Laminas\Mail\Transport\Sendmail::class, - // Uncomment the below line if you want to save a copy of all sent emails to a certain IMAP folder - // Valid only if the Transport is SMTP -// 'save_sent_message_folder' => ['INBOX.Sent'], -// message configuration - 'message_options' => [ - 'from' => '', - 'from_name' => 'Dotkernel', - 'reply_to' => '', - 'reply_to_name' => '', - 'to' => [], - 'cc' => [], - 'bcc' => [], - 'subject' => '', - 'body' => [ - 'content' => '', - 'charset' => 'utf-8', - ], - 'attachments' => [ - 'files' => [], - 'dir' => [ - 'iterate' => false, - 'path' => 'data/mail/attachments', - 'recursive' => false, - ], - ], - ], -// options that will be used only if Laminas\Mail\Transport\Smtp adapter is used - 'smtp_options' => [ - 'host' => '', - 'port' => 587, - 'connection_class' => 'login', - 'connection_config' => [ - 'username' => '', - 'password' => '', - 'ssl' => 'ssl', - ], - ], -// file options that will be used only if the adapter is Laminas\Mail\Transport\File -// 'file_options' => [ -// 'path' => 'data/mail/output', -// //a callable that will get the Laminas\Mail\Transport\File object as an argument -// //and should return the filename if null is used, and empty callable will be used -// 'callback' => null, -// ], -// listeners to register with the mail service, for mail events - 'event_listeners' => [ -// [ -// 'type' => 'service or class name', -// 'priority' => 1, -// ], - ], - ], -// option to log the SENT emails - 'log' => [ - 'sent' => getcwd() . '/log/mail/sent.log', - ], - - /** - * You can define other mail services here, with the same structure as the default block - * you can even extend from the default block, and overwrite only the differences - */ - ], -]; diff --git a/phpcs.xml b/phpcs.xml index 10a9104c..a725e9d8 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -20,5 +20,8 @@ test - + + + + diff --git a/src/Admin/src/Adapter/AuthenticationAdapter.php b/src/Admin/src/Adapter/AuthenticationAdapter.php index 184009b4..dc7c2d10 100644 --- a/src/Admin/src/Adapter/AuthenticationAdapter.php +++ b/src/Admin/src/Adapter/AuthenticationAdapter.php @@ -8,6 +8,7 @@ use Admin\Admin\Entity\AdminIdentity; use Admin\Admin\Entity\AdminRole; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\Exception\ORMException; use Dot\DependencyInjection\Attribute\Inject; use Exception; use Laminas\Authentication\Adapter\AdapterInterface; @@ -64,6 +65,7 @@ private function getCredential(): string /** * @throws Exception + * @throws ORMException */ public function authenticate(): Result { @@ -85,6 +87,7 @@ public function authenticate(): Result [$this->config['orm_default']['messages']['not_found']] ); } + $this->entityManager->refresh($identityClass); $getCredential = "get" . ucfirst($this->config['orm_default']['credential_property']); diff --git a/src/Admin/src/Entity/AdminIdentity.php b/src/Admin/src/Entity/AdminIdentity.php index 48d48398..1b35e836 100644 --- a/src/Admin/src/Entity/AdminIdentity.php +++ b/src/Admin/src/Entity/AdminIdentity.php @@ -33,16 +33,12 @@ public function getStatus(): AdminStatusEnum return $this->status; } - /** - * @return iterable - */ public function getRoles(): iterable { return $this->roles; } /** - * @return array * @psalm-return array */ public function getDetails(): array diff --git a/src/Admin/src/Form/AdminForm.php b/src/Admin/src/Form/AdminForm.php index 7800c9de..c9941f07 100644 --- a/src/Admin/src/Form/AdminForm.php +++ b/src/Admin/src/Form/AdminForm.php @@ -28,9 +28,6 @@ public function __construct(?string $name = null, array $options = []) $this->inputFilter->init(); } - /** - * @param array $roles - */ public function setRoles(array $roles): void { $this->roles = $roles; diff --git a/src/Admin/src/FormData/AdminFormData.php b/src/Admin/src/FormData/AdminFormData.php index d2441971..400a66ae 100644 --- a/src/Admin/src/FormData/AdminFormData.php +++ b/src/Admin/src/FormData/AdminFormData.php @@ -14,9 +14,6 @@ class AdminFormData public ?string $status = null; public array $roles = []; - /** - * @return array - */ public function getRoles(): array { return $this->roles; @@ -35,9 +32,6 @@ public function fromEntity(Admin $admin): self return $this; } - /** - * @return array - */ public function getArrayCopy(): array { return [ diff --git a/src/Admin/src/Service/AdminService.php b/src/Admin/src/Service/AdminService.php index 410c3cf1..05d90bef 100644 --- a/src/Admin/src/Service/AdminService.php +++ b/src/Admin/src/Service/AdminService.php @@ -212,12 +212,12 @@ public function logAdminVisit(array $serverParams, string $name, SuccessFailureE $ipAddress = IpService::getUserIp($serverParams); - $country = (string) $this->locationService->getCountry($ipAddress)->getName(); - $continent = (string) $this->locationService->getContinent($ipAddress)->getName(); - $organization = (string) $this->locationService->getOrganization($ipAddress)->getName(); + $country = $this->locationService->getCountry($ipAddress)->getName(); + $continent = $this->locationService->getContinent($ipAddress)->getName(); + $organization = $this->locationService->getOrganization($ipAddress)->getName(); $adminLogin = (new AdminLogin()) - ->setAdminIp($ipAddress) + ->setAdminIp($this->locationService->obfuscateIpAddress($ipAddress)) ->setContinent($continent) ->setCountry($country) ->setOrganization($organization) diff --git a/src/App/src/Plugin/FormsPlugin.php b/src/App/src/Plugin/FormsPlugin.php index 0030c211..48c446ad 100644 --- a/src/App/src/Plugin/FormsPlugin.php +++ b/src/App/src/Plugin/FormsPlugin.php @@ -80,10 +80,6 @@ private function formMessagesToString(array $formMessages): string return $messages; } - /** - * @param array $formMessages - * @return array - */ protected function processFormMessages(array $formMessages): array { $messages = []; diff --git a/test/Unit/App/Middleware/AuthMiddlewareTest.php b/test/Unit/App/Middleware/AuthMiddlewareTest.php index ced5bd39..f53d41d7 100644 --- a/test/Unit/App/Middleware/AuthMiddlewareTest.php +++ b/test/Unit/App/Middleware/AuthMiddlewareTest.php @@ -11,8 +11,8 @@ use Dot\Rbac\Guard\Guard\GuardInterface; use Dot\Rbac\Guard\Options\RbacGuardOptions; use Dot\Rbac\Guard\Provider\GuardsProviderInterface; +use Fig\Http\Message\StatusCodeInterface; use Laminas\Diactoros\Response\RedirectResponse; -use Laminas\Http\Response; use Mezzio\Router\RouterInterface; use PHPUnit\Framework\MockObject\Exception; use Psr\Http\Message\ResponseInterface; @@ -58,7 +58,7 @@ public function testWillRedirectWhenNotGranted(): void ); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertTrue($response->hasHeader('location')); - $this->assertEquals(Response::STATUS_CODE_302, $response->getStatusCode()); + $this->assertEquals(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode()); } /** @@ -144,7 +144,7 @@ public function getPriority(): int ); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertTrue($response->hasHeader('location')); - $this->assertEquals(Response::STATUS_CODE_302, $response->getStatusCode()); + $this->assertEquals(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode()); } /**