static test

This commit is contained in:
2025-04-25 21:27:31 -04:00
parent 025bc2d924
commit ac99a78bdf
9 changed files with 103 additions and 14 deletions

View File

@@ -40,3 +40,17 @@ Run Code Lint:
image: siteworxpro/composer
script:
- composer run tests:lint
Run Code Sniffer:
stage: tests
needs:
- Install Composer Libraries
rules:
- if: '$CI_COMMIT_TAG'
when: never
- if: '$CI_PIPELINE_SOURCE == "push"'
when: on_success
- when: never
image: siteworxpro/composer
script:
- composer run tests:phpstan

View File

@@ -21,7 +21,8 @@
"phpunit/phpunit": "^12.1",
"mockery/mockery": "^1.6",
"squizlabs/php_codesniffer": "^3.12",
"lendable/composer-license-checker": "^1.2"
"lendable/composer-license-checker": "^1.2",
"phpstan/phpstan": "^2.1"
},
"scripts": {
"tests:unit": [
@@ -37,6 +38,9 @@
],
"tests:license": [
"composer-license-checker"
],
"tests:phpstan": [
"phpstan analyse --level 4 ./src/ -c phpstan.neon"
]
},
"repositories": {

60
composer.lock generated
View File

@@ -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": "8e6be626529d82f7cdc7631ba7f92165",
"content-hash": "597f3c330fcbd311310b6c23e67f82ad",
"packages": [
{
"name": "brick/math",
@@ -2949,6 +2949,64 @@
},
"time": "2022-02-21T01:04:05+00:00"
},
{
"name": "phpstan/phpstan",
"version": "2.1.12",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "96dde49e967c0c22812bcfa7bda4ff82c09f3b0c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/96dde49e967c0c22812bcfa7bda4ff82c09f3b0c",
"reference": "96dde49e967c0c22812bcfa7bda4ff82c09f3b0c",
"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-04-16T13:19:18+00:00"
},
{
"name": "phpunit/php-code-coverage",
"version": "12.1.2",

View File

@@ -8,7 +8,8 @@ return [
* The server configuration.
*/
'server' => [
'port' => Env::get('HTTP_PORT', 9501),
'port' => Env::get('HTTP_PORT', 9501, 'int'),
'dev_mode' => Env::get('DEV_MODE', false, 'bool'),
],
/**
@@ -20,5 +21,11 @@ return [
'database' => Env::get('DB_DATABASE', 'siteworxpro'),
'username' => Env::get('DB_USERNAME', 'siteworxpro'),
'password' => Env::get('DB_PASSWORD', 'password'),
],
'cors' => [
'allowed_origins' => Env::get('CORS_ALLOWED_ORIGINS', 'http://localhost:3000'),
'allow_credentials' => Env::get('CORS_ALLOW_CREDENTIALS', true, 'bool'),
'max_age' => Env::get('CORS_MAX_AGE', 3600, 'int'),
]
];

5
phpstan.neon Normal file
View File

@@ -0,0 +1,5 @@
parameters:
tips:
treatPhpDocTypesAsCertain: false
ignoreErrors:
- '#Static call to instance method#'

View File

@@ -15,7 +15,7 @@ use Siteworx\Config\Exception\UnsupportedFormatException;
* This class serves as a facade for the configuration settings of the application.
* It extends the Facade class from the Illuminate\Support\Facades namespace.
*
* @method static string|int|bool|float get(string $key) Retrieve the configuration value for the given key.
* @method static bool | string | int get(string $key) Retrieve the configuration value for the given key.
*
* @package Siteworx\App\Facades
*/

View File

@@ -16,7 +16,7 @@ class JsonResponseFactory
/**
* Create a JSON response with the given data and status code.
*
* @param mixed $data The data to include in the response.
* @param array $data The data to include in the response.
* @param int $statusCode The HTTP status code for the response.
* @return Response The JSON response.
* @throws \JsonException

View File

@@ -34,7 +34,7 @@ class CorsMiddleware implements MiddlewareInterface
'trim',
explode(
',',
Config::get('CORS_ALLOWED_ORIGINS', 'https://example.com,https://another.com')
Config::get('cors.allowed_origins')
)
);
@@ -57,11 +57,11 @@ class CorsMiddleware implements MiddlewareInterface
?: 'Content-Type, Authorization'
);
if (Config::get('CORS_ALLOW_CREDENTIALS', 'bool')) {
if (Config::get('cors.allow_credentials') === true) {
$response = $response->withHeader('Access-Control-Allow-Credentials', 'true');
}
$maxAge = Config::get('CORS_MAX_AGE') ?: '86400';
$maxAge = Config::get('CORS_MAX_AGE') !== 3600 ? Config::get('CORS_MAX_AGE') : 3600;
return $response->withHeader('Access-Control-Max-Age', $maxAge);
}

View File

@@ -16,12 +16,13 @@ use Spiral\RoadRunner\Http\PSR7Worker;
use Spiral\RoadRunner\Worker;
/**
* Abstract class Server
* Class Server
*
* This abstract class serves as a base for creating server instances.
* It initializes the PSR-7 worker and router, and provides an abstract method
* for registering routes. It also includes a method to start the server and handle
* incoming requests.
* This class represents the main server application.
* It handles incoming HTTP requests, routes them to the appropriate handlers,
* and manages the server lifecycle.
*
* @package Siteworxpro\App
*/
class Server
{
@@ -153,7 +154,7 @@ class Server
Logger::error($e->getTraceAsString());
$json = ['status_code' => 500, 'reason_phrase' => 'Server Error'];
if (Config::get("DEV_MODE", 'bool')) {
if (Config::get("server.dev_mode")) {
$json = [
'status_code' => 500,
'reason_phrase' => 'Server Error',