-
Notifications
You must be signed in to change notification settings - Fork 86
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
Небольшие изменения в класс новой почты #63
base: master
Are you sure you want to change the base?
Conversation
src/Delivery/Array2Xml.php
Outdated
*/ | ||
public function array2xml(array $array, $xml = false) | ||
{ | ||
(false === $xml) and $xml = new \SimpleXMLElement('<root/>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
так делать плохо, используй простой иф, это ухудшает читаемость и понимание кода
src/Delivery/PrepareReturnData.php
Outdated
public function prepare($data) | ||
{ | ||
// Returns array | ||
if ('array' == $this->format) { |
There was a problem hiding this comment.
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 методы связанные с печатью интернет документов. |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
У этого класс разве есть такой метод?
|
||
$prepare = new PrepareReturnData(); | ||
$array2xml = new Array2Xml(); | ||
|
||
// Convert data to neccessary format | ||
$post = 'xml' == $this->format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
На самом деле логику преобразования данных в нужный формат стоило вынести в отдельную иерархию абстракций, как раз таки в PrepareReturnData
// Convert data to neccessary format | ||
$post = 'xml' == $this->format | ||
? $this->array2xml($data) | ||
? $array2xml->array2xml($data) | ||
: json_encode($data); | ||
|
||
if ('curl' == $this->getConnectionType()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Этому здесь не место. Транспорт нужно выносить отдельно от логики
// Convert data to neccessary format | ||
$post = 'xml' == $this->format | ||
? $array2xml->array2xml($data) | ||
: json_encode($data); | ||
|
||
/* | ||
* Здесь тоже самое, я не понимаю как вынести этот транспорт из метода реквест, чтобы потом в нём использовать. |
There was a problem hiding this comment.
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
}
Хотел сделать рефакторинг хотя бы по принципу единой ответственности.
Вынес несколько методов в отдельные классы.
Но потом пришло понимание что делаю что-то не то.
В обшем на этом пока остановился.