Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.
GitHub stops scheduled action if the code base hasn't been updated for a long period of time.
Bug Description
namespace Foo\Bar;
class MyClass
{
/**
* @template T
* @param class-string<T> $modelClass
* @return T
*/
public function doSomething($modelClass)
{
// do something
}
}
class DependencyTest
{
public function test(): TargetExcludeOrBuildStep
{
return PHPat::rule()
->classes(Selector::namespace('Foo\Bar'))
->canOnlyDependOn()
->classes(
Selector::namespace('Foo\Bar'),
);
}
}
error output:
Line src/Foo/Bar/MyClass.php
------ --------------------------------------------------------------------------------------------------------------------------------
10 Foo\Bar\MyClass should not depend on Foo\Bar\MyClass\T
10 Foo\Bar\MyClass should not depend on Foo\Bar\MyClass\T
but Foo\Bar\MyClass\T
is not an actual class, it's a generic type template. So no error should be reported.
Additional context
@alli83 Thank you for clarification. Could you kindly open a pull-req for it?
This pull-request doesn't seem to fix the targeted issue.
AFAIK, the issue author (@elliotbruneel) would've wanted BackedEnumNormalizer
to throw the PartialDenormalizationException
in case a value not corresponding to the enum is attempted to be de-normalized.
While I understood the following argument of @alli83,
By just trying to collect the error we do not prevent the object from being instantiated. But this action is bound to fail because we already know that the data is not valid (checked by the BackedEnumNormalizer).
BackedEnumNormalizer
can throw the PartialDenormalizationException
as long as the DTO doesn't have the constructor but only state their properties like:
<?php
class SerializerIssueReport extends \PHPUnit\Framework\TestCase
{
public function testCollectErrorsOnEnum()
{
$serializer = new Symfony\Component\Serializer\Serializer(
[
new \Symfony\Component\Serializer\Normalizer\BackedEnumNormalizer(),
new \Symfony\Component\Serializer\Normalizer\ObjectNormalizer(),
],
['json' => new \Symfony\Component\Serializer\Encoder\JsonEncoder()]
);
$this->expectException(\Symfony\Component\Serializer\Exception\PartialDenormalizationException::class);
$serializer->deserialize('{"test": "invalid"}', DummyObject2::class, 'json', [
\Symfony\Component\Serializer\Normalizer\DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true
]);
}
}
// Original one, for this class the pull-req is legit.
class DummyObject {
public function __construct(public TestEnum $test) {}
}
// For this, PartialDenormalizationException can be thrown.
class DummyObject2 {
public TestEnum $test;
}
enum TestEnum: String
{
case Test = "test";
}
PartialDenormalizationException
is preferred to InvalidArgumentException
under the situation we can use it.
Hi, I maintain an unofficial container image of s3s here and keep the latest tag is up-to-date automatically as soon as changes are made in this repository. Please consider to use it. https://hub.docker.com/r/isseim/s3s