Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classes referenced as strings instead of via ::class #760

Open
dkarlovi opened this issue Oct 6, 2023 · 0 comments
Open

Classes referenced as strings instead of via ::class #760

dkarlovi opened this issue Oct 6, 2023 · 0 comments
Labels

Comments

@dkarlovi
Copy link
Contributor

dkarlovi commented Oct 6, 2023

Jane version(s) affected: 7.5.3

Description

The generated code will reference the generated classes in a bunch of places while it would be trivial to make it be the FQCN.

How to reproduce

Generate code and check the code, it will do something like

throw new \App\Infrastructure\Langchain\Exception\PostApiV1ClassifyBadRequestException($serializer->deserialize($body, 'App\\Infrastructure\\Langchain\\Model\\ApiV1ClassifyPostResponse400', 'json'), $response);

all over.

Possible Solution

Use the FQCN.

Additional context

This generates a lot of churn if you're using Rector on your app where it will run StringClassNameToClassConstantRector on everything.

Example

26) src/Infrastructure/Langchain/Endpoint/PostApiV1Classify.php:53

    ---------- begin diff ----------
@@ @@
         $status = $response->getStatusCode();
         $body = (string) $response->getBody();
         if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) {
-            return $serializer->deserialize($body, 'App\\Infrastructure\\Langchain\\Model\\ApiV1ClassifyPostResponse200', 'json');
+            return $serializer->deserialize($body, \App\Infrastructure\Langchain\Model\ApiV1ClassifyPostResponse200::class, 'json');
         }
         if (($contentType === null) === false && ($status === 400 && mb_strpos($contentType, 'application/json') !== false)) {
-            throw new \App\Infrastructure\Langchain\Exception\PostApiV1ClassifyBadRequestException($serializer->deserialize($body, 'App\\Infrastructure\\Langchain\\Model\\ApiV1ClassifyPostResponse400', 'json'), $response);
+            throw new \App\Infrastructure\Langchain\Exception\PostApiV1ClassifyBadRequestException($serializer->deserialize($body, \App\Infrastructure\Langchain\Model\ApiV1ClassifyPostResponse400::class, 'json'), $response);
         }
     }
    ----------- end diff -----------

Applied rules:
 * StringClassNameToClassConstantRector (https://wiki.php.net/rfc/class_name_scalars https://github.com/symfony/symfony/blob/2.8/UPGRADE-2.8.md#form)

The difference is trivial and could easily be done by Jane itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant