Skip to content

Commit

Permalink
Update packages (#296)
Browse files Browse the repository at this point in the history
This updates packages including the ones that have been locked to particular versions in #278, as a workaround has been added here.

Duplicates mapping config from the main app to the PHPStan Latte extension, again, and adds a check that the config is the same in all files. I'd need to add `unformatPresenterClass()` somewhere somehow if it wasn't the duplicated config. And while that's a copy/pasta, with the test it's acceptable. Partially rolls back #84

 - efabrica/phpstan-latte updated from 0.16.3 to 0.17.0 minor
   See changes: efabrica-team/[email protected]
   Release notes: https://github.com/efabrica-team/phpstan-latte/releases/tag/0.17.0

 - nette/application updated from v3.1.14 to v3.2.1 minor
   See changes: nette/[email protected]
   Release notes: https://github.com/nette/application/releases/tag/v3.2.1

 - nette/forms updated from v3.1.15 to v3.2.1 minor
   See changes: nette/[email protected]
   Release notes: https://github.com/nette/forms/releases/tag/v3.2.1

 - nette/http updated from v3.2.4 to v3.3.0 minor
   See changes: nette/[email protected]
   Release notes: https://github.com/nette/http/releases/tag/v3.3.0

 - php-parallel-lint/php-parallel-lint updated from v1.3.2 to v1.4.0 minor
   See changes: php-parallel-lint/[email protected]
   Release notes: https://github.com/php-parallel-lint/PHP-Parallel-Lint/releases/tag/v1.4.0

 - phpstan/phpstan updated from 1.10.64 to 1.10.66 patch
   See changes: phpstan/[email protected]
   Release notes: https://github.com/phpstan/phpstan/releases/tag/1.10.66

 - roave/security-advisories updated from dev-latest@1054e91 to dev-latest@6900b81
   See changes: Roave/SecurityAdvisories@1054e91...6900b81
  • Loading branch information
spaze authored Mar 31, 2024
2 parents 3e4d305 + b1ffc4c commit b5572a2
Show file tree
Hide file tree
Showing 191 changed files with 3,703 additions and 2,683 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ jobs:
php-version: ${{ matrix.php-version }}
- run: make --directory=site check-makefile

check-application-mapping:
runs-on: ubuntu-latest
strategy:
matrix:
php-version:
- "8.3"
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: ${{ matrix.php-version }}
- run: make --directory=site check-application-mapping

lint-php:
runs-on: ubuntu-latest
strategy:
Expand Down
7 changes: 5 additions & 2 deletions site/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: test audit cs-fix check-file-patterns check-makefile lint-php lint-latte lint-neon lint-xml lint-xml-auto-install phpcs phpstan phpstan-latte-templates phpstan-vendor psalm tester tester-include-skipped gitleaks composer-dependency-analyser
.PHONY: test audit cs-fix check-file-patterns check-makefile check-application-mapping lint-php lint-latte lint-neon lint-xml lint-xml-auto-install phpcs phpstan phpstan-latte-templates phpstan-vendor psalm tester tester-include-skipped gitleaks composer-dependency-analyser

test: audit check-file-patterns check-makefile lint-php lint-latte lint-neon lint-xml phpcs phpstan tester psalm phpstan-vendor composer-dependency-analyser
test: audit check-file-patterns check-makefile check-application-mapping lint-php lint-latte lint-neon lint-xml phpcs phpstan tester psalm phpstan-vendor composer-dependency-analyser

audit:
composer audit
Expand All @@ -14,6 +14,9 @@ check-file-patterns:
check-makefile:
bin/check-makefile.php

check-application-mapping:
bin/check-application-mapping.php

lint-php:
vendor/php-parallel-lint/php-parallel-lint/parallel-lint --colors -e php,phtml,phpt,phpstub app/ public/ stubs/ tests/

Expand Down
4 changes: 3 additions & 1 deletion site/app/Admin/Presenters/SignPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use MichalSpacekCz\Form\UiForm;
use MichalSpacekCz\User\Manager;
use MichalSpacekCz\Www\Presenters\BasePresenter;
use Nette\Http\Session;
use Nette\Security\User;

class SignPresenter extends BasePresenter
Expand All @@ -20,6 +21,7 @@ public function __construct(
private readonly Manager $authenticator,
private readonly SignInFormFactory $signInFormFactory,
private readonly User $user,
private readonly Session $sessionHandler,
) {
parent::__construct();
}
Expand Down Expand Up @@ -47,7 +49,7 @@ public function actionIn(): void
$this->forward('Honeypot:signIn');
}

