Completed
Push — master ( 5195d4...70b5c1 )
by Raphaël
01:37
created
tests/bootstrap.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 if (file_exists(__DIR__.'/../vendor/autoload.php')) {
3 3
     require_once __DIR__.'/../vendor/autoload.php';
4
-} else {
4
+}else {
5 5
     require_once __DIR__.'/../../../../vendor/autoload.php';
6 6
 }
7 7
\ No newline at end of file
Please login to merge, or discard this patch.
src/Services/DetectAppointmentsChangingsService.php 1 patch
Spacing   +28 added lines, -28 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){
30
+        if (!$maxResult) {
31 31
             $maxResult = 999999;
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
-    public static function insertDateTimeChanges(array $appointments,$timestamp){
145
-        foreach ($appointments as $key => $appointment){
144
+    public static function insertDateTimeChanges(array $appointments, $timestamp) {
145
+        foreach ($appointments as $key => $appointment) {
146 146
             $appointments[$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'] = self::insertDateTimeChanges($changesList['updated'],$timestamp);
161
-        $changesList['deleted'] = self::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'] = self::insertDateTimeChanges($changesList['updated'], $timestamp);
161
+        $changesList['deleted'] = self::insertDateTimeChanges($changesList['deleted'], $timestamp);
162 162
         return $changesList;
163 163
     }
164 164
 
Please login to merge, or discard this patch.
tests/Wabel/Services/DetectAppointmentsChangingsServiceTest.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
68 68
 
69 69
     protected function setUp()
70 70
     {
71
-        $certainApiClient =  new CertainApiClient(null,$GLOBALS['username'],$GLOBALS['password'],$GLOBALS['accountCode']);
72
-        $this->certainApiService  = new CertainApiService($certainApiClient);
71
+        $certainApiClient = new CertainApiClient(null, $GLOBALS['username'], $GLOBALS['password'], $GLOBALS['accountCode']);
72
+        $this->certainApiService = new CertainApiService($certainApiClient);
73 73
         $this->appointmentsCertain = new AppointmentsCertain($this->certainApiService);
74
-        $this->certainAppointmentsList = $this->appointmentsCertain->get($GLOBALS['eventCode'],['start_index'=>0,'max_results'=>10])->getResults()->appointments;
74
+        $this->certainAppointmentsList = $this->appointmentsCertain->get($GLOBALS['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
 block discarded – undo
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));
99
-        $this->assertContains($delete1,$changings);
100
-        $this->assertContains($delete2,$changings);
101
-        $this->assertContains($delete3,$changings);
97
+        $changings = $detectService->getListChangings($oldAppointments, $currentAppoiments);
98
+        $this->assertEquals(3, count($changings));
99
+        $this->assertContains($delete1, $changings);
100
+        $this->assertContains($delete2, $changings);
101
+        $this->assertContains($delete3, $changings);
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
 block discarded – undo
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);
118
-        $this->assertEquals(3,count($changings));
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);
118
+        $this->assertEquals(3, count($changings));
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
 block discarded – undo
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
Please login to merge, or discard this patch.
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.