Completed
Pull Request — master (#10)
by claudio
04:00
created
app/Console/Commands/SyncCaldav/Sync.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
     }
65 65
 
66 66
     /**
67
-     * @return array|\it\thecsea\caldav_client_adapter\EventInterface[]
67
+     * @return EventInterface[]
68 68
      * @throws \it\thecsea\caldav_client_adapter\CaldavException
69 69
      * @thorws \Illuminate\Contracts\Encryption\DecryptException
70 70
      */
Please login to merge, or discard this patch.
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Created by PhpStorm.
4
- * User: Claudio Cardinale <[email protected]>
5
- * Date: 03/12/15
6
- * Time: 2.33
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License
9
- * as published by the Free Software Foundation; either version 2
10
- * of the License, or (at your option) any later version.
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, write to the Free Software
17
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
- */
3
+     * Created by PhpStorm.
4
+     * User: Claudio Cardinale <[email protected]>
5
+     * Date: 03/12/15
6
+     * Time: 2.33
7
+     * This program is free software; you can redistribute it and/or
8
+     * modify it under the terms of the GNU General Public License
9
+     * as published by the Free Software Foundation; either version 2
10
+     * of the License, or (at your option) any later version.
11
+     * This program is distributed in the hope that it will be useful,
12
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+     * GNU General Public License for more details.
15
+     * You should have received a copy of the GNU General Public License
16
+     * along with this program; if not, write to the Free Software
17
+     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
+     */
19 19
 
20 20
 namespace plunner\Console\Commands\SyncCaldav;
21 21
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
         $caldavClient = new SimpleCaldavAdapter();
74 74
         $caldavClient->connect($this->calendar->url, $this->calendar->username, \Crypt::decrypt($this->calendar->password));
75 75
         $calendars = $caldavClient->findCalendars();
76
-        $caldavClient->setCalendar($calendars[$this->calendar->calendar_name]);
76
+        $caldavClient->setCalendar($calendars[ $this->calendar->calendar_name ]);
77 77
         /**
78 78
          * 26 hours before to avoid tiemezone problems and dst problems
79 79
          * 30 days after
80 80
          */
81
-        return $caldavClient->getEvents(date('Ymd\THis\Z', time()-93600), date('Ymd\THis\Z', time()+2592000));
81
+        return $caldavClient->getEvents(date('Ymd\THis\Z', time() - 93600), date('Ymd\THis\Z', time() + 2592000));
82 82
     }
83 83
 
84 84
     /**
@@ -89,10 +89,10 @@  discard block
 block discarded – undo
89 89
         try
90 90
         {
91 91
             $events = $this->getEvents();
92
-        }catch (\it\thecsea\caldav_client_adapter\CaldavException $e)
92
+        } catch (\it\thecsea\caldav_client_adapter\CaldavException $e)
93 93
         {
94 94
             \Event::fire(new CaldavErrorEvent($this->calendar, $e->getMessage()));
95
-        }catch(\Illuminate\Contracts\Encryption\DecryptException $e){
95
+        } catch (\Illuminate\Contracts\Encryption\DecryptException $e) {
96 96
             \Event::fire(new CaldavErrorEvent($this->calendar, $e->getMessage()));
97 97
         }
98 98
 
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 
104 104
         //remove old timeslots
105 105
         $calendarMain->timeslots()->delete();
106
-        foreach($events as $event){
107
-            if(!($event = $this->parseEvent($event)))
106
+        foreach ($events as $event) {
107
+            if (!($event = $this->parseEvent($event)))
108 108
                 \Event::fire(new CaldavErrorEvent($this->calendar, 'problem during the parsing an event'));
109 109
             $calendarMain->timeslots()->create($event);
110 110
         }
@@ -117,16 +117,16 @@  discard block
 block discarded – undo
117 117
     private function parseEvent(EventInterface $event)
118 118
     {
119 119
         $pattern = "/^((DTSTART;)|(DTEND;))(.*)\$/m";
120
-        if(preg_match_all($pattern, $event->getData(), $matches)){
121
-            if(!isset($matches[4]) || count($matches[4]) != 2)
120
+        if (preg_match_all($pattern, $event->getData(), $matches)) {
121
+            if (!isset($matches[ 4 ]) || count($matches[ 4 ]) != 2)
122 122
                 return null;
123
-            $ret = [];
124
-            if($tmp = $this->parseDate($matches[4][0]))
125
-                $ret['time_start'] = $tmp;
123
+            $ret = [ ];
124
+            if ($tmp = $this->parseDate($matches[ 4 ][ 0 ]))
125
+                $ret[ 'time_start' ] = $tmp;
126 126
             else
127 127
                 return null;
128
-            if($tmp = $this->parseDate($matches[4][1]))
129
-                $ret['time_end'] = $tmp;
128
+            if ($tmp = $this->parseDate($matches[ 4 ][ 1 ]))
129
+                $ret[ 'time_end' ] = $tmp;
130 130
             else
131 131
                 return null;
132 132
             return $ret;
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
     private function parseDate($date)
142 142
     {
143 143
         $pattern = "/^((TZID=)|(VALUE=))(.*):(.*)\$/m";
144
-        if(preg_match_all($pattern, $date, $matches)){
145
-            if($matches[1][0] == 'TZID=')
144
+        if (preg_match_all($pattern, $date, $matches)) {
145
+            if ($matches[ 1 ][ 0 ] == 'TZID=')
146 146
             {
147
-                return \DateTime::createFromFormat('Ymd\THis', $matches[5][0], new \DateTimeZone($matches[4][0]));
148
-            }else if($matches[1][0] == 'VALUE=' && $matches[4][0] == 'DATE')
147
+                return \DateTime::createFromFormat('Ymd\THis', $matches[ 5 ][ 0 ], new \DateTimeZone($matches[ 4 ][ 0 ]));
148
+            } else if ($matches[ 1 ][ 0 ] == 'VALUE=' && $matches[ 4 ][ 0 ] == 'DATE')
149 149
             {
150
-                return \DateTime::createFromFormat('Ymd\THis', $matches[5][0].'T000000');
150
+                return \DateTime::createFromFormat('Ymd\THis', $matches[ 5 ][ 0 ].'T000000');
151 151
             }
152 152
         }
153 153
         return null;
Please login to merge, or discard this patch.
Braces   +19 added lines, -15 removed lines patch added patch discarded remove patch
@@ -89,10 +89,10 @@  discard block
 block discarded – undo
89 89
         try
90 90
         {
91 91
             $events = $this->getEvents();
92
-        }catch (\it\thecsea\caldav_client_adapter\CaldavException $e)
92
+        } catch (\it\thecsea\caldav_client_adapter\CaldavException $e)
93 93
         {
94 94
             \Event::fire(new CaldavErrorEvent($this->calendar, $e->getMessage()));
95
-        }catch(\Illuminate\Contracts\Encryption\DecryptException $e){
95
+        } catch(\Illuminate\Contracts\Encryption\DecryptException $e){
96 96
             \Event::fire(new CaldavErrorEvent($this->calendar, $e->getMessage()));
97 97
         }
98 98
 
@@ -104,8 +104,9 @@  discard block
 block discarded – undo
104 104
         //remove old timeslots
105 105
         $calendarMain->timeslots()->delete();
106 106
         foreach($events as $event){
107
-            if(!($event = $this->parseEvent($event)))
108
-                \Event::fire(new CaldavErrorEvent($this->calendar, 'problem during the parsing an event'));
107
+            if(!($event = $this->parseEvent($event))) {
108
+                            \Event::fire(new CaldavErrorEvent($this->calendar, 'problem during the parsing an event'));
109
+            }
109 110
             $calendarMain->timeslots()->create($event);
110 111
         }
111 112
     }
@@ -118,17 +119,20 @@  discard block
 block discarded – undo
118 119
     {
119 120
         $pattern = "/^((DTSTART;)|(DTEND;))(.*)\$/m";
120 121
         if(preg_match_all($pattern, $event->getData(), $matches)){
121
-            if(!isset($matches[4]) || count($matches[4]) != 2)
122
-                return null;
122
+            if(!isset($matches[4]) || count($matches[4]) != 2) {
123
+                            return null;
124
+            }
123 125
             $ret = [];
124
-            if($tmp = $this->parseDate($matches[4][0]))
125
-                $ret['time_start'] = $tmp;
126
-            else
127
-                return null;
128
-            if($tmp = $this->parseDate($matches[4][1]))
129
-                $ret['time_end'] = $tmp;
130
-            else
131
-                return null;
126
+            if($tmp = $this->parseDate($matches[4][0])) {
127
+                            $ret['time_start'] = $tmp;
128
+            } else {
129
+                            return null;
130
+            }
131
+            if($tmp = $this->parseDate($matches[4][1])) {
132
+                            $ret['time_end'] = $tmp;
133
+            } else {
134
+                            return null;
135
+            }
132 136
             return $ret;
133 137
         }
134 138
         return null;
@@ -145,7 +149,7 @@  discard block
 block discarded – undo
145 149
             if($matches[1][0] == 'TZID=')
146 150
             {
147 151
                 return \DateTime::createFromFormat('Ymd\THis', $matches[5][0], new \DateTimeZone($matches[4][0]));
148
-            }else if($matches[1][0] == 'VALUE=' && $matches[4][0] == 'DATE')
152
+            } else if($matches[1][0] == 'VALUE=' && $matches[4][0] == 'DATE')
149 153
             {
150 154
                 return \DateTime::createFromFormat('Ymd\THis', $matches[5][0].'T000000');
151 155
             }
Please login to merge, or discard this patch.
app/Listeners/CaldavErrorListener.php 1 patch
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,6 @@
 block discarded – undo
3 3
 namespace plunner\Listeners;
4 4
 
5 5
 use plunner\Events\CaldavErrorEvent;
6
-use Illuminate\Queue\InteractsWithQueue;
7
-use Illuminate\Contracts\Queue\ShouldQueue;
8 6
 
9 7
 class CaldavErrorListener
10 8
 {
Please login to merge, or discard this patch.
app/Caldav.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
     /**
17 17
      * @var array
18 18
      */