$this->getSession()->start();
$this->sessionHandler->start();
$token = $this->authenticator->verifyPermanentLogin();
if ($token !== null) {
$this->user->login($this->authenticator->getIdentity($token->getUserId(), $token->getUsername()));
Expand Down
60 changes: 60 additions & 0 deletions site/app/Application/MappingCheck/ApplicationMappingCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
declare(strict_types = 1);

namespace MichalSpacekCz\Application\MappingCheck;

use MichalSpacekCz\Application\MappingCheck\Exceptions\ApplicationMappingMismatchException;
use MichalSpacekCz\Application\MappingCheck\Exceptions\ApplicationMappingMultiplePrimaryFilesException;
use MichalSpacekCz\Application\MappingCheck\Exceptions\ApplicationMappingNoOtherFilesException;
use MichalSpacekCz\Application\MappingCheck\Exceptions\ApplicationMappingNoPrimaryFileException;
use MichalSpacekCz\Application\MappingCheck\Files\ApplicationMappingCheckFile;

readonly class ApplicationMappingCheck
{

/**
* @param list<ApplicationMappingCheckFile> $files
*/
public function __construct(
private array $files,
) {
}


/**
* @return list<string>
* @throws ApplicationMappingMultiplePrimaryFilesException
* @throws ApplicationMappingNoPrimaryFileException
* @throws ApplicationMappingMismatchException
* @throws ApplicationMappingNoOtherFilesException
*/
public function checkFiles(): array
{
$primaryFile = null;
$otherFilenames = $otherFiles = [];
foreach ($this->files as $file) {
if ($file->isPrimaryFile()) {
if ($primaryFile !== null) {
throw new ApplicationMappingMultiplePrimaryFilesException($primaryFile, $file);
}
$primaryFile = $file;
} else {
$otherFilenames[] = $file->getFilename();
$otherFiles[] = $file;
}
}
if ($primaryFile === null) {
throw new ApplicationMappingNoPrimaryFileException($otherFilenames);
}
if ($otherFiles === []) {
throw new ApplicationMappingNoOtherFilesException($primaryFile);
}
foreach ($otherFiles as $file) {
if ($primaryFile->getMapping() !== $file->getMapping()) {
throw new ApplicationMappingMismatchException($primaryFile, $file);
}
}
return array_merge([$primaryFile->getFilename()], $otherFilenames);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types = 1);

namespace MichalSpacekCz\Application\MappingCheck\Exceptions;

use Exception;

abstract class ApplicationMappingException extends Exception
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
declare(strict_types = 1);

namespace MichalSpacekCz\Application\MappingCheck\Exceptions;

use Throwable;

class ApplicationMappingFileNotFoundException extends ApplicationMappingException
{

public function __construct(string $file, ?Throwable $previous = null)
{
parent::__construct("Application mapping file not found: '{$file}'", previous: $previous);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
declare(strict_types = 1);

namespace MichalSpacekCz\Application\MappingCheck\Exceptions;

use Throwable;

class ApplicationMappingInvalidConfigException extends ApplicationMappingException
{

public function __construct(string $file, string $message, ?Throwable $previous = null)
{
parent::__construct("Application mapping config invalid in '{$file}': {$message}", previous: $previous);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
declare(strict_types = 1);

namespace MichalSpacekCz\Application\MappingCheck\Exceptions;

use MichalSpacekCz\Application\MappingCheck\Files\ApplicationMappingCheckFile;
use Throwable;

class ApplicationMappingMismatchException extends ApplicationMappingException
{

public function __construct(ApplicationMappingCheckFile $primary, ApplicationMappingCheckFile $file, ?Throwable $previous = null)
{
$message = sprintf(
"Application mapping in '%s' ('%s') doesn't match the primary mapping in '%s' ('%s')",
$file->getFilename(),
$this->describeMapping($file),
$primary->getFilename(),
$this->describeMapping($primary),
);
parent::__construct($message, previous: $previous);
}


private function describeMapping(ApplicationMappingCheckFile $file): string
{
$result = [];
foreach ($file->getMapping() as $key => $value) {
$result[] = "{$key}: {$value}";
}
return implode('; ', $result);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types = 1);

namespace MichalSpacekCz\Application\MappingCheck\Exceptions;

use MichalSpacekCz\Application\MappingCheck\Files\ApplicationMappingCheckFile;
use Throwable;

class ApplicationMappingMultiplePrimaryFilesException extends ApplicationMappingException
{

public function __construct(ApplicationMappingCheckFile $primary, ApplicationMappingCheckFile $other, ?Throwable $previous = null)
{
parent::__construct("Application mapping has multiple primary files: '{$primary->getFilename()}' & '{$other->getFilename()}'", previous: $previous);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types = 1);

namespace MichalSpacekCz\Application\MappingCheck\Exceptions;

use MichalSpacekCz\Application\MappingCheck\Files\ApplicationMappingCheckFile;
use Throwable;

class ApplicationMappingNoOtherFilesException extends ApplicationMappingException
{

public function __construct(ApplicationMappingCheckFile $file, ?Throwable $previous = null)
{
parent::__construct("No other files with application mapping, just the primary one: '{$file->getFilename()}'", previous: $previous);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
declare(strict_types = 1);

namespace MichalSpacekCz\Application\MappingCheck\Exceptions;

use Throwable;

class ApplicationMappingNoPrimaryFileException extends ApplicationMappingException
{

/**
* @param list<string> $files
*/
public function __construct(array $files, ?Throwable $previous = null)
{
parent::__construct("Application mapping has no primary file: '" . implode("', '", $files) . "'", previous: $previous);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
declare(strict_types = 1);

namespace MichalSpacekCz\Application\MappingCheck\Files;

use MichalSpacekCz\Application\MappingCheck\Exceptions\ApplicationMappingFileNotFoundException;
use MichalSpacekCz\Application\MappingCheck\Exceptions\ApplicationMappingInvalidConfigException;
use MichalSpacekCz\ShouldNotHappenException;
use Nette\Neon\Exception;
use Nette\Neon\Neon;
use Override;

readonly class ApplicationMappingCheckCommonNeon implements ApplicationMappingCheckFile
{

private string $filename;


/**
* @throws ApplicationMappingFileNotFoundException
*/
public function __construct(string $filename)
{
if (!file_exists($filename)) {
throw new ApplicationMappingFileNotFoundException($filename);
}
$realpath = realpath($filename);
$this->filename = $realpath !== false ? $realpath : $filename;
}


#[Override]
public function getFilename(): string
{
return $this->filename;
}


#[Override]
public function isPrimaryFile(): bool
{
return true;
}


/**
* @return array<string, string>
* @throws ApplicationMappingInvalidConfigException
* @throws Exception
*/
#[Override]
public function getMapping(): array
{
$decoded = Neon::decodeFile($this->filename);
if (!is_array($decoded)) {
throw new ApplicationMappingInvalidConfigException($this->filename, "Should be an array, but it's " . get_debug_type($decoded));
}
if (!isset($decoded['application'])) {
throw new ApplicationMappingInvalidConfigException($this->filename, "Missing 'application' key");
}
if (!is_array($decoded['application'])) {
throw new ApplicationMappingInvalidConfigException($this->filename, "The 'application' key should be an array, but it's " . get_debug_type($decoded['application']));
}
if (!isset($decoded['application']['mapping'])) {
throw new ApplicationMappingInvalidConfigException($this->filename, "Missing 'application.mapping' key");
}
if (!is_array($decoded['application']['mapping'])) {
throw new ApplicationMappingInvalidConfigException($this->filename, "The 'application.mapping' should be an array, but it's " . get_debug_type($decoded['application']['mapping']));
}
$mapping = [];
foreach ($decoded['application']['mapping'] as $key => $value) {
if (!is_string($key) || !is_string($value)) {
throw new ShouldNotHappenException(sprintf('Both key and value should be an array, but they are %s => %s', get_debug_type($key), get_debug_type($value)));
}
$mapping[$key] = $value;
}
return $mapping;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
declare(strict_types = 1);

namespace MichalSpacekCz\Application\MappingCheck\Files;

interface ApplicationMappingCheckFile
{

public function getFilename(): string;


public function isPrimaryFile(): bool;


/**
* @return array<string, string>
*/
public function getMapping(): array;

}
Loading

0 comments on commit b5572a2

Please sign in to comment.