-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cache warming error on invalid class in transformer's `getSuppor…
…tedTransformation` (#79) * fix: cache warming error on invalid class in transformer's `getSupportedTransformation` * bump psr/log dep
- Loading branch information
Showing
8 changed files
with
253 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/mapper package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\Mapper\Exception; | ||
|
||
class InvalidClassException extends InvalidArgumentException | ||
{ | ||
public function __construct( | ||
private string $class, | ||
int $code = 0, | ||
?\Throwable $previous = null | ||
) { | ||
$message = sprintf('Class "%s" does not exist.', $class); | ||
|
||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
public function getClass(): string | ||
{ | ||
return $this->class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/mapper package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\Mapper\Tests\Fixtures\InvalidTransformer; | ||
|
||
use Rekalogika\Mapper\Context\Context; | ||
use Rekalogika\Mapper\Exception\InvalidArgumentException; | ||
use Rekalogika\Mapper\Transformer\TransformerInterface; | ||
use Rekalogika\Mapper\Transformer\TypeMapping; | ||
use Rekalogika\Mapper\Util\TypeFactory; | ||
use Symfony\Component\PropertyInfo\Type; | ||
|
||
class InvalidTransformer implements TransformerInterface | ||
{ | ||
public function getSupportedTransformation(): iterable | ||
{ | ||
/** | ||
* @psalm-suppress InvalidClass | ||
* @psalm-suppress UndefinedClass | ||
* @psalm-suppress MixedArgument | ||
*/ | ||
yield new TypeMapping( | ||
// @phpstan-ignore-next-line | ||
TypeFactory::objectOfClass(InvalidClass::class), | ||
// @phpstan-ignore-next-line | ||
TypeFactory::objectOfClass(AnotherInvalidClass::class) | ||
); | ||
} | ||
|
||
public function transform( | ||
mixed $source, | ||
mixed $target, | ||
?Type $sourceType, | ||
?Type $targetType, | ||
Context $context | ||
): mixed { | ||
throw new InvalidArgumentException('Should never reach here'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/mapper package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\Mapper\Tests\Service; | ||
|
||
use Psr\Log\LoggerInterface; | ||
|
||
class TestLogger implements LoggerInterface | ||
{ | ||
public function __construct(private LoggerInterface $logger) | ||
{ | ||
} | ||
|
||
private function isSuppressed(string|\Stringable $message): bool | ||
{ | ||
return str_contains((string)$message, 'has a mapping involving an invalid class'); | ||
} | ||
|
||
public function emergency(string|\Stringable $message, array $context = []): void | ||
{ | ||
if (!$this->isSuppressed($message)) { | ||
$this->logger->emergency($message, $context); | ||
} | ||
} | ||
|
||
public function alert(string|\Stringable $message, array $context = []): void | ||
{ | ||
if (!$this->isSuppressed($message)) { | ||
$this->logger->alert($message, $context); | ||
} | ||
} | ||
|
||
public function critical(string|\Stringable $message, array $context = []): void | ||
{ | ||
if (!$this->isSuppressed($message)) { | ||
$this->logger->critical($message, $context); | ||
} | ||
} | ||
|
||
public function error(string|\Stringable $message, array $context = []): void | ||
{ | ||
if (!$this->isSuppressed($message)) { | ||
$this->logger->error($message, $context); | ||
} | ||
} | ||
|
||
public function warning(string|\Stringable $message, array $context = []): void | ||
{ | ||
if (!$this->isSuppressed($message)) { | ||
$this->logger->warning($message, $context); | ||
} | ||
} | ||
|
||
public function notice(string|\Stringable $message, array $context = []): void | ||
{ | ||
if (!$this->isSuppressed($message)) { | ||
$this->logger->notice($message, $context); | ||
} | ||
} | ||
|
||
public function info(string|\Stringable $message, array $context = []): void | ||
{ | ||
if (!$this->isSuppressed($message)) { | ||
$this->logger->info($message, $context); | ||
} | ||
} | ||
|
||
public function debug(string|\Stringable $message, array $context = []): void | ||
{ | ||
if (!$this->isSuppressed($message)) { | ||
$this->logger->debug($message, $context); | ||
} | ||
} | ||
|
||
public function log($level, string|\Stringable $message, array $context = []): void | ||
{ | ||
if (!$this->isSuppressed($message)) { | ||
$this->logger->log($level, $message, $context); | ||
} | ||
} | ||
} |