@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * Personal Object to test |
30 | 30 | * @return array |
31 | 31 | */ |
32 | - private function personalAppointment(){ |
|
32 | + private function personalAppointment() { |
|
33 | 33 | return [ |
34 | 34 | "appointmentId"=> 52, |
35 | 35 | "startDate"=> "2015-16-07 11:00:00", |
@@ -68,23 +68,23 @@ discard block |
||
68 | 68 | |
69 | 69 | protected function setUp() |
70 | 70 | { |
71 | - $certainApiClient = new CertainApiClient(null,getenv('username'),getenv('password'),getenv('accountCode')); |
|
72 | - $this->certainApiService = new CertainApiService($certainApiClient); |
|
71 | + $certainApiClient = new CertainApiClient(null, getenv('username'), getenv('password'), getenv('accountCode')); |
|
72 | + $this->certainApiService = new CertainApiService($certainApiClient); |
|
73 | 73 | $this->appointmentsCertain = new AppointmentsCertain($this->certainApiService); |
74 | - $this->certainAppointmentsList = $this->appointmentsCertain->get(getenv('eventCode'),['start_index'=>0,'max_results'=>10])->getResults()->appointments; |
|
74 | + $this->certainAppointmentsList = $this->appointmentsCertain->get(getenv('eventCode'), ['start_index'=>0, 'max_results'=>10])->getResults()->appointments; |
|
75 | 75 | } |
76 | 76 | |
77 | - public function testDetectChangings(){ |
|
77 | + public function testDetectChangings() { |
|
78 | 78 | $detectService = new DetectAppointmentsChangingsService($this->appointmentsCertain); |
79 | 79 | $oldAppointments = $this->certainAppointmentsList; |
80 | 80 | $currentAppoiments = $oldAppointments; |
81 | 81 | unset($currentAppoiments[0]); |
82 | 82 | unset($currentAppoiments[1]); |
83 | - $hasChanged = $detectService->hasChanged($oldAppointments,$currentAppoiments); |
|
83 | + $hasChanged = $detectService->hasChanged($oldAppointments, $currentAppoiments); |
|
84 | 84 | $this->assertTrue($hasChanged); |
85 | 85 | } |
86 | 86 | |
87 | - public function testGetListChangings(){ |
|
87 | + public function testGetListChangings() { |
|
88 | 88 | $detectService = new DetectAppointmentsChangingsService($this->appointmentsCertain); |
89 | 89 | $oldAppointments = $this->certainAppointmentsList; |
90 | 90 | $currentAppoiments = $oldAppointments; |
@@ -94,14 +94,14 @@ discard block |
||
94 | 94 | unset($currentAppoiments[0]); |
95 | 95 | unset($currentAppoiments[1]); |
96 | 96 | unset($currentAppoiments[4]); |
97 | - $changings = $detectService->getListChangings($oldAppointments,$currentAppoiments); |
|
98 | - $this->assertEquals(3,count($changings['updated_deleted'])); |
|
99 | - $this->assertContains($delete1,$changings['updated_deleted']); |
|
100 | - $this->assertContains($delete2,$changings['updated_deleted']); |
|
101 | - $this->assertContains($delete3,$changings['updated_deleted']); |
|
97 | + $changings = $detectService->getListChangings($oldAppointments, $currentAppoiments); |
|
98 | + $this->assertEquals(3, count($changings['updated_deleted'])); |
|
99 | + $this->assertContains($delete1, $changings['updated_deleted']); |
|
100 | + $this->assertContains($delete2, $changings['updated_deleted']); |
|
101 | + $this->assertContains($delete3, $changings['updated_deleted']); |
|
102 | 102 | } |
103 | 103 | |
104 | - public function testDetectDeleteOrUpdated(){ |
|
104 | + public function testDetectDeleteOrUpdated() { |
|
105 | 105 | $detectService = new DetectAppointmentsChangingsService($this->appointmentsCertain); |
106 | 106 | $oldAppointments = $this->certainAppointmentsList; |
107 | 107 | $oldAppointments[10] = $this->personalAppointment(); |
@@ -113,19 +113,19 @@ discard block |
||
113 | 113 | $update1 = $currentAppoiments[10]; |
114 | 114 | $currentAppoiments[10]["startDate"] = "2015-17-07 12:00:00"; |
115 | 115 | $currentAppoiments[10]["endDate"] = "2015-17-07 12:30:00"; |
116 | - $changings = $detectService->getListChangings($oldAppointments,$currentAppoiments); |
|
117 | - $listDetected = $detectService->detectDeleteOrUpdated($currentAppoiments,$changings['updated_deleted']); |
|
118 | - $this->assertEquals(3,count($changings['updated_deleted'])); |
|
119 | - $this->assertArrayHasKey('deleted',$listDetected); |
|
120 | - $this->assertArrayHasKey('updated',$listDetected); |
|
121 | - $this->assertEquals(2,count($listDetected['deleted'])); |
|
122 | - $this->assertEquals(1,count($listDetected['updated'])); |
|
123 | - $this->assertContains($delete1,$listDetected['deleted']); |
|
124 | - $this->assertContains($delete2,$listDetected['deleted']); |
|
125 | - $this->assertContains($update1,$listDetected['updated']); |
|
116 | + $changings = $detectService->getListChangings($oldAppointments, $currentAppoiments); |
|
117 | + $listDetected = $detectService->detectDeleteOrUpdated($currentAppoiments, $changings['updated_deleted']); |
|
118 | + $this->assertEquals(3, count($changings['updated_deleted'])); |
|
119 | + $this->assertArrayHasKey('deleted', $listDetected); |
|
120 | + $this->assertArrayHasKey('updated', $listDetected); |
|
121 | + $this->assertEquals(2, count($listDetected['deleted'])); |
|
122 | + $this->assertEquals(1, count($listDetected['updated'])); |
|
123 | + $this->assertContains($delete1, $listDetected['deleted']); |
|
124 | + $this->assertContains($delete2, $listDetected['deleted']); |
|
125 | + $this->assertContains($update1, $listDetected['updated']); |
|
126 | 126 | } |
127 | 127 | |
128 | - public function testDetectAppointmentsChangings(){ |
|
128 | + public function testDetectAppointmentsChangings() { |
|
129 | 129 | $detectService = new DetectAppointmentsChangingsService($this->appointmentsCertain); |
130 | 130 | $oldAppointments = $this->certainAppointmentsList; |
131 | 131 | $oldAppointments[10] = $this->personalAppointment(); |
@@ -141,10 +141,10 @@ discard block |
||
141 | 141 | $update1['dateDetectChanges'] = $time; |
142 | 142 | $currentAppoiments[10]["startDate"] = "2015-17-07 12:00:00"; |
143 | 143 | $currentAppoiments[10]["endDate"] = "2015-17-07 12:30:00"; |
144 | - $listDetected = $detectService->detectAppointmentsChangings($oldAppointments,$currentAppoiments,$time); |
|
145 | - $this->assertContains($delete1,$listDetected['deleted']); |
|
146 | - $this->assertContains($delete2,$listDetected['deleted']); |
|
147 | - $this->assertContains($update1,$listDetected['updated']); |
|
144 | + $listDetected = $detectService->detectAppointmentsChangings($oldAppointments, $currentAppoiments, $time); |
|
145 | + $this->assertContains($delete1, $listDetected['deleted']); |
|
146 | + $this->assertContains($delete2, $listDetected['deleted']); |
|
147 | + $this->assertContains($update1, $listDetected['updated']); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | } |
151 | 151 | \ No newline at end of file |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | - * @param $eventCode |
|
51 | + * @param string $eventCode |
|
52 | 52 | * @param null|int $start |
53 | 53 | * @param null|int $maxResult |
54 | 54 | * @return mixed |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | |
210 | 210 | /** |
211 | 211 | * @param array $appointments |
212 | - * @param $timestamp |
|
212 | + * @param string $timestamp |
|
213 | 213 | * @return array |
214 | 214 | */ |
215 | 215 | public static function insertDateTimeChanges(array $appointments, $timestamp) |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | { |
102 | 102 | if (is_object($object)) { |
103 | 103 | |
104 | - return (array)$object; |
|
104 | + return (array) $object; |
|
105 | 105 | } |
106 | 106 | return $object; |
107 | 107 | } |
@@ -243,15 +243,15 @@ discard block |
||
243 | 243 | } |
244 | 244 | $codeCheckDirectory = FileChangesHelper::checkDirectory($this->dirPathHistoryAppointments); |
245 | 245 | if ($codeCheckDirectory === 'no_directory') { |
246 | - $this->logger->error('Path ' . $this->dirPathHistoryAppointments . ' doesn\'t exists.'); |
|
246 | + $this->logger->error('Path '.$this->dirPathHistoryAppointments.' doesn\'t exists.'); |
|
247 | 247 | return; |
248 | 248 | } |
249 | 249 | if ($codeCheckDirectory === 'not_readable') { |
250 | - $this->logger->error('Path ' . $this->dirPathHistoryAppointments . ' is not readable.'); |
|
250 | + $this->logger->error('Path '.$this->dirPathHistoryAppointments.' is not readable.'); |
|
251 | 251 | return; |
252 | 252 | } |
253 | 253 | if ($codeCheckDirectory === 'not_writable') { |
254 | - $this->logger->error('Path ' . $this->dirPathHistoryAppointments . ' is not writable.'); |
|
254 | + $this->logger->error('Path '.$this->dirPathHistoryAppointments.' is not writable.'); |
|
255 | 255 | return; |
256 | 256 | } |
257 | 257 | $this->lock->acquireLock(); |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | if (!$appointmentsOldHistoryFilePath) { |
266 | 266 | //No files so it's the first time we attempt to synchronize. |
267 | 267 | $appointmentsOld = []; |
268 | - } else { |
|
268 | + }else { |
|
269 | 269 | //Get the last old appointments data. |
270 | 270 | $appointmentsOldHistory = FileChangesHelper::getJsonContentFromFile($appointmentsOldHistoryFilePath); |
271 | 271 | $appointmentsOld = self::recursiveArrayObjectToFullArray($appointmentsOldHistory); |
@@ -276,9 +276,9 @@ discard block |
||
276 | 276 | if (!$appointmentsOld || ((isset($listChangings['updated']) && !empty($listChangings['updated'])) |
277 | 277 | || (isset($listChangings['deleted']) && !empty($listChangings['deleted'])))) { |
278 | 278 | //Changes? So we save the new online appointments |
279 | - FileChangesHelper::saveAppointmentsFileByHistory($this->dirPathHistoryAppointments . '/appointments_' . $eventCode . '.json', json_encode($appointmentsNew)); |
|
279 | + FileChangesHelper::saveAppointmentsFileByHistory($this->dirPathHistoryAppointments.'/appointments_'.$eventCode.'.json', json_encode($appointmentsNew)); |
|
280 | 280 | $this->logger->info('Detect changes - Save Changes'); |
281 | - } else { |
|
281 | + }else { |
|
282 | 282 | $this->logger->info('Detect changes - No Changes'); |
283 | 283 | } |
284 | 284 | foreach ($this->listeners as $listener) { |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | * @param $dirPath |
11 | 11 | * @return bool |
12 | 12 | */ |
13 | - public static function createDirectory($dirPath){ |
|
14 | - if(!file_exists($dirPath)){ |
|
13 | + public static function createDirectory($dirPath) { |
|
14 | + if (!file_exists($dirPath)) { |
|
15 | 15 | return mkdir($dirPath, 0775, true, null); |
16 | 16 | } |
17 | 17 | return false; |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param string $msg |
24 | 24 | * @return void |
25 | 25 | */ |
26 | - public static function writeFile($path,$msg){ |
|
26 | + public static function writeFile($path, $msg) { |
|
27 | 27 | $f = fopen($path, "w+"); |
28 | 28 | fwrite($f, $msg); |
29 | 29 | fclose($f); |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | * @param string $contents |
43 | 43 | * @return void |
44 | 44 | */ |
45 | - public static function saveAppointmentsFileByHistory($filePath,$contents){ |
|
45 | + public static function saveAppointmentsFileByHistory($filePath, $contents) { |
|
46 | 46 | $time = time(); |
47 | 47 | $file = pathinfo($filePath); |
48 | 48 | $fileNamebase = $file['filename']; |
49 | 49 | $filePath = $file['dirname'].'/'.$fileNamebase.'_'.$time.'.json'; |
50 | - if(!file_exists($filePath)){ |
|
51 | - self::writeFile($filePath,''); |
|
50 | + if (!file_exists($filePath)) { |
|
51 | + self::writeFile($filePath, ''); |
|
52 | 52 | } |
53 | - self::writeFile($filePath,$contents); |
|
53 | + self::writeFile($filePath, $contents); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | * @param $path |
59 | 59 | * @return string |
60 | 60 | */ |
61 | - public static function getContentFile($path){ |
|
62 | - if(!file_exists($path)){ |
|
63 | - self::writeFile($path,''); |
|
61 | + public static function getContentFile($path) { |
|
62 | + if (!file_exists($path)) { |
|
63 | + self::writeFile($path, ''); |
|
64 | 64 | } |
65 | 65 | $handle = fopen($path, "rb"); |
66 | 66 | if (FALSE === $handle) { |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param string $path |
80 | 80 | * @return mixed |
81 | 81 | */ |
82 | - public static function getJsonContentFromFile($path){ |
|
82 | + public static function getJsonContentFromFile($path) { |
|
83 | 83 | $contents = self::getContentFile($path); |
84 | 84 | return json_decode($contents, true); |
85 | 85 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param string $pathDir |
91 | 91 | * @return array |
92 | 92 | */ |
93 | - public static function getFilesListHistoryAppointmentsByEventCode($eventCode,$pathDir){ |
|
93 | + public static function getFilesListHistoryAppointmentsByEventCode($eventCode, $pathDir) { |
|
94 | 94 | $fileList = array(); |
95 | 95 | $files = glob($pathDir.'/appointments_'.$eventCode.'_*.json'); |
96 | 96 | foreach ($files as $file) { |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | * @param string $pathDir |
108 | 108 | * @return string |
109 | 109 | */ |
110 | - public static function getTheLastAppointmentsSaved($eventCode,$pathDir){ |
|
111 | - $fileList = self::getFilesListHistoryAppointmentsByEventCode($eventCode,$pathDir); |
|
110 | + public static function getTheLastAppointmentsSaved($eventCode, $pathDir) { |
|
111 | + $fileList = self::getFilesListHistoryAppointmentsByEventCode($eventCode, $pathDir); |
|
112 | 112 | return array_shift($fileList); |
113 | 113 | } |
114 | 114 | |
@@ -128,20 +128,20 @@ discard block |
||
128 | 128 | |
129 | 129 | public static function commandIsLocked(string $pathDir): bool |
130 | 130 | { |
131 | - return file_exists($pathDir. '/command.lock'); |
|
131 | + return file_exists($pathDir.'/command.lock'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | public static function lockCommand(string $pathDir): void |
135 | 135 | { |
136 | 136 | if (!self::commandIsLocked($pathDir)) { |
137 | - self::writeFile($pathDir. '/command.lock','1'); |
|
137 | + self::writeFile($pathDir.'/command.lock', '1'); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
141 | 141 | public static function unlockCommand(string $pathDir): void |
142 | 142 | { |
143 | 143 | if (self::commandIsLocked($pathDir)) { |
144 | - self::removeFile($pathDir. '/command.lock'); |
|
144 | + self::removeFile($pathDir.'/command.lock'); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | } |
148 | 148 | \ No newline at end of file |