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
2 changes: 1 addition & 1 deletion app/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
final class Bootstrap {
public static function boot(): Configurator {
$configurator = new Configurator();
// $configurator->setDebugMode('23.75.345.200'); // enable for your remote IP
// $configurator->setDebugMode('secret@23.75.345.200'); // enable for your remote IP
$configurator->enableTracy(__DIR__ . '/../log');
$configurator->setTimeZone('UTC');
$configurator->setTempDirectory(__DIR__ . '/../temp');
Expand Down
4 changes: 3 additions & 1 deletion app/Components/BootstrapCheckboxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ public function getControl(): Html {

/** @var Html */
$input = Controls\MultiChoiceControl::getControl();
$htmlId = $input->id;
\assert(\is_string($htmlId));
$items = $this->getItems();
$ids = [];
if ($this->generateId) {
foreach ($items as $value => $label) {
$ids[$value] = $input->id . '-' . $value;
$ids[$value] = $htmlId . '-' . $value;
}
}

Expand Down
4 changes: 3 additions & 1 deletion app/Components/BootstrapRadioList.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ public function getControl(): Html {

/** @var Html */
$input = Controls\ChoiceControl::getControl();
$htmlId = $input->id;
\assert(\is_string($htmlId));
$items = $this->getItems();
$ids = [];
if ($this->generateId) {
foreach ($items as $value => $label) {
$ids[$value] = $input->id . '-' . $value;
$ids[$value] = $htmlId . '-' . $value;
}
}

Expand Down
6 changes: 3 additions & 3 deletions app/Components/CategoryEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public function __construct(string $label, Entries $entries, bool $showAll = fal
$categoryGroups = $categoryTree;
$items = array_combine(
array_map(
static fn(CategoryGroup $group) => $group->key,
static fn(CategoryGroup $group): string => $group->key,
$categoryGroups,
),
array_map(
function(CategoryGroup $group) use ($showAll): OptGroup {
$categoryArray = array_combine(
array_map(
static fn(Category $category) => $category->name,
static fn(Category $category): string => $category->name,
$group->categories,
),
array_map(
Expand All @@ -60,7 +60,7 @@ function(CategoryGroup $group) use ($showAll): OptGroup {
$categories = $categoryTree;
$items = array_combine(
array_map(
static fn(Category $category) => $category->name,
static fn(Category $category): string => $category->name,
$categories,
),
array_map(
Expand Down
2 changes: 1 addition & 1 deletion app/Components/ObjectSelectBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct($label = null, ?array $items = null) {
parent::__construct($label, $items);
$this->setOption('type', 'select');
$this
->addCondition(fn() => $this->prompt === false && $this->options && $this->control->size < 2)
->addCondition(fn(): bool => $this->prompt === false && $this->options && $this->control->size < 2)
->addRule(Nette\Forms\Form::FILLED, Nette\Forms\Validator::$messages[self::VALID]);
}

Expand Down
3 changes: 2 additions & 1 deletion app/Components/TeamForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Nette\Forms\Controls\SubmitButton;
use Nette\Forms\Rules;
use Nette\Localization\Translator;
use Nette\Utils\ArrayHash;
use Nette\Utils\Json;
use Nextras\FormComponents\Controls\DateControl;
use stdClass;
Expand Down Expand Up @@ -352,7 +353,7 @@ private function checkCategoryConstraints(self $form, stdClass $data): void {

$categoryField = $form->getComponent('category');
$constraints = $this->entries->categories->allCategories[$data->category]->constraints;
/** @var iterable<iterable<string, mixed>> */
/** @var ArrayHash<ArrayHash<string, mixed>> */
$persons = $data->persons;
foreach ($constraints as $constraint) {
if (!$constraint->admits($persons)) {
Expand Down
12 changes: 6 additions & 6 deletions app/Config/CustomInvoiceModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function modify(Team $team, Invoice $invoice, Entries $entries): v

$data = $team->getJsonData();
if ($data->friday2h === 'yes' && $data->saturday5h === 'yes' && $data->sunday4h === 'yes') {
$invoice->addItem('all_stages_discount', $invoice->items['team:enum:friday2h:yes']->price->multiply(-1));
$invoice->addItem('all_stages_discount', $invoice->items['team:enum:friday2h:yes']->getPrice()->multiply(-1));
}

self::fixPersonItemAmounts($invoice, \count($team->persons));
Expand Down Expand Up @@ -49,25 +49,25 @@ private static function fixPersonItemAmounts(Invoice $invoice, int $personCount)
$items = $invoice->items;

if (isset($items['team:enum:friday2h:yes'])) {
$items['team:enum:friday2h:yes'] = $items['team:enum:friday2h:yes']->setAmount($personCount);
$items['team:enum:friday2h:yes'] = $items['team:enum:friday2h:yes']->withAmount($personCount);
}

if (isset($items['team:enum:saturday5h:yes'])) {
$items['team:enum:saturday5h:yes'] = $items['team:enum:saturday5h:yes']->setAmount($personCount);
$items['team:enum:saturday5h:yes'] = $items['team:enum:saturday5h:yes']->withAmount($personCount);
}

if (isset($items['team:enum:sunday4h:yes'])) {
$items['team:enum:sunday4h:yes'] = $items['team:enum:sunday4h:yes']->setAmount($personCount);
$items['team:enum:sunday4h:yes'] = $items['team:enum:sunday4h:yes']->withAmount($personCount);
}

if (isset($items['all_stages_discount'])) {
$items['all_stages_discount'] = $items['all_stages_discount']->setAmount($personCount);
$items['all_stages_discount'] = $items['all_stages_discount']->withAmount($personCount);
}

$invoice->items = $items;
}

private static function discount(InvoiceItem $item, int $discount): InvoiceItem {
return $item->setPrice($item->price->subtract(Money::CZK($discount * 100))); // price in halíř
return $item->withPrice($item->getPrice()->subtract(Money::CZK($discount * 100))); // price in halíř
}
}
12 changes: 6 additions & 6 deletions app/Config/common.neon
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ di:
- Contributte\Translation\LocalesResolvers\Session
- Nette\Localization\Translator

latte:
strictTypes: true
strictParsing: true
extensions:
- App\Templates\Accessory\LatteExtension

session:
autoStart: yes
expiration: 31 days
Expand Down Expand Up @@ -66,12 +72,6 @@ services:
- App\Templates\Filters\PriceFilter
- App\Templates\Filters\WrapInParagraphsFilter
exchange: Money\Exchange\FixedExchange([])
nette.latteFactory:
setup:
- addFilter(categoryFormat, @App\Templates\Filters\CategoryFormatFilter)
- addFilter(exchangeCurrency, @App\Templates\Filters\CurrencyExchangeFilter)
- addFilter(price, @App\Templates\Filters\PriceFilter)
- addFilter(wrapInParagraphs, @App\Templates\Filters\WrapInParagraphsFilter)

translation:
translatorFactory: App\Locale\Translator
Expand Down
3 changes: 0 additions & 3 deletions app/Forms/FormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

namespace App\Forms;

use Nette;
use Nette\Application\UI\Form;
use Nette\Localization\Translator;
use Nextras\FormsRendering\Renderers\Bs5FormRenderer;
use Nextras\FormsRendering\Renderers\FormLayout;

final class FormFactory {
use Nette\SmartObject;

public function __construct(
private readonly Translator $translator,
) {
Expand Down
5 changes: 1 addition & 4 deletions app/Forms/TeamFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@

use App\Components\TeamForm;
use App\Model\Configuration\Entries;
use Nette;
use Nette\Localization\Translator;
use Nextras\FormsRendering\Renderers\Bs5FormRenderer;

final class TeamFormFactory {
use Nette\SmartObject;

public function __construct(
private readonly Translator $translator,
private readonly Entries $entries,
Expand Down Expand Up @@ -41,7 +38,7 @@ public function create(
$form->setTranslator($this->translator);
$renderer = new Bs5FormRenderer();
// We need the class to know what to hide (e.g. for applicableCategories).
$renderer->wrappers['pair']['container'] = preg_replace('(class=")', '$0form-group ', $renderer->wrappers['pair']['container']);
$renderer->wrappers['pair']['container'] = preg_replace('(class=")', '$0form-group ', (string) $renderer->wrappers['pair']['container']);
$form->setRenderer($renderer);

return $form;
Expand Down
4 changes: 2 additions & 2 deletions app/Model/Configuration/CategoryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function from(
$groups = $categories;

$categoryGroups = array_map(
fn(string $groupKey, array $group) => CategoryGroup::from(
fn(string $groupKey, array $group): CategoryGroup => CategoryGroup::from(
$groupKey,
Helpers::parseLabel("category group #{$groupKey}", $group, $allLocales),
$group,
Expand All @@ -88,7 +88,7 @@ public static function from(
);
} else {
$categoriesData = array_map(
fn(string $categoryKey, array $category) => Category::from(
fn(string $categoryKey, array $category): Category => Category::from(
$categoryKey,
$category,
$fees,
Expand Down
2 changes: 1 addition & 1 deletion app/Model/Configuration/CategoryGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function from(
$categoriesRaw = $group['categories'];

$categories = array_map(
fn(string $categoryKey, array $category) => Category::from(
fn(string $categoryKey, array $category): Category => Category::from(
$categoryKey,
$category,
$fees,
Expand Down
5 changes: 5 additions & 0 deletions app/Model/Configuration/Constraints/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

namespace App\Model\Configuration\Constraints;

use ArrayAccess;

interface Constraint {
/**
* @param iterable<ArrayAccess<string, mixed>> $members
*/
public function admits(iterable $members): bool;

public function getErrorMessage(): string;
Expand Down
2 changes: 1 addition & 1 deletion app/Model/Configuration/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static function makeItems(
return array_combine(
array_keys($items),
array_map(
function(string $name, mixed $item) use ($allLocales, $context, $disabled, $fallbackFee, $fees, $limitName) {
function(string $name, mixed $item) use ($allLocales, $context, $disabled, $fallbackFee, $fees, $limitName): Fields\Item {
if (!\is_array($item)) {
throw new InvalidConfigurationException("Item {$name} inside {$context} must be an array.");
}
Expand Down
8 changes: 4 additions & 4 deletions app/Model/Orm/Invoice/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @property string $status {default self::STATUS_NEW} {enum self::STATUS_*}
* @property DateTimeImmutable $timestamp {default now}
* @property Team $team {m:1 Team::$invoices}
* @property array $items
* @property InvoiceItem[] $items
*
* @phpstan-property self::STATUS_* $status
*/
Expand All @@ -30,7 +30,7 @@ public function createItem(string $name, Money $price): self {
$items = $this->items;

if (isset($items[$name])) {
$existingPrice = $items[$name]->price;
$existingPrice = $items[$name]->getPrice();
if (!$price->equals($existingPrice)) {
throw new Exception("This invoice item “{$name}” already exists with a different price.");
}
Expand All @@ -56,7 +56,7 @@ public function addItem(string $name, ?Money $price = null): self {
throw new Exception("Invoice item “{$name}” was not defined.");
}

$items[$name] = $items[$name]->addAmount(1);
$items[$name] = $items[$name]->withAmountAdded(1);

$this->items = $items;

Expand All @@ -80,7 +80,7 @@ public function getTotal(?array $filter = null): Money {
return Money::sum(
...array_values(
array_map(
fn(InvoiceItem $item): Money => $item->price->multiply($item->amount),
fn(InvoiceItem $item): Money => $item->getPrice()->multiply($item->getAmount()),
$relevantItems
)
)
Expand Down
21 changes: 7 additions & 14 deletions app/Model/Orm/Invoice/InvoiceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@

use JsonSerializable;
use Money\Money;
use Nette;

/**
* Immutable invoice item.
*
* @property string $name
* @property Money $price
* @property int $amount
*/
final class InvoiceItem implements JsonSerializable {
use Nette\SmartObject;

public function __construct(
private readonly string $name,
private readonly Money $price,
Expand All @@ -37,23 +30,23 @@ public function getAmount(): int {
return $this->amount;
}

public function setPrice(Money $price): self {
public function withPrice(Money $price): self {
return new self($this->name, $price, $this->amount);
}

public function setAmount(int $amount): self {
public function withAmount(int $amount): self {
return new self($this->name, $this->price, $amount);
}

public function addAmount(int $amount): self {
return $this->setAmount($this->amount + $amount);
public function withAmountAdded(int $amount): self {
return $this->withAmount($this->amount + $amount);
}

public function jsonSerialize(): array {
return [
'name' => $this->name,
'price' => $this->price,
'amount' => $this->amount,
'name' => $this->getName(),
'price' => $this->getPrice(),
'amount' => $this->getAmount(),
];
}
}
2 changes: 0 additions & 2 deletions app/Model/TeamManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
use Nette\Security\SimpleIdentity;

final class TeamManager implements Nette\Security\Authenticator {
use Nette\SmartObject;

public const ENTRY_WITHDRAWN = 317806432;

public function __construct(
Expand Down
4 changes: 2 additions & 2 deletions app/Presenters/CommunicationPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function composeFormPreview(SubmitButton $button): void {
/** @var array */ // actually \ArrayAccess but PHPStan does not handle that very well.
$values = $form->getValues();

$teamsIds = explode(',', $values['recipients']);
$teamsIds = explode(',', (string) $values['recipients']);
$teamsIds = array_map(
trim(...),
$teamsIds,
Expand Down Expand Up @@ -181,7 +181,7 @@ private function composeFormEnqueue(SubmitButton $button): void {
$values = $form->getValues();
$subject = $values['subject'];

$teamsIds = explode(',', $values['recipients']);
$teamsIds = explode(',', (string) $values['recipients']);
$teamsIds = array_map(
trim(...),
$teamsIds,
Expand Down
15 changes: 10 additions & 5 deletions app/Presenters/Error4xxPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@
use Nette;

/**
* Handles 4xx HTTP error responses.
*
* @property Nette\Application\UI\Template $template
*/
final class Error4xxPresenter extends BasePresenter {
public function startup(): void {
parent::startup();
protected function checkHttpMethod(): void {
// allow access via all HTTP methods and ensure the request is a forward (internal redirect)
if ($this->getRequest() === null || !$this->getRequest()->isMethod(Nette\Application\Request::FORWARD)) {
$this->error();
}
}

public function renderDefault(Nette\Application\BadRequestException $exception): void {
// load template 403.latte or 404.latte or ... 4xx.latte
$file = __DIR__ . "/../Templates/Error/{$exception->getCode()}.latte";
$file = is_file($file) ? $file : __DIR__ . '/../Templates/Error/4xx.latte';
// renders the appropriate error template based on the HTTP status code
$code = $exception->getCode();
$file = is_file($file = __DIR__ . "/../Templates/Error/$code.latte")
? $file
: __DIR__ . '/../Templates/Error/4xx.latte';
$this->template->httpCode = $code;
$this->template->setFile($file);
}
}
Loading