diff --git a/.editorconfig b/.editorconfig index 3faf149..5e5b915 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,6 +11,6 @@ indent_style = tab indent_size = tab tab_width = 4 -[{*.json, *.yaml, *.yml, *.md}] +[*.{json,yaml,yml,md}] indent_style = space indent_size = 2 diff --git a/.gitattributes b/.gitattributes index 12910b6..ee08e84 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,11 +1,10 @@ -# Not archived .docs export-ignore -tests export-ignore +.github export-ignore .editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore -.travis.yml export-ignore Makefile export-ignore -phpstan.neon export-ignore README.md export-ignore +phpstan.neon export-ignore ruleset.xml export-ignore +tests export-ignore diff --git a/.github/workflows/codesniffer.yml b/.github/workflows/codesniffer.yml index dfc76ff..a58ac4f 100644 --- a/.github/workflows/codesniffer.yml +++ b/.github/workflows/codesniffer.yml @@ -2,6 +2,7 @@ name: "Codesniffer" on: pull_request: + workflow_dispatch: push: branches: ["*"] @@ -12,4 +13,6 @@ on: jobs: codesniffer: name: "Codesniffer" - uses: contributte/.github/.github/workflows/codesniffer.yml@v1 + uses: contributte/.github/.github/workflows/codesniffer.yml@master + with: + php: "8.2" diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 121f718..860c47e 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -2,6 +2,7 @@ name: "Coverage" on: pull_request: + workflow_dispatch: push: branches: ["*"] @@ -12,4 +13,6 @@ on: jobs: coverage: name: "Nette Tester" - uses: contributte/.github/.github/workflows/nette-tester-coverage.yml@v1 + uses: contributte/.github/.github/workflows/nette-tester-coverage-v2.yml@master + with: + php: "8.2" diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 43545cf..eb916bf 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -1,7 +1,8 @@ -name: "PHPStan" +name: "Phpstan" on: pull_request: + workflow_dispatch: push: branches: ["*"] @@ -11,5 +12,7 @@ on: jobs: phpstan: - name: "PHPStan" - uses: contributte/.github/.github/workflows/phpstan.yml@v1 + name: "Phpstan" + uses: contributte/.github/.github/workflows/phpstan.yml@master + with: + php: "8.2" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b37ff92..a574bd1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,35 +2,36 @@ name: "Nette Tester" on: pull_request: + workflow_dispatch: push: - branches: ["*"] + branches: [ "*" ] schedule: - cron: "0 8 * * 1" jobs: - test82: + test83: name: "Nette Tester" - uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + uses: contributte/.github/.github/workflows/nette-tester.yml@master with: - php: "8.2" + php: "8.3" - test81: + test82: name: "Nette Tester" - uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + uses: contributte/.github/.github/workflows/nette-tester.yml@master with: - php: "8.1" + php: "8.2" - test80: + test81: name: "Nette Tester" - uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + uses: contributte/.github/.github/workflows/nette-tester.yml@master with: - php: "8.0" + php: "8.1" - test-lowest: + testlower: name: "Nette Tester" - uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + uses: contributte/.github/.github/workflows/nette-tester.yml@master with: - php: "8.0" - composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest" + php: "8.1" + composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest" diff --git a/.gitignore b/.gitignore index 9f0e148..f0b3670 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ /composer.lock # Tests -/temp -/coverage.html -/coverage.xml +/tests/tmp +/coverage.* +/tests/**/*.log +/tests/**/*.html +/tests/**/*.expected +/tests/**/*.actual diff --git a/Makefile b/Makefile index a3dd4c6..8899265 100644 --- a/Makefile +++ b/Makefile @@ -25,8 +25,8 @@ tests: coverage: ifdef GITHUB_ACTION vendor/bin/codecept build - phpdbg -qrr vendor/bin/codecept run --coverage-xml + vendor/bin/codecept run --coverage-xml else vendor/bin/codecept build - phpdbg -qrr vendor/bin/codecept run --coverage-html + vendor/bin/codecept run --coverage-html endif diff --git a/README.md b/README.md index 10b0e7a..dfc5847 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ For details on how to use this package, check out our [documentation](.docs). | State | Version | Branch | PHP | |-------------|----------|----------|---------| -| dev | `^1.5.0` | `master` | `>=8.0` | -| stable | `^1.4.0` | `master` | `>=8.0` | +| dev | `^1.6.0` | `master` | `>=8.1` | +| stable | `^1.5.0` | `master` | `>=8.1` | ## Development diff --git a/composer.json b/composer.json index d2d9e07..6e5a47b 100644 --- a/composer.json +++ b/composer.json @@ -19,25 +19,22 @@ } ], "require": { - "php": ">= 8.0", - "codeception/codeception": "^5.0.0", - "codeception/lib-innerbrowser": "^3.1.3 || ^4.0.0", - "nette/di": "^3.1.1", - "nette/bootstrap": "^3.2.0", - "nette/http": "^3.2.1", - "nette/utils": "^3.2.8 || ^4.0" + "php": ">=8.1", + "codeception/codeception": "^5.0.13", + "codeception/lib-innerbrowser": "^4.0.2", + "nette/di": "^3.1.8", + "nette/bootstrap": "^3.2.1", + "nette/http": "^3.2.3", + "nette/utils": "^4.0.3" }, "require-dev": { - "latte/latte": "^2.11.5", + "latte/latte": "^3.0.12", "nette/application": "^3.1.7", - "nette/caching": "^3.1.4", - "ninjify/qa": "^0.14", - "phpstan/phpstan": "^1.8.11", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-nette": "^1.1.0", - "phpstan/phpstan-strict-rules": "^1.4.4", - "tracy/tracy": "^2.9.0", - "phpunit/php-code-coverage": "^9.2.24" + "nette/caching": "^3.2.3", + "contributte/qa": "^0.4", + "contributte/phpstan": "^0.1", + "tracy/tracy": "^2.10.5", + "phpunit/php-code-coverage": "^10.1.11" }, "autoload": { "psr-4": { @@ -59,7 +56,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.5.x-dev" + "dev-master": "1.6.x-dev" } } } diff --git a/phpstan.neon b/phpstan.neon index 5ccda88..6fe47d4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,14 +1,20 @@ includes: - - vendor/phpstan/phpstan-deprecation-rules/rules.neon - - vendor/phpstan/phpstan-nette/extension.neon - - vendor/phpstan/phpstan-nette/rules.neon - - vendor/phpstan/phpstan-strict-rules/rules.neon + - vendor/contributte/phpstan/phpstan.neon - extension.neon parameters: - level: 9 + level: 8 + phpVersion: 80100 + + scanDirectories: + - src + + fileExtensions: + - php + paths: - src + - .docs excludePaths: - %currentWorkingDirectory%/tests/_* @@ -22,16 +28,13 @@ parameters: # Should not happen - '#^Method Contributte\\Codeception\\Module\\NetteDIModule::getContainer\(\) should return Nette\\DI\\Container but returns Nette\\DI\\Container\|null#' - '#^Method Contributte\\Codeception\\Http\\Request::getFile\(\) should return Nette\\Http\\FileUpload\|null but returns array\|Nette\\Http\\FileUpload\|null.#' - - '#^Cannot call method getName\(\) on PHPStan\\Reflection\\ClassReflection\|null.#' - '#Parameter \#1 \$path of static method Nette\\Utils\\FileSystem::delete\(\) expects string, string\|false given\.#' - '#Call to an undefined method Nette\\DI\\Definitions\\Definition::setFactory\(\)\.#' - '#Call to protected method setType\(\) of class Nette\\DI\\Definitions\\Definition\.#' - - # Complicated to test dev-required phpstan with separatly installed version - - '#^Call to an undefined method PHPStan\\#' + - '#.+Contributte\\Codeception\\Module\\NetteApplicationModule::\$config.+#' + - '#.+Contributte\\Codeception\\Module\\NetteDIModule::\$config.+#' + - '#.+Contributte\\Codeception\\Module\\NetteDIModule::\$requiredFields.+#' earlyTerminatingMethodCalls: Codeception\Module: - fail - - reportMaybesInPropertyPhpDocTypes: false diff --git a/ruleset.xml b/ruleset.xml index 811b5d2..ca67f98 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,26 +1,24 @@ - - - - - + + + + + - + + + + + - - /tests/functional - - - - /tests/_output - /tests/_support - /tests/_temp + + /tests diff --git a/src/Connector/NetteConnector.php b/src/Connector/NetteConnector.php index 0dd0643..8f33188 100644 --- a/src/Connector/NetteConnector.php +++ b/src/Connector/NetteConnector.php @@ -29,7 +29,7 @@ public function setContainerAccessor(callable $containerAccessor): void * @param Request $request * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint */ - public function doRequest($request): Response + public function doRequest(object $request): Response { $phpSelf = $_SERVER['PHP_SELF']; $_COOKIE = $request->getCookies(); @@ -67,6 +67,7 @@ public function doRequest($request): Response $content = (string) ob_get_clean(); } catch (Throwable $e) { ob_end_clean(); + throw $e; } diff --git a/src/Http/Request.php b/src/Http/Request.php index 6ad4e47..49c051e 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -13,11 +13,9 @@ class Request implements IRequest { - /** @var RequestFactory */ - private $factory; + private RequestFactory $factory; - /** @var IRequest */ - private $request; + private IRequest $request; public function __construct(RequestFactory $factory) { @@ -30,10 +28,7 @@ public function reset(): void $this->request = $this->factory->fromGlobals(); } - /** - * @return mixed - */ - public function getCookie(string $key) + public function getCookie(string $key): mixed { return $this->request->getCookie($key); } @@ -77,18 +72,12 @@ public function getMethod(): string return $this->request->getMethod(); } - /** - * @return mixed - */ - public function getPost(?string $key = null) + public function getPost(?string $key = null): mixed { return func_num_args() === 0 ? $this->request->getPost() : $this->request->getPost($key); } - /** - * @return mixed - */ - public function getQuery(?string $key = null) + public function getQuery(?string $key = null): mixed { return func_num_args() === 0 ? $this->request->getQuery() : $this->request->getQuery($key); } diff --git a/src/Http/Response.php b/src/Http/Response.php index a0993be..1bf59ac 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -14,19 +14,18 @@ class Response implements IResponse { /** @var string The domain in which the cookie will be available */ - public $cookieDomain = ''; + public string $cookieDomain = ''; /** @var string The path in which the cookie will be available */ - public $cookiePath = '/'; + public string $cookiePath = '/'; /** @var bool Whether the cookie is available only through HTTPS */ - public $cookieSecure = false; + public bool $cookieSecure = false; - /** @var int */ - private $code = self::S200_OK; + private int $code = self::S200_OK; /** @var string[] */ - private $headers = []; + private array $headers = []; public function reset(): void { @@ -42,36 +41,40 @@ public function getCode(): int /** * @return static */ - public function setCode(int $code, ?string $reason = null) + public function setCode(int $code, ?string $reason = null): static { $this->code = $code; + return $this; } /** * @return static */ - public function setHeader(string $name, string $value) + public function setHeader(string $name, string $value): static { $this->headers[$name] = $value; + return $this; } /** * @return static */ - public function addHeader(string $name, string $value) + public function addHeader(string $name, string $value): static { $this->headers[$name] = $value; + return $this; } /** * @return static */ - public function setContentType(string $type, ?string $charset = null) + public function setContentType(string $type, ?string $charset = null): static { $this->setHeader('Content-Type', $type . ($charset !== null ? '; charset=' . $charset : '')); + return $this; } @@ -84,7 +87,7 @@ public function redirect(string $url, int $code = self::S302_Found): void /** * @return static */ - public function setExpiration(?string $time) + public function setExpiration(?string $time): static { if (!$time) { $this->setHeader('Cache-Control', 's-maxage=0, max-age=0, must-revalidate'); @@ -122,13 +125,14 @@ public function getHeaders(): array * @param string|int|DateTimeInterface $time * @return static */ - public function setCookie(string $name, string $value, $time, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null, ?string $sameSite = null) + public function setCookie(string $name, string $value, mixed $time, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null, ?string $sameSite = null): static { return $this; } public function deleteCookie(string $name, ?string $path = null, ?string $domain = null, ?bool $secure = null): void { + // No-op } } diff --git a/src/Module/NetteApplicationModule.php b/src/Module/NetteApplicationModule.php index e0de5ec..da425ba 100644 --- a/src/Module/NetteApplicationModule.php +++ b/src/Module/NetteApplicationModule.php @@ -15,18 +15,18 @@ class NetteApplicationModule extends Framework { - /** @var array */ + /** @var array */ protected array $config = [ 'followRedirects' => true, ]; - private string $path; + private ?string $path = null; /** * @param array{path?: string} $settings * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint */ - public function _beforeSuite($settings = []): void + public function _beforeSuite(mixed $settings = []): void { assert(isset($settings['path'])); diff --git a/src/Module/NetteDIModule.php b/src/Module/NetteDIModule.php index 0d42ba5..a148e1a 100644 --- a/src/Module/NetteDIModule.php +++ b/src/Module/NetteDIModule.php @@ -17,10 +17,10 @@ class NetteDIModule extends Module { /** @var callable[] function(Container $configurator): void; */ - public $onCreateConfigurator = []; + public array $onCreateConfigurator = []; /** @var callable[] function(Container $container): void; */ - public $onCreateContainer = []; + public array $onCreateContainer = []; /** @var array */ protected array $config = [ @@ -38,14 +38,12 @@ class NetteDIModule extends Module 'tempDir', ]; - /** @var string */ - private $path; + private string $path; /** @var string[] */ - private $configFiles = []; + private array $configFiles = []; - /** @var Container|null */ - private $container; + private ?Container $container = null; /** * @param array{path?: string} $settings @@ -106,10 +104,9 @@ public function getContainer(): Container } /** - * @return object * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint */ - public function grabService(string $service) + public function grabService(string $service): object { try { /** @phpstan-var class-string $service */ @@ -164,13 +161,11 @@ private function createContainer(): void } } - private function getTempDir(): string { return $this->path . '/' . $this->config['tempDir']; } - private function clearTempDir(): void { $this->deleteTempDir(); @@ -179,7 +174,6 @@ private function clearTempDir(): void FileSystem::createDir($tempDir); } - private function deleteTempDir(): void { $tempDir = $this->getTempDir(); @@ -188,7 +182,6 @@ private function deleteTempDir(): void } } - private function stopContainer(): void { if ($this->container === null) { diff --git a/src/Qa/PhpStan/NetteDIModuleType.php b/src/Qa/PhpStan/NetteDIModuleType.php index 285a085..81e814b 100644 --- a/src/Qa/PhpStan/NetteDIModuleType.php +++ b/src/Qa/PhpStan/NetteDIModuleType.php @@ -28,29 +28,29 @@ public function isMethodSupported(MethodReflection $methodReflection): bool public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type { if ($methodCall->args === []) { - return $methodReflection->getReturnType(); + return $methodReflection->getReturnType(); // @phpstan-ignore-line } $arg = $methodCall->getArgs()[0]->value; if (!$arg instanceof ClassConstFetch) { - return $methodReflection->getReturnType(); + return $methodReflection->getReturnType(); // @phpstan-ignore-line } $class = $arg->class; if (!$class instanceof Name) { - return $methodReflection->getReturnType(); + return $methodReflection->getReturnType(); // @phpstan-ignore-line } $class = (string) $class; if ($class === 'static') { - return $methodReflection->getReturnType(); + return $methodReflection->getReturnType(); // @phpstan-ignore-line } if ($class === 'self') { - $class = $scope->getClassReflection()->getName(); + $class = $scope->getClassReflection()->getName(); // @phpstan-ignore-line } return new ObjectType($class); diff --git a/src/Tracy/Logger.php b/src/Tracy/Logger.php index 1282aca..96de847 100644 --- a/src/Tracy/Logger.php +++ b/src/Tracy/Logger.php @@ -11,7 +11,7 @@ class Logger extends Extension { /** @var string[] */ - public static $events = [ + public static array $events = [ Events::TEST_FAIL => 'testFail', Events::TEST_ERROR => 'testError', ]; @@ -21,9 +21,10 @@ class Logger extends Extension * @param mixed[] $options * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint */ - public function __construct($config, $options) + public function __construct(array $config, array $options) { parent::__construct($config, $options); + Debugger::$logDirectory = $this->getLogDir(); }