Conditions | 18 |
Paths | 436 |
Total Lines | 91 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
46 | public function run($request) |
||
47 | { |
||
48 | // Definitions |
||
49 | $default_source_id = Defaults::config()->source_id; |
||
50 | $query = []; |
||
51 | $consumer = Consumer::get()->find('Title', 'OrderUpdate'); // to get modifiedSince |
||
52 | |||
53 | if ($consumer) { |
||
54 | $date = new DateTime($consumer->ExternalLastEdited); |
||
55 | $query['modifiedSince'] = substr($date->format('Y-m-d\TH:i:s.u'), 0, 23); |
||
56 | } |
||
57 | |||
58 | if ($default_source_id) { |
||
59 | $query['sourceId'] = $default_source_id; |
||
60 | } |
||
61 | |||
62 | $response = UnleashedAPI::sendCall( |
||
63 | 'GET', |
||
64 | 'https://api.unleashedsoftware.com/SalesOrders', |
||
65 | ['query' => $query] |
||
66 | ); |
||
67 | |||
68 | if ($response->getStatusCode() == 200) { |
||
69 | $apidata_array = (array) json_decode($response->getBody(), true); |
||
70 | $apidata = $apidata_array['Items']; |
||
71 | $pagination = $apidata_array['Pagination']; |
||
72 | $numberofpages = intval($pagination['NumberOfPages']); |
||
73 | |||
74 | if ($numberofpages > 1) { |
||
75 | for ($i = 2; $i <= $numberofpages; $i++) { |
||
76 | $response = UnleashedAPI::sendCall( |
||
77 | 'GET', |
||
78 | 'https://api.unleashedsoftware.com/SalesOrders/' . $i, |
||
79 | ['query' => $query] |
||
80 | ); |
||
81 | if ($response->getStatusCode() == 200) { |
||
82 | $apidata_array = (array) json_decode($response->getBody(), true); |
||
83 | $apidata = array_merge($apidata, $apidata_array['Items']); |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | $this->log('<h3>Update the OrderStatus in Silvershop</h3>'); |
||
89 | $loader = OrderBulkLoader::create(Order::class); |
||
90 | $loader->transforms = [ |
||
91 | 'Status' => [ |
||
92 | 'callback' => fn($value) => |
||
93 | // convert from Unleashed Sales Order status to Silvershop |
||
94 | $this->order_status_map[$value] |
||
95 | ] |
||
96 | ]; |
||
97 | $results = $loader->updateRecords($apidata, $this->preview); |
||
98 | |||
99 | if ($results->UpdatedCount()) { |
||
100 | $this->log(Debug::text($results->getData())); |
||
101 | } |
||
102 | $this->log("Done"); |
||
103 | |||
104 | // Send email |
||
105 | if ($results->Count() && $this->email_subject && !$this->preview && Email::config()->admin_email) { |
||
106 | $data = $results->getData(); |
||
107 | $email = Email::create( |
||
108 | ShopConfigExtension::config()->email_from ?: Email::config()->admin_email, |
||
109 | Email::config()->admin_email, |
||
110 | $this->email_subject, |
||
111 | Debug::text($data) |
||
112 | ); |
||
113 | |||
114 | $dispatched = true; |
||
115 | try { |
||
116 | $email->send(); |
||
117 | } catch (TransportExceptionInterface $e) { |
||
118 | $dispatched = false; |
||
119 | $this->log("Email not sent: " . $e->getDebug()); |
||
120 | } finally { |
||
121 | if ($dispatched) { |
||
122 | $this->log("Email sent"); |
||
123 | } |
||
124 | } |
||
125 | } |
||
126 | |||
127 | // Create/update Consumer |
||
128 | if (!$this->preview && $apidata) { |
||
129 | if (!$consumer) { |
||
130 | $consumer = Consumer::create([ |
||
131 | 'Title' => 'OrderUpdate', |
||
132 | 'ExternalLastEditedKey' => 'LastModifiedOn' |
||
133 | ]); |
||
134 | } |
||
135 | $consumer->setMaxExternalLastEdited($apidata); |
||
136 | $consumer->write(); |
||
137 | } |
||
141 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths