Skip to content

Conversation

@se1209
Copy link

@se1209 se1209 commented May 15, 2022

Хотел сделать рефакторинг хотя бы по принципу единой ответственности.
Вынес несколько методов в отдельные классы.
Но потом пришло понимание что делаю что-то не то.
В обшем на этом пока остановился.

*/
public function array2xml(array $array, $xml = false)
{
(false === $xml) and $xml = new \SimpleXMLElement('<root/>');
Copy link

Choose a reason for hiding this comment

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

так делать плохо, используй простой иф, это ухудшает читаемость и понимание кода

public function prepare($data)
{
// Returns array
if ('array' == $this->format) {
Copy link

Choose a reason for hiding this comment

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

Если тут сделать НЕ равно и сразу ретурн то уменьшится вложенность кода

<?php
namespace LisDev\Delivery;

// Вынес из NovaPoshtaApi2.php методы связанные с печатью интернет документов.
Copy link

Choose a reason for hiding this comment

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

Хорошее решение

return $this->printGetLink('printDocument', $documentRefs, $type);
}
// If needs data
return $this->request('InternetDocument', 'printDocument', array('DocumentRefs' => $documentRefs, 'Type' => $type));
Copy link

Choose a reason for hiding this comment

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

У этого класс разве есть такой метод?

$array2xml = new Array2Xml();

// Convert data to neccessary format
$post = 'xml' == $this->format
Copy link

Choose a reason for hiding this comment

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

На самом деле логику преобразования данных в нужный формат стоило вынести в отдельную иерархию абстракций, как раз таки в PrepareReturnData

? $array2xml->array2xml($data)
: json_encode($data);

if ('curl' == $this->getConnectionType()) {
Copy link

Choose a reason for hiding this comment

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

Этому здесь не место. Транспорт нужно выносить отдельно от логики

: json_encode($data);

/*
* Здесь тоже самое, я не понимаю как вынести этот транспорт из метода реквест, чтобы потом в нём использовать.
Copy link

Choose a reason for hiding this comment

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


public function __construct($key, $language = 'ru', $throwErrors = false, ConnectionInterface $connection)

$this->connection->getData();


class CurlConnection implements ConnectionInterface {
// implementation
}

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.

2 participants