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

Adding Rector: Dead Code, Code quality, Coding Style, Type Declarations, Early return #107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

roberto-butti
Copy link
Collaborator

Introducing Rector and updating the code for:

  • Dead Code;
  • Code quality;
  • Coding Style;
  • Type Declarations
  • Early return
  • Updating old PHP code (in order to use at least the PHP 7.3 , at the moment the oldest PHP version supported by Storyblok PHP client)

The configurarion:

->withPhpSets(php73: true)
->withPreparedSets(
deadCode: true,
codeQuality: true,
codingStyle: true,
typeDeclarations: true,
earlyReturn: true

);

Running all tests are still green

Introducting Rector and updating code for the configurarion:

```
    ->withPhpSets(php73: true)
    ->withPreparedSets(
        deadCode: true,
        codeQuality: true,
        codingStyle: true,
        typeDeclarations: true,
        earlyReturn: true

    );
```
$data = (string) $responseObj->getBody();
$jsonResponseData = (array) json_decode($data, true);

// return response data as json if possible, raw if not
$result->httpResponseBody = $data && empty($jsonResponseData) ? $data : $jsonResponseData;
$result->httpResponseBody = $data && [] === $jsonResponseData ? $data : $jsonResponseData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$data && $jsonResponseData === []

@@ -377,39 +362,30 @@ protected function getResponseExceptionMessage(ResponseInterface $responseObj)
{
$body = (string) $responseObj->getBody();
$response = json_decode($body);
if (JSON_ERROR_NONE !== json_last_error()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (json_last_error() !== JSON_ERROR_NONE) {

@@ -32,7 +32,7 @@ public function setBodyFromStreamInterface(StreamInterface $body): self
$data = (string) $body;
$jsonResponseData = (array) json_decode($data, true);
// return response data as json if possible, raw if not
$this->httpResponseBody = $data && empty($jsonResponseData) ? $data : $jsonResponseData;
$this->httpResponseBody = $data && [] === $jsonResponseData ? $data : $jsonResponseData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->httpResponseBody = $data && $jsonResponseData === [] ? $data : $jsonResponseData;

@roberto-butti
Copy link
Collaborator Author

Hi @RicLeP i see your comments, thank you!
So are you suggesting to avoid yoda style, so i can set in the PHP cs fixer configuration :

    'yoda_style' => [
        'always_move_variable' => false,
        'equal' => false,
        'identical' => false,
        'less_and_greater' => false,
    ],

What do you think ?

@RicLeP
Copy link
Contributor

RicLeP commented May 15, 2024

It’s a code style choice so not essential, however I think it’s usually recommended, but go with what you feel it best. :)

@silasjoisten
Copy link
Collaborator

Since PSR-12 its not recommended to use yoda style due to less readability of the code. However i prefer yoda style as well :)

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

Successfully merging this pull request may close these issues.

3 participants