Completed
Push — master ( 5195d4...70b5c1 )
by Raphaël
01:37
created
src/Commands/DetectAppointmentsChangingCommand.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      * @param CertainListener[] $listeners
48 48
      * @param null $name
49 49
      */
50
-    public function __construct(DetectAppointmentsChangingsService $detectAppointmentsChangingsService,$filePathEventToCheck,$dirPathHistoryAppointments,$fileLockAuthorizeRun, array $listeners=[],$name=null)
50
+    public function __construct(DetectAppointmentsChangingsService $detectAppointmentsChangingsService, $filePathEventToCheck, $dirPathHistoryAppointments, $fileLockAuthorizeRun, array $listeners = [], $name = null)
51 51
     {
52 52
         parent::__construct($name);
53 53
         $this->detectAppointmentsChangingsService = $detectAppointmentsChangingsService;
@@ -73,44 +73,44 @@  discard block
 block discarded – undo
73 73
         $eventCode = null;
74 74
 
75 75
         //Get the EventCode we need to check.
76
-        if($this->filePathEventToCheck && file_exists($this->filePathEventToCheck)){
76
+        if ($this->filePathEventToCheck && file_exists($this->filePathEventToCheck)) {
77 77
             $configurationEventFile = parse_ini_file($this->filePathEventToCheck);
78
-            if(isset($configurationEventFile['eventCode'])){
78
+            if (isset($configurationEventFile['eventCode'])) {
79 79
                 $eventCode = $configurationEventFile['eventCode'];
80 80
             }
81 81
         }
82 82
         //That permits to stop the followings instructions when we are makings changes on Certain.
83
-        if(!file_exists($this->fileLockAuthorizeRun.'/detect_appointments_changes.lock') && $eventCode){
83
+        if (!file_exists($this->fileLockAuthorizeRun.'/detect_appointments_changes.lock') && $eventCode) {
84 84
             $output->writeln('Detect changes - Run.');
85 85
             //Get the online appointments.
86 86
             $appointmentsNewCertain = $this->detectAppointmentsChangingsService->getCurrentAppoiments($eventCode);
87 87
             $appointmentsNew = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($appointmentsNewCertain);
88 88
             //Get the last saved appointments to get old data.
89
-            $appointmentsOldHistoryFilePath = FileChangesHelper::getTheLastAppointmentsSaved($eventCode,$this->dirPathHistoryAppointments);
90
-            if(!$appointmentsOldHistoryFilePath){
89
+            $appointmentsOldHistoryFilePath = FileChangesHelper::getTheLastAppointmentsSaved($eventCode, $this->dirPathHistoryAppointments);
90
+            if (!$appointmentsOldHistoryFilePath) {
91 91
                 //No files so it's the first time we attempt to synchronize.
92 92
                 $appointmentsOld = [];
93
-            }else{
93
+            }else {
94 94
                 //Get the last old appointments data.
95 95
                 $appointmentsOldHistory = FileChangesHelper::getJsonContentFromFile($appointmentsOldHistoryFilePath);
96 96
                 $appointmentsOld = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($appointmentsOldHistory);
97 97
             }
98 98
             //Check if they are changes.
99 99
             $timestamp = time();
100
-            $listChangings = $this->detectAppointmentsChangingsService->detectAppointmentsChangings($appointmentsOld,$appointmentsNew,$timestamp);
101
-            if(!$appointmentsOld || ((isset($listChangings['updated']) && !empty($listChangings['updated']))
102
-                || (isset($listChangings['deleted']) && !empty($listChangings['deleted'])))){
100
+            $listChangings = $this->detectAppointmentsChangingsService->detectAppointmentsChangings($appointmentsOld, $appointmentsNew, $timestamp);
101
+            if (!$appointmentsOld || ((isset($listChangings['updated']) && !empty($listChangings['updated']))
102
+                || (isset($listChangings['deleted']) && !empty($listChangings['deleted'])))) {
103 103
                 //Changes? So we save the new online appointments
104
-                FileChangesHelper::saveAppointmentsFileByHistory($this->dirPathHistoryAppointments.'/appointments_'.$eventCode.'.json',json_encode($appointmentsNew));
104
+                FileChangesHelper::saveAppointmentsFileByHistory($this->dirPathHistoryAppointments.'/appointments_'.$eventCode.'.json', json_encode($appointmentsNew));
105 105
                 $output->writeln('Detect changes - Save Changes');
106
-            }else{
106
+            }else {
107 107
                 $output->writeln('Detect changes - No Changes');
108 108
             }
109
-            foreach ($this->listeners as $listener){
109
+            foreach ($this->listeners as $listener) {
110 110
                 //Run Listener. For instance,Here we can use ChangingsToFileListeners to save the changes in file.
111
-                $listener->run($eventCode,$listChangings);
111
+                $listener->run($eventCode, $listChangings);
112 112
             }
113
-        }else{
113
+        }else {
114 114
             $output->writeln('Detect changes - Stop.');
115 115
         }
116 116
     }
Please login to merge, or discard this patch.