Completed
Push — master ( ce12a2...461a38 )
by Raphaël
01:36
created
src/Services/DetectAppointmentsChangingsService.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
      * @param null|int $maxResult
24 24
      * @return mixed
25 25
      */
26
-    public function getCurrentAppoiments($eventCode,$start=null,$maxResult=null){
27
-        if(!$start){
26
+    public function getCurrentAppoiments($eventCode, $start = null, $maxResult = null) {
27
+        if (!$start) {
28 28
             $start = 0;
29 29
         }
30
-        if(!$maxResult){
31
-            $maxResult = $this->appointmentsCertain->get($eventCode,['start_index'=>0,'max_results'=>99999])->getMaxResults();
30
+        if (!$maxResult) {
31
+            $maxResult = $this->appointmentsCertain->get($eventCode, ['start_index'=>0, 'max_results'=>99999])->getMaxResults();
32 32
         }
33
-        return $this->certainAppointmentsList = $this->appointmentsCertain->get($eventCode,['start_index'=>$start,'max_results'=>$maxResult])->getResults()->appointments;
33
+        return $this->certainAppointmentsList = $this->appointmentsCertain->get($eventCode, ['start_index'=>$start, 'max_results'=>$maxResult])->getResults()->appointments;
34 34
     }
35 35
 
36 36
     /**
@@ -38,12 +38,12 @@  discard block
 block discarded – undo
38 38
      * @param array $appointmentsNew
39 39
      * @return bool
40 40
      */
41
-    public function hasChanged(array $appointmentsOld,array $appointmentsNew){
41
+    public function hasChanged(array $appointmentsOld, array $appointmentsNew) {
42 42
         $hasChanged = false;
43 43
         $appointmentsOld = self::recursiveArrayObjectToFullArray($appointmentsOld);
44 44
         $appointmentsNew = self::recursiveArrayObjectToFullArray($appointmentsNew);
45
-        foreach ($appointmentsOld as $appointmentOld){
46
-            if(!in_array($appointmentOld,$appointmentsNew)){
45
+        foreach ($appointmentsOld as $appointmentOld) {
46
+            if (!in_array($appointmentOld, $appointmentsNew)) {
47 47
                 $hasChanged = true;
48 48
                 break;
49 49
             }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      * @return array
57 57
      */
58 58
     public static  function objectToArray($object) {
59
-        if(is_object($object)){
59
+        if (is_object($object)) {
60 60
 
61 61
             return (array) $object;
62 62
         }
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      * @param $appointments
68 68
      * @return array
69 69
      */
70
-    public static function recursiveArrayObjectToFullArray($appointments){
70
+    public static function recursiveArrayObjectToFullArray($appointments) {
71 71
         return json_decode(json_encode($appointments), true);
72 72
     }
73 73
 
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
      */
79 79
     private function arrayRecursiveDiff(array $arrayOlds, array $arrayNews) {
80 80
         $difference = [];
81
-        foreach($arrayOlds as $key => $arrayOld){
82
-            if(!in_array($arrayOld,$arrayNews)){
81
+        foreach ($arrayOlds as $key => $arrayOld) {
82
+            if (!in_array($arrayOld, $arrayNews)) {
83 83
                 $difference[$key] = $arrayOld;
84 84
             }
85 85
         }
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
      * @param array $appointmentsNew
92 92
      * @return array
93 93
      */
94
-    public function getListChangings(array $appointmentsOld,array $appointmentsNew){
94
+    public function getListChangings(array $appointmentsOld, array $appointmentsNew) {
95 95
         $appointmentsOld = self::recursiveArrayObjectToFullArray($appointmentsOld);
96 96
         $appointmentsNew = self::recursiveArrayObjectToFullArray($appointmentsNew);
97 97
         $changesList = [];
98
-        if($this->hasChanged($appointmentsOld,$appointmentsNew)){
99
-            $changesList = self::recursiveArrayObjectToFullArray($this->arrayRecursiveDiff($appointmentsOld,$appointmentsNew));
98
+        if ($this->hasChanged($appointmentsOld, $appointmentsNew)) {
99
+            $changesList = self::recursiveArrayObjectToFullArray($this->arrayRecursiveDiff($appointmentsOld, $appointmentsNew));
100 100
         }
101 101
         return $changesList;
102 102
     }
@@ -107,26 +107,26 @@  discard block
 block discarded – undo
107 107
      * @param array $changingsDetected
108 108
      * @return array ['deleted'=>[],'updated'=>[]]
109 109
      */
110
-    public function detectDeleteOrUpdated(array $currentAppointments,array $changingsDetected){
110
+    public function detectDeleteOrUpdated(array $currentAppointments, array $changingsDetected) {
111 111
         $delete = [];
112 112
         $update = [];
113 113
         //@Todo: Detect Fields has changed
114 114
         $appointmentsNew = self::recursiveArrayObjectToFullArray($currentAppointments);
115 115
         $changings = self::recursiveArrayObjectToFullArray($changingsDetected);
116
-        foreach ($changings as $changing){
116
+        foreach ($changings as $changing) {
117 117
             $registration = $changing['registration']['regCode'];
118 118
             $registrationTarget = $changing['targetRegistration']['regCode'];
119
-            foreach ($appointmentsNew as $currentAppointment){
119
+            foreach ($appointmentsNew as $currentAppointment) {
120 120
                 $registrationCurrent = $currentAppointment['registration']['regCode'];
121 121
                 $registrationTargetCurrent = $currentAppointment['targetRegistration']['regCode'];
122
-                if(in_array($registration,[$registrationCurrent,$registrationTargetCurrent])
123
-                    && in_array($registrationTarget,[$registrationCurrent,$registrationTargetCurrent])
124
-                    && !in_array($changing,$update) && !in_array($changing,$delete)) {
122
+                if (in_array($registration, [$registrationCurrent, $registrationTargetCurrent])
123
+                    && in_array($registrationTarget, [$registrationCurrent, $registrationTargetCurrent])
124
+                    && !in_array($changing, $update) && !in_array($changing, $delete)) {
125 125
                     $update[] = $changing;
126 126
                     break;
127 127
                 }
128 128
             }
129
-            if(!in_array($changing,$update) && !in_array($changing,$delete)){
129
+            if (!in_array($changing, $update) && !in_array($changing, $delete)) {
130 130
                 $delete[] = $changing;
131 131
             }
132 132
         }
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
      * @param $timestamp
142 142
      * @return array
143 143
      */
144
-    private function insertDateTimeChanges(array $appointments,$timestamp){
145
-        foreach ($appointments as $key => $appointment){
144
+    private function insertDateTimeChanges(array $appointments, $timestamp) {
145
+        foreach ($appointments as $key => $appointment) {
146 146
             $appointment[$key]['dateDetectChanges'] = $timestamp;
147 147
         }
148 148
         return $appointments;
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
      * @param string $timestamp
155 155
      * @return array ['deleted'=>[],'updated'=>[]]
156 156
      */
157
-    public function detectAppointmentsChangings(array $appointmentsOld,array $appointmentsNew,$timestamp){
158
-        $changings = $this->getListChangings($appointmentsOld,$appointmentsNew);
159
-        $changesList = $this->detectDeleteOrUpdated($appointmentsNew,$changings);
160
-        $changesList['updated'] = $this->insertDateTimeChanges($changesList['updated'],$timestamp);
161
-        $changesList['deleted'] = $this->insertDateTimeChanges($changesList['deleted'],$timestamp);
157
+    public function detectAppointmentsChangings(array $appointmentsOld, array $appointmentsNew, $timestamp) {
158
+        $changings = $this->getListChangings($appointmentsOld, $appointmentsNew);
159
+        $changesList = $this->detectDeleteOrUpdated($appointmentsNew, $changings);
160
+        $changesList['updated'] = $this->insertDateTimeChanges($changesList['updated'], $timestamp);
161
+        $changesList['deleted'] = $this->insertDateTimeChanges($changesList['deleted'], $timestamp);
162 162
         return $changesList;
163 163
     }
164 164
 
Please login to merge, or discard this patch.
src/Commands/DetectAppointmentsChangingCommand.php 1 patch
Spacing   +14 added lines, -14 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;
@@ -72,41 +72,41 @@  discard block
 block discarded – undo
72 72
     {
73 73
         $eventCode = null;
74 74
         //Get the EventCode we need to check.
75
-        if($this->filePathEventToCheck && file_exists($this->filePathEventToCheck)){
75
+        if ($this->filePathEventToCheck && file_exists($this->filePathEventToCheck)) {
76 76
             $eventCode = FileChangesHelper::getContentFile($this->filePathEventToCheck);
77 77
         }
78 78
         //That permits to stop the followings instructions when we are makings changes on Certain.
79
-        if(!file_exists($this->fileLockAuthorizeRun.'/detect_appointments_changes.lock') && $eventCode){
79
+        if (!file_exists($this->fileLockAuthorizeRun.'/detect_appointments_changes.lock') && $eventCode) {
80 80
             $output->writeln('Detect changes - Run.');
81 81
             //Get the online appointments.
82 82
             $appointmentsNewCertain = $this->detectAppointmentsChangingsService->getCurrentAppoiments($eventCode);
83 83
             $appointmentsNew = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($appointmentsNewCertain);
84 84
             //Get the last saved appointments to get old data.
85
-            $appointmentsOldHistoryFilePath = FileChangesHelper::getTheLastAppointmentsSaved($eventCode,$this->dirPathHistoryAppointments);
86
-            if(!$appointmentsOldHistoryFilePath){
85
+            $appointmentsOldHistoryFilePath = FileChangesHelper::getTheLastAppointmentsSaved($eventCode, $this->dirPathHistoryAppointments);
86
+            if (!$appointmentsOldHistoryFilePath) {
87 87
                 //No files so it's the first time we attempt to synchronize.
88 88
                 $appointmentsOld = [];
89
-            }else{
89
+            }else {
90 90
                 //Get the last old appointments data.
91 91
                 $appointmentsOldHistory = FileChangesHelper::getJsonContentFromFile($appointmentsOldHistoryFilePath);
92 92
                 $appointmentsOld = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($appointmentsOldHistory);
93 93
             }
94 94
             //Check if they are changes.
95 95
             $timestamp = time();
96
-            $listChangings = $this->detectAppointmentsChangingsService->detectAppointmentsChangings($appointmentsOld,$appointmentsNew,$timestamp);
97
-            if(!$appointmentsOld || ((isset($listChangings['updated']) && !empty($listChangings['updated']))
98
-                || (isset($listChangings['deleted']) && !empty($listChangings['deleted'])))){
96
+            $listChangings = $this->detectAppointmentsChangingsService->detectAppointmentsChangings($appointmentsOld, $appointmentsNew, $timestamp);
97
+            if (!$appointmentsOld || ((isset($listChangings['updated']) && !empty($listChangings['updated']))
98
+                || (isset($listChangings['deleted']) && !empty($listChangings['deleted'])))) {
99 99
                 //Changes? So we save the new online appointments
100
-                FileChangesHelper::saveAppointmentsFileByHistory($this->dirPathHistoryAppointments.'/appointments_'.$eventCode.'.json',json_encode($appointmentsNew));
100
+                FileChangesHelper::saveAppointmentsFileByHistory($this->dirPathHistoryAppointments.'/appointments_'.$eventCode.'.json', json_encode($appointmentsNew));
101 101
                 $output->writeln('Detect changes - Save Changes');
102
-            }else{
102
+            }else {
103 103
                 $output->writeln('Detect changes - No Changes');
104 104
             }
105
-            foreach ($this->listeners as $listener){
105
+            foreach ($this->listeners as $listener) {
106 106
                 //Run Listener. For instance,Here we can use ChangingsToFileListeners to save the changes in file.
107
-                $listener->run($eventCode,$listChangings);
107
+                $listener->run($eventCode, $listChangings);
108 108
             }
109
-        }else{
109
+        }else {
110 110
             $output->writeln('Detect changes - Stop.');
111 111
         }
112 112
     }
Please login to merge, or discard this patch.