19
-    protected $touches = ['calendar'];
19
+    protected $touches = [ 'calendar' ];
20 20
 
21 21
     /**
22 22
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
Please login to merge, or discard this patch.
app/Calendar.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      *
32 32
      * @var array
33 33
      */
34
-    protected $fillable = ['name'];
34
+    protected $fillable = [ 'name' ];
35 35
 
36 36
     /**
37 37
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function Caldav()
56 56
     {
57
-        if($this->type == 'caldav')
57
+        if ($this->type == 'caldav')
58 58
             return $this->hasOne(Caldav::class);
59 59
         return null;
60 60
     }
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -54,8 +54,9 @@
 block discarded – undo
54 54
      */
55 55
     public function Caldav()
56 56
     {
57
-        if($this->type == 'caldav')
58
-            return $this->hasOne(Caldav::class);
57
+        if($this->type == 'caldav') {
58
+                    return $this->hasOne(Caldav::class);
59
+        }
59 60
         return null;
60 61
     }
61 62
 }
Please login to merge, or discard this patch.
app/Console/Commands/SyncCaldav/SyncCaldav.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@
 block discarded – undo
82 82
     {
83 83
         $event = $this->schedule->command('sync:caldav '.$calendar->calendar_id)->withoutOverlapping();
84 84
         if($event->isDue($this->laravel))
85
-             $event->run($this->laravel);
85
+                $event->run($this->laravel);
86 86
     }
87 87
 
