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

Improve HTTP Client structure #1

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

Conversation

mathleite
Copy link
Owner

No description provided.

@mathleite mathleite added the enhancement New feature or request label Mar 27, 2020
@mathleite mathleite self-assigned this Mar 27, 2020
@mathleite mathleite force-pushed the feature/improve-http-client-structure branch 2 times, most recently from f57be43 to b5c653f Compare March 27, 2020 15:07
@mathleite mathleite force-pushed the feature/improve-http-client-structure branch 2 times, most recently from 7deb814 to d537479 Compare March 27, 2020 19:35
@mathleite mathleite force-pushed the feature/improve-http-client-structure branch from d537479 to 129255f Compare March 27, 2020 19:37

use Psr\Http\Message\ResponseInterface;

interface HttpClientAdapterInterface
Copy link

@deenison deenison Apr 1, 2020

Choose a reason for hiding this comment

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

Not sure if Adapter in the name is really necessary - (this is not a change request)

<?php


namespace App\Notification\Client;
Copy link

Choose a reason for hiding this comment

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

It would be more appropriated to have HttpClient instead of just Client as subdomain, because Client alone doesn't mean much, opposed as HttpClient

Copy link

Choose a reason for hiding this comment

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

Otherwise will leave the impression those are NotificationClients instead


final class SlackNotification implements AppNotificationInterface
{
private SlackStylizedMessageCreator $message;
private HTTPClientAdapterInterface $client;
private HttpClientAdapterInterface $client;
Copy link

Choose a reason for hiding this comment

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

Suggested change
private HttpClientAdapterInterface $client;
private HttpClientAdapterInterface $httpClient;


public function __construct(HTTPClientAdapterInterface $client, string $message, string $messageType)
public function __construct(HttpClientAdapterInterface $client, string $message, string $messageType)
Copy link

Choose a reason for hiding this comment

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

Suggested change
public function __construct(HttpClientAdapterInterface $client, string $message, string $messageType)
public function __construct(HttpClientAdapterInterface $httpClient, string $message, string $messageType)

<?php


namespace App\Notification\Client\Guzzle;
Copy link

Choose a reason for hiding this comment

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

Suggested change
namespace App\Notification\Client\Guzzle;
namespace App\Notification\HttpClient\Adapter;

@@ -4,12 +4,12 @@
namespace App\Notification;


use App\Notification\Client\HTTPClientAdapterInterface;
use App\Notification\Client\ResponseAdapterInterface;
use App\Notification\Client\HttpClientAdapterInterface;
Copy link

Choose a reason for hiding this comment

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

This namespace doesn't match the file structure.

Suggested change
use App\Notification\Client\HttpClientAdapterInterface;
use App\Notification\HttpClientAdapterInterface;


final class GuzzleHttpClient implements HttpClientAdapterInterface
{
private Client $client;
Copy link

Choose a reason for hiding this comment

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

Suggested change
private Client $client;
private Client $guzzle;

use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;

final class GuzzleHttpClient implements HttpClientAdapterInterface
Copy link

Choose a reason for hiding this comment

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

It seems at the moment there is no test for this class

@@ -41,6 +41,6 @@
"phpunit/phpunit": "8.5.*"
},
"scripts": {
"tests": "./vendor/bin/phpunit tests --color=always --stop-on-failure",
"tests": "./vendor/bin/phpunit tests --color=always --stop-on-failure"
Copy link

Choose a reason for hiding this comment

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

This change doesn't belong to the main intent of this PR. A more appropriated approach would be to split things up.:

  1. we put this PR on hold
  2. create a PR fixing the issue
  3. Once it got merged, we get back here, rebase and re-send it

<?php


namespace App\Test\Notification\Fake;
Copy link

Choose a reason for hiding this comment

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

It seems Fake is actually a "concrete" application subdomain. This may be very misleading.

An approach to get it clear up, is to have a test-subdomain called Support:

tests/
  app/
    ...  
  support/
    Notification/
      HttpClient/
        Adapter/
          FakeHttpClient.php
    ...

and then pointing it out on composer.json:

"autoload-dev": {
  "psr-4": {
    "App\\Test\\": "tests/app",
    "App\\Test\\Support\\": "tests/support"
  }
}

(perhaps "Test" should be the first term, actually - but this is for another discussion in another time)

@@ -0,0 +1,23 @@
<?php

Copy link

Choose a reason for hiding this comment

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

You need to establish a pattern/consistency regarding the application files structure - tabs vs spaces, how many, blank lines between <?php and namespace statements, etc :)

There a lot of variations it seems.

I'd suggest you take a look on https://editorconfig.org

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

Successfully merging this pull request may close these issues.

2 participants