Release 2.36.0 (#5514)

This commit is contained in:
Kevin Papst
2025-06-02 16:07:48 +02:00
committed by GitHub
parent 594385f741
commit 2f2ebd6293
27 changed files with 466 additions and 257 deletions

View File

@@ -0,0 +1,26 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Validator\Constraints;
final class TimesheetNegativeDuration extends TimesheetConstraint
{
public const NEGATIVE_DURATION_ERROR = 'kimai-timesheet-negative-duration-01';
protected const ERROR_NAMES = [
self::NEGATIVE_DURATION_ERROR => 'Duration cannot be negative.',
];
public string $message = 'Duration cannot be negative.';
public function getTargets(): string
{
return self::CLASS_CONSTRAINT;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Validator\Constraints;
use App\Entity\Timesheet as TimesheetEntity;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
final class TimesheetNegativeDurationValidator extends ConstraintValidator
{
public function validate(mixed $value, Constraint $constraint): void
{
if (!($constraint instanceof TimesheetNegativeDuration)) {
throw new UnexpectedTypeException($constraint, TimesheetNegativeDuration::class);
}
if (!\is_object($value) || !($value instanceof TimesheetEntity)) {
throw new UnexpectedTypeException($value, TimesheetEntity::class);
}
if ($value->isRunning()) {
return;
}
$duration = $value->getCalculatedDuration();
if ($duration !== null && $duration < 0) {
$this->context->buildViolation($constraint->message)
->atPath('duration')
->setTranslationDomain('validators')
->setCode(TimesheetNegativeDuration::NEGATIVE_DURATION_ERROR)
->addViolation();
}
}
}

View File

@@ -44,7 +44,7 @@ final class TimesheetZeroDurationValidator extends ConstraintValidator
$duration = $value->getCalculatedDuration();
}
if ($duration <= 0) {
if ($duration === 0) {
$this->context->buildViolation($constraint->message)
->atPath('duration')
->setTranslationDomain('validators')

View File

@@ -14,7 +14,7 @@ final class ValidationException extends \RuntimeException
public function __construct(string $message = null)
{
if ($message === null) {
$message = 'Validation failed';
$message = 'Validation Failed';
}
parent::__construct($message, 400);
}

View File

@@ -13,10 +13,10 @@ use Symfony\Component\Validator\ConstraintViolationListInterface;
final class ValidationFailedException extends \RuntimeException
{
public function __construct(private ConstraintViolationListInterface $violations, ?string $message = null)
public function __construct(private readonly ConstraintViolationListInterface $violations, ?string $message = null)
{
if ($message === null) {
$message = 'Validation failed';
$message = 'Validation Failed';
}
parent::__construct($message, 400);
}