Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ jobs:
cd ./src
composer install --prefer-dist --no-progress

- name: Run codesniffer
run: make codesniffer

- name: Run phpstan
run: make phpstan
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
.PHONE codesniffer:
codesniffer:
cd ./src && composer codesniffer

.PHONE codesnifferFix:
codesnifferFix:
cd ./src && composer codesnifferFix

.PHONE composerValidate:
composerValidate:
cd ./src && composer validate --strict
Expand All @@ -8,4 +16,4 @@ dockerComposeUp:

.PHONE phpstan:
phpstan:
cd ./src && composer phpstan
cd ./src && composer phpstan
387 changes: 387 additions & 0 deletions phpcs.xml

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
parameters:
checkDynamicProperties: true

checkMissingCallableSignature: true

checkMissingOverrideMethodAttribute: true

checkTooWideReturnTypesInProtectedAndPublicMethods: true

checkUninitializedProperties: true

fileExtensions:
- php
- phpt

level: 5

paths:
- ./src/app
- ./src/www

reportAnyTypeWideningInVarTag: true

reportWrongPhpDocTypeInVarTag: true

strictRules:
allRules: true

universalObjectCratesClasses:
- Dibi\Row

includes:
- ./src/vendor/phpstan/phpstan-deprecation-rules/rules.neon
- ./src/vendor/phpstan/phpstan-dibi/extension.neon
Expand Down
12 changes: 9 additions & 3 deletions src/app/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@
namespace WbAssignment;

use Nette;
use Nette\Bootstrap\Configurator;


class Bootstrap
{
private Configurator $configurator;

private Nette\Bootstrap\Configurator $configurator;

private string $rootDir;



public function __construct()
{
$this->rootDir = dirname(__DIR__);
$this->configurator = new Configurator;
$this->configurator = new Nette\Bootstrap\Configurator();
$this->configurator->setTempDirectory($this->rootDir . '/temp');
}



public function bootWebApplication(): Nette\DI\Container
{
$this->initializeEnvironment();
Expand All @@ -28,6 +31,7 @@ public function bootWebApplication(): Nette\DI\Container
}



public function initializeEnvironment(): void
{
//$this->configurator->setDebugMode('secret@23.75.345.200'); // enable for your remote IP
Expand All @@ -39,10 +43,12 @@ public function initializeEnvironment(): void
}



private function setupContainer(): void
{
$configDir = $this->rootDir . '/config';
$this->configurator->addConfig($configDir . '/common.neon');
$this->configurator->addConfig($configDir . '/services.neon');
}

}
9 changes: 6 additions & 3 deletions src/app/Core/RouterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
namespace WbAssignment\Core;

use Nette;
use Nette\Application\Routers\RouteList;


final class RouterFactory
{

use Nette\StaticClass;

public static function createRouter(): RouteList


public static function createRouter(): Nette\Application\Routers\RouteList
{
$router = new RouteList;
$router = new Nette\Application\Routers\RouteList();
$router->addRoute('<presenter>/<action>[/<id>]', 'Home:default');
return $router;
}

}
5 changes: 3 additions & 2 deletions src/app/Presentation/Error/Error4xx/Error4xxPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
namespace WbAssignment\Presentation\Error\Error4xx;

use Nette;
use Nette\Application\Attributes\Requires;


/**
* Handles 4xx HTTP error responses.
*/
#[Requires(methods: '*', forward: true)]
#[Nette\Application\Attributes\Requires(methods: '*', forward: TRUE)]
final class Error4xxPresenter extends Nette\Application\UI\Presenter
{

public function renderDefault(Nette\Application\BadRequestException $exception): void
{
// renders the appropriate error template based on the HTTP status code
Expand All @@ -22,4 +22,5 @@ public function renderDefault(Nette\Application\BadRequestException $exception):
$this->template->httpCode = $code;
$this->template->setFile($file);
}

}
20 changes: 10 additions & 10 deletions src/app/Presentation/Error/Error5xx/Error5xxPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
namespace WbAssignment\Presentation\Error\Error5xx;

use Nette;
use Nette\Application\Attributes\Requires;
use Nette\Application\Responses;
use Nette\Http;
use Tracy\ILogger;
use Tracy;


/**
* Handles uncaught exceptions and errors, and logs them.
*/
#[Requires(forward: true)]
#[Nette\Application\Attributes\Requires(forward: TRUE)]
final class Error5xxPresenter implements Nette\Application\IPresenter
{

public function __construct(
private ILogger $logger,
) {
}
private Tracy\ILogger $logger,
) {}



#[\Override]
public function run(Nette\Application\Request $request): Nette\Application\Response
{
// Log the exception
$exception = $request->getParameter('exception');
$this->logger->log($exception, ILogger::EXCEPTION);
$this->logger->log($exception, Tracy\ILogger::EXCEPTION);

// Display a generic error message to the user
return new Responses\CallbackResponse(function (Http\IRequest $httpRequest, Http\IResponse $httpResponse): void {
return new Nette\Application\Responses\CallbackResponse(function (Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse): void {
if (preg_match('#^text/html(?:;|$)#', (string) $httpResponse->getHeader('Content-Type'))) {
require __DIR__ . '/500.phtml';
}
});
}

}
1 change: 1 addition & 0 deletions src/app/Presentation/Home/HomePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

final class HomePresenter extends Nette\Application\UI\Presenter
{

}
5 changes: 5 additions & 0 deletions src/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"phpstan/phpstan-dibi": "^2.0",
"phpstan/phpstan-nette": "^2",
"phpstan/phpstan-strict-rules": "^2.0",
"slevomat/coding-standard": "^8.20",
"spaze/phpstan-disallowed-calls": "^4.6",
"squizlabs/php_codesniffer": "^3.13",
"symfony/thanks": "^1"
},
"autoload": {
Expand All @@ -36,13 +38,16 @@
}
},
"scripts": {
"codesniffer": "vendor/bin/phpcs --standard=../phpcs.xml --extensions=php,phpt --colors -p -s ./app",
"codesnifferFix": "vendor/bin/phpcbf --standard=../phpcs.xml --extensions=php,phpt --colors -p -s ./app",
"phpstan": "phpstan analyse -c ../phpstan.neon",
"server": "cd ./www && php -S localhost:8005",
"tester": "tester tests -s"
},
"minimum-stability": "stable",
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"symfony/thanks": true
},
"platform": {
Expand Down
Loading