88 88
     /**
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     {
54 54
         //
55 55
         $calendarId = $this->argument('calendarId');
56
-        if(is_numeric($calendarId))
56
+        if (is_numeric($calendarId))
57 57
             $this->makeForeground(Caldav::findOrFail($calendarId));
58 58
         else
59 59
             $this->syncAll();
@@ -62,15 +62,15 @@  discard block
 block discarded – undo
62 62
     private function syncAll()
63 63
     {
64 64
         $calendars = Caldav::all();
65
-        if($this->option('background')) {
65
+        if ($this->option('background')) {
66 66
             \Log::debug(self::BACKGROUND_MOD_MEX);
67 67
             $this->info(self::BACKGROUND_MOD_MEX);
68 68
             foreach ($calendars as $calendar)
69 69
                 $this->makeBackground($calendar);
70 70
             \Log::debug(self::BACKGROUND_COMPLETED_MEX);
71 71
             $this->info(self::BACKGROUND_COMPLETED_MEX);
72
-        }else
73
-            foreach($calendars as $calendar)
72
+        } else
73
+            foreach ($calendars as $calendar)
74 74
                 $this->makeForeground($calendar);
75 75
     }
76 76
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
     private function makeBackground(Caldav $calendar)
82 82
     {
83 83
         $event = $this->schedule->command('sync:caldav '.$calendar->calendar_id)->withoutOverlapping();
84
-        if($event->isDue($this->laravel))
84
+        if ($event->isDue($this->laravel))
85 85
              $event->run($this->laravel);
86 86
     }
87 87
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
      */
92 92
     private function makeForeground(Caldav $calendar)
93 93
     {
94
-        $this->info('Sync calendar '. $calendar->calendar_id.' started');
94
+        $this->info('Sync calendar '.$calendar->calendar_id.' started');
95 95
         (new Sync($calendar))->sync();
96
-        $this->info('Sync calendar '. $calendar->calendar_id.' completed');
96
+        $this->info('Sync calendar '.$calendar->calendar_id.' completed');
97 97
     }
98 98
 }
Please login to merge, or discard this patch.
Braces   +14 added lines, -10 removed lines patch added patch discarded remove patch
@@ -53,10 +53,11 @@  discard block
 block discarded – undo
53 53
     {
54 54
         //
55 55
         $calendarId = $this->argument('calendarId');
56
-        if(is_numeric($calendarId))
57
-            $this->makeForeground(Caldav::findOrFail($calendarId));
58
-        else
59
-            $this->syncAll();
56
+        if(is_numeric($calendarId)) {
57
+                    $this->makeForeground(Caldav::findOrFail($calendarId));
58
+        } else {
59
+                    $this->syncAll();
60
+        }
60 61
     }
61 62
 
62 63
     private function syncAll()
@@ -65,13 +66,15 @@  discard block
 block discarded – undo
65 66
         if($this->option('background')) {
66 67
             \Log::debug(self::BACKGROUND_MOD_MEX);
67 68
             $this->info(self::BACKGROUND_MOD_MEX);
68
-            foreach ($calendars as $calendar)
69
-                $this->makeBackground($calendar);
69
+            foreach ($calendars as $calendar) {
70
+                            $this->makeBackground($calendar);
71
+            }
70 72
             \Log::debug(self::BACKGROUND_COMPLETED_MEX);
71 73
             $this->info(self::BACKGROUND_COMPLETED_MEX);
72
-        }else
73
-            foreach($calendars as $calendar)
74
+        } else {
75
+                    foreach($calendars as $calendar)
74 76
                 $this->makeForeground($calendar);
77
+        }
75 78
     }
76 79
 
77 80
     /**
@@ -81,8 +84,9 @@  discard block
 block discarded – undo
81 84
     private function makeBackground(Caldav $calendar)
82 85
     {
83 86
         $event = $this->schedule->command('sync:caldav '.$calendar->calendar_id)->withoutOverlapping();
84
-        if($event->isDue($this->laravel))
85
-             $event->run($this->laravel);
87
+        if($event->isDue($this->laravel)) {
88
+                     $event->run($this->laravel);
89
+        }
86 90
     }
87 91
 
88 92
     /**
Please login to merge, or discard this patch.