| 1 |
<?php |
| 2 |
|
| 3 |
namespace QuadLayers\PluginFeedback; |
| 4 |
|
| 5 |
class Client |
| 6 |
{ |
| 7 |
/** @var Collector */ |
| 8 |
private $collector; |
| 9 |
/** @var Validator */ |
| 10 |
private $validator; |
| 11 |
/** @var Request */ |
| 12 |
private $request; |
| 13 |
|
| 14 |
/** |
| 15 |
* Constructor to initialize the client with plugin slug and version. |
| 16 |
* |
| 17 |
* @param string $pluginBasename The plugin slug. |
| 18 |
*/ |
| 19 |
public function __construct( |
| 20 |
string $pluginBasename |
| 21 |
) { |
| 22 |
$this->collector = new Collector($pluginBasename); |
| 23 |
$this->validator = new Validator(); |
| 24 |
$this->request = new Request(); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Sends feedback to the server. |
| 29 |
* |
| 30 |
* @param bool $isAnonymous Determines if the feedback is anonymous. |
| 31 |
* @param string $feedbackReason The reason for the feedback. |
| 32 |
* @param string $feedbackDetails Additional details for the feedback. |
| 33 |
* @return bool True if the feedback was sent successfully, False otherwise. |
| 34 |
*/ |
| 35 |
public function sendFeedback(string $feedbackReason = '', string $feedbackDetails = '', $isAnonymous = false, $hasFeedback = false) : bool |
| 36 |
{ |
| 37 |
// Collect data |
| 38 |
$data = $this->collector->collectData($feedbackReason, $feedbackDetails, $isAnonymous, $hasFeedback); |
| 39 |
|
| 40 |
// Validate data |
| 41 |
if (!$this->validator->validate($data, $isAnonymous)) { |
| 42 |
return false; |
| 43 |
} |
| 44 |
|
| 45 |
// Send data |
| 46 |
return $this->request->send($data); |
| 47 |
} |
| 48 |
} |
| 49 |
|