Conversation
| case 'integrationToken': | ||
| case 'release': | ||
| case 'url': | ||
| case 'transport': |
There was a problem hiding this comment.
I'd suggest to add a separate case for transport validation to restrict it only for allowed values
There was a problem hiding this comment.
@neSpecc Hawk\Transport::init have validation
public static function init(Options $options)
{
$transports = self::getTransports();
if (!array_key_exists($options->getTransport(), $transports)) {
throw new TransportException('Invalid transport specified');
}
return new $transports[$options->getTransport()]($options);
}
| public static function init(Options $options) | ||
| { | ||
| $transports = self::getTransports(); | ||
|
|
||
| if (!array_key_exists($options->getTransport(), $transports)) { | ||
| throw new TransportException('Invalid transport specified'); | ||
| } | ||
|
|
||
| return new $transports[$options->getTransport()]($options); | ||
| } | ||
|
|
||
| public static function getTransports(): array |
| /** | ||
| * @var string | ||
| */ | ||
| protected $url; | ||
|
|
||
| /** | ||
| * @var int |
There was a problem hiding this comment.
docs are needed not only for typings. Add descriptions: why this property or function is used
|
| * @inheritDoc | ||
| */ | ||
| public function send(Event $event): void | ||
| protected function _send(Event $event): string |
There was a problem hiding this comment.
_send method violates the PSR-12 recommendations.
It is not recommended to add underscores to method names.
| */ | ||
| public static function getTransports(): array | ||
| { | ||
| return [ |
There was a problem hiding this comment.
Using a hardcoded static registry in getTransports violates the Open-Closed Principle (OCP). Adding a new transport requires modifying the base class.
| $response = $this->_send($event); | ||
|
|
||
| try { | ||
| $data = json_decode($response, true); |
There was a problem hiding this comment.
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
...
}
| * | ||
| * @return mixed | ||
| */ | ||
| public function send(Event $event) |
There was a problem hiding this comment.
public function send(Event $event): ?array
Edits:
Hawk\Transport\GuzzleTransportclientHawk\Transport\TransportInterfacetransform toHawk\Transportclassurlandtimeoutfrom child classesHawk\Transport::initfactoryHawk\Options::$transport(curlorguzzle, defaultcurl)Hawk\Exception\TransportExceptiondefaultandcustomHawk\Optionsoptionstimeout,transportHow to pass new options:
PHPUnit results: